| 
1 |  | -from django.contrib.auth.models import User  | 
2 |  | -from django.test import TestCase  | 
 | 1 | +from todolists.models import Todolist, TodolistPackage  | 
3 | 2 | 
 
  | 
4 | 3 | 
 
  | 
5 |  | -from todolists.models import Todolist, TodolistPackage  | 
 | 4 | +def assert_create_todo(client):  | 
 | 5 | +    response = client.post('/todo/add/', {  | 
 | 6 | +        'name': 'Foo rebuild',  | 
 | 7 | +        'description': 'The Foo Rebuild, please read the instructions',  | 
 | 8 | +        'raw': 'linux',  | 
 | 9 | +    }, follow=True)  | 
 | 10 | +    assert response.status_code == 200  | 
 | 11 | + | 
 | 12 | + | 
 | 13 | +def test_todolist_overview(user_client, todolist):  | 
 | 14 | +    response = user_client.get('/todo/')  | 
 | 15 | +    assert response.status_code == 200  | 
 | 16 | +    assert todolist.name in response.content.decode()  | 
 | 17 | + | 
 | 18 | + | 
 | 19 | +def test_todolist_detail(todolist, user_client):  | 
 | 20 | +    response = user_client.get(todolist.get_absolute_url())  | 
 | 21 | +    assert response.status_code == 200  | 
 | 22 | +    assert todolist.name in response.content.decode()  | 
 | 23 | + | 
 | 24 | + | 
 | 25 | +def test_todolist_json(todolist, user_client):  | 
 | 26 | +    response = user_client.get(todolist.get_absolute_url() + 'json')  | 
 | 27 | +    assert response.status_code == 200  | 
 | 28 | +    data = response.json()  | 
 | 29 | +    assert data['name'] == todolist.name  | 
 | 30 | + | 
 | 31 | + | 
 | 32 | +def test_create_todolist(user_client):  | 
 | 33 | +    assert_create_todo(user_client)  | 
 | 34 | +    assert Todolist.objects.count() == 1  | 
 | 35 | +    Todolist.objects.all().delete()  | 
 | 36 | + | 
 | 37 | + | 
 | 38 | +def test_flag_pkg(user_client, arches, repos, package):  | 
 | 39 | +    assert_create_todo(user_client)  | 
 | 40 | + | 
 | 41 | +    todolist = Todolist.objects.first()  | 
 | 42 | +    package = todolist.packages().first()  | 
 | 43 | +    assert package.status == TodolistPackage.INCOMPLETE  | 
 | 44 | + | 
 | 45 | +    response = user_client.get('/todo/{}/flag/{}/'.format(todolist.slug, package.id))  | 
 | 46 | +    assert response.status_code == 302  | 
 | 47 | + | 
 | 48 | +    package = todolist.packages().first()  | 
 | 49 | +    assert package.status == TodolistPackage.COMPLETE  | 
 | 50 | + | 
 | 51 | +    Todolist.objects.all().delete()  | 
 | 52 | + | 
 | 53 | +def test_edit(user_client, arches, repos, package):  | 
 | 54 | +    assert_create_todo(user_client)  | 
 | 55 | + | 
 | 56 | +    todolist = Todolist.objects.first()  | 
 | 57 | +    assert todolist.packages().count() == 1  | 
 | 58 | + | 
 | 59 | +    response = user_client.post('/todo/{}/edit/'.format(todolist.slug), {  | 
 | 60 | +        'name': 'Foo rebuild',  | 
 | 61 | +        'description': 'The Foo Rebuild, please read the instructions',  | 
 | 62 | +        'raw': 'linux\nglibc',  | 
 | 63 | +    })  | 
 | 64 | +    assert response.status_code == 302  | 
 | 65 | +    todolist = Todolist.objects.first()  | 
 | 66 | +    assert todolist.packages().count() == 2  | 
 | 67 | + | 
 | 68 | +    Todolist.objects.all().delete()  | 
6 | 69 | 
 
  | 
 | 70 | +def test_delete(user_client, arches, repos, package):  | 
 | 71 | +    assert_create_todo(user_client)  | 
7 | 72 | 
 
  | 
8 |  | -class TestTodolist(TestCase):  | 
9 |  | -    fixtures = ['main/fixtures/arches.json', 'main/fixtures/repos.json',  | 
10 |  | -                'main/fixtures/package.json']  | 
11 |  | - | 
12 |  | -    def setUp(self):  | 
13 |  | -        self.user = User.objects.create(username="joeuser", first_name="Joe",  | 
14 |  | -                                        last_name="User",  email="[email protected]")   | 
15 |  | -        self.todolist = Todolist.objects.create(name='Boost rebuild',  | 
16 |  | -                                                description='Boost 1.66 rebuid',  | 
17 |  | -                                                creator=self.user,  | 
18 |  | -                                                slug='boost-rebuild',  | 
19 |  | -                                                raw='linux')  | 
20 |  | - | 
21 |  | -    def test_todolist_overview(self):  | 
22 |  | -        response = self.client.get('/todo/')  | 
23 |  | -        self.assertEqual(response.status_code, 200)  | 
24 |  | -        self.assertIn(self.todolist.name, response.content.decode())  | 
25 |  | - | 
26 |  | -    def test_todolist_detail(self):  | 
27 |  | -        response = self.client.get(self.todolist.get_absolute_url())  | 
28 |  | -        self.assertEqual(response.status_code, 200)  | 
29 |  | -        self.assertIn(self.todolist.name, response.content.decode())  | 
30 |  | - | 
31 |  | -    def test_todolist_json(self):  | 
32 |  | -        response = self.client.get(self.todolist.get_absolute_url() + 'json')  | 
33 |  | -        self.assertEqual(response.status_code, 200)  | 
34 |  | -        data = response.json()  | 
35 |  | -        self.assertEqual(data['name'], self.todolist.name)  | 
36 |  | - | 
37 |  | - | 
38 |  | -class TestTodolistAdmin(TestCase):  | 
39 |  | -    fixtures = ['main/fixtures/arches.json', 'main/fixtures/repos.json',  | 
40 |  | -                'main/fixtures/package.json']  | 
41 |  | - | 
42 |  | -    def setUp(self):  | 
43 |  | -        password = 'test'  | 
44 |  | -        self.user = User.objects.create_superuser("admin",  | 
45 |  | - | 
46 |  | -                                                  password)  | 
47 |  | - | 
48 |  | -        self.client.post('/login/', {  | 
49 |  | -                                    'username': self.user.username,  | 
50 |  | -                                    'password': password  | 
51 |  | -        })  | 
52 |  | - | 
53 |  | -    def tearDown(self):  | 
54 |  | -        Todolist.objects.all().delete()  | 
55 |  | -        self.user.delete()  | 
56 |  | - | 
57 |  | -    def create_todo(self):  | 
58 |  | -        return self.client.post('/todo/add/', {  | 
59 |  | -            'name': 'Foo rebuild',  | 
60 |  | -            'description': 'The Foo Rebuild, please read the instructions',  | 
61 |  | -            'raw': 'linux',  | 
62 |  | -        })  | 
63 |  | - | 
64 |  | -    def test_create_todolist(self):  | 
65 |  | -        response = self.create_todo()  | 
66 |  | -        self.assertEqual(response.status_code, 302)  | 
67 |  | -        self.assertEqual(len(Todolist.objects.all()), 1)  | 
68 |  | - | 
69 |  | -    def test_flag_pkg(self):  | 
70 |  | -        response = self.create_todo()  | 
71 |  | -        self.assertEqual(response.status_code, 302)  | 
72 |  | - | 
73 |  | -        todolist = Todolist.objects.first()  | 
74 |  | -        package = todolist.packages().first()  | 
75 |  | -        self.assertEqual(package.status, TodolistPackage.INCOMPLETE)  | 
76 |  | - | 
77 |  | -        response = self.client.get('/todo/{}/flag/{}/'.format(todolist.slug, package.id))  | 
78 |  | -        self.assertEqual(response.status_code, 302)  | 
79 |  | - | 
80 |  | -        package = todolist.packages().first()  | 
81 |  | -        self.assertEqual(package.status, TodolistPackage.COMPLETE)  | 
82 |  | - | 
83 |  | -    def test_edit(self):  | 
84 |  | -        response = self.create_todo()  | 
85 |  | -        self.assertEqual(response.status_code, 302)  | 
86 |  | -        todolist = Todolist.objects.first()  | 
87 |  | -        self.assertEqual(len(todolist.packages().all()), 1)  | 
88 |  | - | 
89 |  | -        response = self.client.post('/todo/{}/edit/'.format(todolist.slug), {  | 
90 |  | -            'name': 'Foo rebuild',  | 
91 |  | -            'description': 'The Foo Rebuild, please read the instructions',  | 
92 |  | -            'raw': 'linux\nglibc',  | 
93 |  | -        })  | 
94 |  | -        self.assertEqual(response.status_code, 302)  | 
95 |  | -        todolist = Todolist.objects.first()  | 
96 |  | -        self.assertEqual(len(todolist.packages().all()), 2)  | 
97 |  | - | 
98 |  | -    def test_delete(self):  | 
99 |  | -        response = self.create_todo()  | 
100 |  | -        self.assertEqual(response.status_code, 302)  | 
101 |  | -        todolist = Todolist.objects.first()  | 
102 |  | -        response = self.client.post('/todo/{}/delete'.format(todolist.slug))  | 
103 |  | -        self.assertEqual(response.status_code, 301)  | 
 | 73 | +    todolist = Todolist.objects.first()  | 
 | 74 | +    response = user_client.post('/todo/{}/delete'.format(todolist.slug))  | 
 | 75 | +    assert response.status_code == 301  | 
 | 76 | +    Todolist.objects.all().delete()  | 
0 commit comments