todolists: test delete/edit/add
This commit is contained in:
parent
d1e272d19b
commit
eeb07d7bee
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user