Commit eeb07d7b authored by Jelle van der Waa's avatar Jelle van der Waa 🚧
Browse files

todolists: test delete/edit/add

parent d1e272d1
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
from django.test import TestCase from django.test import TestCase
from todolists.models import Todolist from todolists.models import Todolist, TodolistPackage
class TestTodolist(TestCase): class TestTodolist(TestCase):
...@@ -33,3 +33,71 @@ def test_todolist_json(self): ...@@ -33,3 +33,71 @@ def test_todolist_json(self):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
data = response.json() data = response.json()
self.assertEqual(data['name'], self.todolist.name) 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)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment