-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,76 @@ | ||
from django.contrib.auth.models import User | ||
from django.test import TestCase | ||
from todolists.models import Todolist, TodolistPackage | ||
|
||
|
||
from todolists.models import Todolist, TodolistPackage | ||
def assert_create_todo(client): | ||
response = client.post('/todo/add/', { | ||
'name': 'Foo rebuild', | ||
'description': 'The Foo Rebuild, please read the instructions', | ||
'raw': 'linux', | ||
}, follow=True) | ||
assert response.status_code == 200 | ||
|
||
|
||
def test_todolist_overview(user_client, todolist): | ||
response = user_client.get('/todo/') | ||
assert response.status_code == 200 | ||
assert todolist.name in response.content.decode() | ||
|
||
|
||
def test_todolist_detail(todolist, user_client): | ||
response = user_client.get(todolist.get_absolute_url()) | ||
assert response.status_code == 200 | ||
assert todolist.name in response.content.decode() | ||
|
||
|
||
def test_todolist_json(todolist, user_client): | ||
response = user_client.get(todolist.get_absolute_url() + 'json') | ||
assert response.status_code == 200 | ||
data = response.json() | ||
assert data['name'] == todolist.name | ||
|
||
|
||
def test_create_todolist(user_client): | ||
assert_create_todo(user_client) | ||
assert Todolist.objects.count() == 1 | ||
Todolist.objects.all().delete() | ||
|
||
|
||
def test_flag_pkg(user_client, arches, repos, package): | ||
assert_create_todo(user_client) | ||
|
||
todolist = Todolist.objects.first() | ||
package = todolist.packages().first() | ||
assert package.status == TodolistPackage.INCOMPLETE | ||
|
||
response = user_client.get('/todo/{}/flag/{}/'.format(todolist.slug, package.id)) | ||
assert response.status_code == 302 | ||
|
||
package = todolist.packages().first() | ||
assert package.status == TodolistPackage.COMPLETE | ||
|
||
Todolist.objects.all().delete() | ||
|
||
def test_edit(user_client, arches, repos, package): | ||
assert_create_todo(user_client) | ||
|
||
todolist = Todolist.objects.first() | ||
assert todolist.packages().count() == 1 | ||
|
||
response = user_client.post('/todo/{}/edit/'.format(todolist.slug), { | ||
'name': 'Foo rebuild', | ||
'description': 'The Foo Rebuild, please read the instructions', | ||
'raw': 'linux\nglibc', | ||
}) | ||
assert response.status_code == 302 | ||
todolist = Todolist.objects.first() | ||
assert todolist.packages().count() == 2 | ||
|
||
Todolist.objects.all().delete() | ||
|
||
def test_delete(user_client, arches, repos, package): | ||
assert_create_todo(user_client) | ||
|
||
class TestTodolist(TestCase): | ||
fixtures = ['main/fixtures/arches.json', 'main/fixtures/repos.json', | ||
'main/fixtures/package.json'] | ||
|
||
def setUp(self): | ||
self.user = User.objects.create(username="joeuser", first_name="Joe", | ||
last_name="User", email="user1@example.com") | ||
self.todolist = Todolist.objects.create(name='Boost rebuild', | ||
description='Boost 1.66 rebuid', | ||
creator=self.user, | ||
slug='boost-rebuild', | ||
raw='linux') | ||
|
||
def test_todolist_overview(self): | ||
response = self.client.get('/todo/') | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn(self.todolist.name, response.content.decode()) | ||
|
||
def test_todolist_detail(self): | ||
response = self.client.get(self.todolist.get_absolute_url()) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn(self.todolist.name, response.content.decode()) | ||
|
||
def test_todolist_json(self): | ||
response = self.client.get(self.todolist.get_absolute_url() + 'json') | ||
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) | ||
todolist = Todolist.objects.first() | ||
response = user_client.post('/todo/{}/delete'.format(todolist.slug)) | ||
assert response.status_code == 301 | ||
Todolist.objects.all().delete() |