From eeb07d7beea60e1cbba7971458c421b09a91a8fa Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Sun, 12 Aug 2018 19:48:46 +0200 Subject: [PATCH] todolists: test delete/edit/add --- todolists/tests/test_views.py | 70 ++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/todolists/tests/test_views.py b/todolists/tests/test_views.py index c0d6cee0..7a53d7c1 100644 --- a/todolists/tests/test_views.py +++ b/todolists/tests/test_views.py @@ -2,7 +2,7 @@ from django.test import TestCase -from todolists.models import Todolist +from todolists.models import Todolist, TodolistPackage class TestTodolist(TestCase): @@ -33,3 +33,71 @@ def test_todolist_json(self): self.assertEqual(response.status_code, 200) data = response.json() self.assertEqual(data['name'], self.todolist.name) + + +class TestTodolistAdmin(TestCase): + fixtures = ['main/fixtures/arches.json', 'main/fixtures/repos.json', + 'main/fixtures/package.json'] + + def setUp(self): + password = 'test' + self.user = User.objects.create_superuser("admin", + "admin@archlinux.org", + password) + + self.client.post('/login/', { + 'username': self.user.username, + 'password': password + }) + + def tearDown(self): + Todolist.objects.all().delete() + self.user.delete() + + def create_todo(self): + return self.client.post('/todo/add/', { + 'name': 'Foo rebuild', + 'description': 'The Foo Rebuild, please read the instructions', + 'raw': 'linux', + }) + + def test_create_todolist(self): + response = self.create_todo() + self.assertEqual(response.status_code, 302) + self.assertEqual(len(Todolist.objects.all()), 1) + + def test_flag_pkg(self): + response = self.create_todo() + self.assertEqual(response.status_code, 302) + + todolist = Todolist.objects.first() + package = todolist.packages().first() + self.assertEqual(package.status, TodolistPackage.INCOMPLETE) + + response = self.client.get('/todo/{}/flag/{}/'.format(todolist.slug, package.id)) + self.assertEqual(response.status_code, 302) + + package = todolist.packages().first() + self.assertEqual(package.status, TodolistPackage.COMPLETE) + + def test_edit(self): + response = self.create_todo() + self.assertEqual(response.status_code, 302) + todolist = Todolist.objects.first() + self.assertEqual(len(todolist.packages().all()), 1) + + response = self.client.post('/todo/{}/edit/'.format(todolist.slug), { + 'name': 'Foo rebuild', + 'description': 'The Foo Rebuild, please read the instructions', + 'raw': 'linux\nglibc', + }) + self.assertEqual(response.status_code, 302) + todolist = Todolist.objects.first() + self.assertEqual(len(todolist.packages().all()), 2) + + def test_delete(self): + response = self.create_todo() + self.assertEqual(response.status_code, 302) + todolist = Todolist.objects.first() + response = self.client.post('/todo/{}/delete'.format(todolist.slug)) + self.assertEqual(response.status_code, 301)