1
- from django .test import TestCase
2
1
from lists .models import List , Item
3
2
from django .core .exceptions import ValidationError
3
+ import pytest
4
4
5
+ pytestmark = pytest .mark .django_db
5
6
6
- class ItemModelTest (TestCase ):
7
+
8
+ class TestItemModel :
7
9
def test_default_text (self ):
8
10
item = Item ()
9
- self . assertEqual ( item . text , '' )
11
+ assert '' == item . text
10
12
11
13
def test_item_is_related_to_list (self ):
12
14
list_ = List .objects .create ()
13
15
item = Item ()
14
16
item .list = list_
15
17
item .save ()
16
- self . assertIn ( item , list_ .item_set .all () )
18
+ assert item in list_ .item_set .all ()
17
19
18
20
def test_cannot_save_empty_list_items (self ):
19
21
list_ = List .objects .create ()
20
22
item = Item (list = list_ , text = '' )
21
- with self . assertRaises (ValidationError ):
23
+ with pytest . raises (ValidationError ):
22
24
item .save ()
23
25
item .full_clean ()
24
26
25
27
def test_duplicate_items_are_invalid (self ):
26
28
list_ = List .objects .create ()
27
29
Item .objects .create (list = list_ , text = 'bla' )
28
- with self . assertRaises (ValidationError ):
30
+ with pytest . raises (ValidationError ):
29
31
item = Item (list = list_ , text = 'bla' )
30
32
item .full_clean ()
31
33
@@ -41,18 +43,15 @@ def test_list_ordering(self):
41
43
item1 = Item .objects .create (list = list1 , text = 'i1' )
42
44
item2 = Item .objects .create (list = list1 , text = 'item 2' )
43
45
item3 = Item .objects .create (list = list1 , text = '3' )
44
- self .assertEqual (
45
- list (Item .objects .all ()),
46
- [item1 , item2 , item3 ]
47
- )
46
+ assert list (Item .objects .all ()) == [item1 , item2 , item3 ]
48
47
49
48
def test_string_representation (self ):
50
49
item = Item (text = 'some text' )
51
- self . assertEqual ( str ( item ), 'some text' )
50
+ assert 'some text' == str ( item )
52
51
53
52
54
- class ListModelTest ( TestCase ) :
53
+ class TestListModel :
55
54
56
55
def test_get_absolute_url (self ):
57
56
list_ = List .objects .create ()
58
- self . assertEqual ( list_ . get_absolute_url (), '/lists/%d/' % list_ .id )
57
+ assert '/lists/%d/' % list_ .id == list_ . get_absolute_url ( )
0 commit comments