Ticket #5390: tests.py

File tests.py, 1.6 KB (added by Ludovico Magnocavallo <ludo@…>, 17 years ago)

Test cases

Line 
1"""
2>>> from testapp.models import Category, Entry
3>>> for i in range(1, 6):
4... c = Category(name='Cat %s' % i)
5... c.save()
6>>> Category.objects.all()
7[<Category 1 'Cat 1' (0)>, <Category 2 'Cat 2' (0)>, <Category 3 'Cat 3' (0)>, <Category 4 'Cat 4' (0)>, <Category 5 'Cat 5' (0)>]
8>>> e = Entry(title='Pippo')
9>>> e.save()
10>>> e.categories = (1, 2)
11>>> e.save()
12>>> e.status
13'D'
14>>> e.categories.all()
15[<Category 1 'Cat 1' (0)>, <Category 2 'Cat 2' (0)>]
16>>> e.status = 'P'
17>>> e.save()
18>>> e.status
19'P'
20>>> e.categories.all()
21[<Category 1 'Cat 1' (1)>, <Category 2 'Cat 2' (1)>]
22>>> e.categories.remove(1)
23>>> e.categories.all()
24[<Category 2 'Cat 2' (1)>]
25>>> Category.objects.get(id=1)
26<Category 1 'Cat 1' (0)>
27>>> e.categories.add(4, 5)
28>>> e.categories.all()
29[<Category 2 'Cat 2' (1)>, <Category 4 'Cat 4' (1)>, <Category 5 'Cat 5' (1)>]
30>>> e2 = Entry(title='Test', status='P')
31>>> e2.save()
32>>> e2.categories.add(*e.categories.all())
33>>> e.categories.all()
34[<Category 2 'Cat 2' (2)>, <Category 4 'Cat 4' (2)>, <Category 5 'Cat 5' (2)>]
35>>> e2.categories.remove(4)
36>>> e.categories.all()
37[<Category 2 'Cat 2' (2)>, <Category 4 'Cat 4' (1)>, <Category 5 'Cat 5' (2)>]
38>>> e2.categories.clear()
39>>> e2.categories.all()
40[]
41>>> e.categories.all()
42[<Category 2 'Cat 2' (1)>, <Category 4 'Cat 4' (1)>, <Category 5 'Cat 5' (1)>]
43>>> c = Category.objects.get(id=2)
44>>> c.post_count
451
46>>> c.entry_set.all()
47[<Post 'Pippo'>]
48>>> c.entry_set.add(e2)
49>>> c.entry_set.all()
50[<Post 'Pippo'>, <Post 'Test'>]
51>>> c.post_count
522
53>>> c.entry_set.remove(Entry.objects.get(id=1))
54>>> c.post_count
551
56>>> c.entry_set.clear()
57>>> c.post_count
580
59>>>
60"""
Back to Top