Skip to content

Commit

Permalink
Merge pull request #30 from rdmorganiser/test_mixins
Browse files Browse the repository at this point in the history
Test mixins
  • Loading branch information
jochenklar authored May 24, 2017
2 parents 9b49b65 + bc52236 commit 1913fab
Show file tree
Hide file tree
Showing 10 changed files with 548 additions and 994 deletions.
29 changes: 16 additions & 13 deletions apps/accounts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
from django.core.urlresolvers import reverse
from django.core import mail

from test_generator.core import TestModelStringMixin
from test_generator.viewsets import TestListViewsetMixin, TestRetrieveViewsetMixin

from apps.accounts.utils import set_group_permissions
from apps.core.testing.mixins import (
TestModelStringMixin,
TestListAPIViewMixin,
TestRetrieveAPIViewMixin
)


class AccountsTestCase(TestCase):
Expand All @@ -33,11 +31,6 @@ class AccountsTestCase(TestCase):
('anonymous', None),
)

api_status_map = {
'list': {'editor': 403, 'reviewer': 403, 'api': 200, 'user': 403, 'anonymous': 403},
'retrieve': {'editor': 403, 'reviewer': 403, 'api': 200, 'user': 403, 'anonymous': 403},
}

def setUp(self):
set_group_permissions()

Expand Down Expand Up @@ -171,6 +164,7 @@ def test_post_profile_update_next2(self):
else:
self.assertEqual(response.status_code, 200)


class AdditionalFieldTests(TestModelStringMixin, AccountsTestCase):

def setUp(self):
Expand Down Expand Up @@ -251,8 +245,17 @@ def test_password_reset_post_valid(self):
self.assertEqual(response.status_code, 200)


class UserAPITests(TestListAPIViewMixin, TestRetrieveAPIViewMixin, AccountsTestCase):
class UserAPITests(TestListViewsetMixin, TestRetrieveViewsetMixin, AccountsTestCase):

instances = User.objects.all()

api_url_name = 'api-v1-accounts:user'
url_names = {
'viewset': 'api-v1-accounts:user'
}
status_map = {
'list_viewset': {
'editor': 403, 'reviewer': 403, 'api': 200, 'user': 403, 'anonymous': 403
},
'retrieve_viewset': {
'editor': 403, 'reviewer': 403, 'api': 200, 'user': 403, 'anonymous': 403
},
}
89 changes: 52 additions & 37 deletions apps/conditions/tests.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
from django.test import TestCase

from apps.accounts.utils import set_group_permissions
from apps.core.testing.mixins import (
TestListViewMixin,
TestExportViewMixin,
TestImportViewMixin,
TestModelAPIViewMixin,
TestListAPIViewMixin,
TestRetrieveAPIViewMixin
)
from test_generator.views import TestListViewMixin
from test_generator.viewsets import TestModelViewsetMixin, TestListViewsetMixin, TestRetrieveViewsetMixin

from apps.core.testing.mixins import TestExportViewMixin, TestImportViewMixin
from apps.accounts.utils import set_group_permissions
from apps.domain.models import Attribute

from .models import Condition


class ConditionsTestCase(TestCase):

lang = 'en'

fixtures = (
'users.json',
'groups.json',
Expand All @@ -28,6 +21,10 @@ class ConditionsTestCase(TestCase):
'options.json',
)

languages = (
'en',
)

users = (
('editor', 'editor'),
('reviewer', 'reviewer'),
Expand All @@ -37,58 +34,75 @@ class ConditionsTestCase(TestCase):
)

status_map = {
'list': {'editor': 200, 'reviewer': 200, 'api': 200, 'user': 403, 'anonymous': 302},
'export': {'editor': 200, 'reviewer': 200, 'api': 200, 'user': 403, 'anonymous': 302}
'list_view': {
'editor': 200, 'reviewer': 200, 'api': 200, 'user': 403, 'anonymous': 302
},
'export_view': {
'editor': 200, 'reviewer': 200, 'api': 200, 'user': 403, 'anonymous': 302
},
'list_viewset': {
'editor': 200, 'reviewer': 200, 'api': 200, 'user': 403, 'anonymous': 403
},
'retrieve_viewset': {
'editor': 200, 'reviewer': 200, 'api': 200, 'user': 403, 'anonymous': 403
},
'create_viewset': {
'editor': 201, 'reviewer': 403, 'api': 403, 'user': 403, 'anonymous': 403
},
'update_viewset': {
'editor': 200, 'reviewer': 403, 'api': 403, 'user': 403, 'anonymous': 403
},
'delete_viewset': {
'editor': 204, 'reviewer': 403, 'api': 403, 'user': 403, 'anonymous': 403
}
}

api_status_map = {
'list': {'editor': 200, 'reviewer': 200, 'api': 200, 'user': 403, 'anonymous': 403},
'retrieve': {'editor': 200, 'reviewer': 200, 'api': 200, 'user': 403, 'anonymous': 403},
'create': {'editor': 201, 'reviewer': 403, 'api': 403, 'user': 403, 'anonymous': 403},
'update': {'editor': 200, 'reviewer': 403, 'api': 403, 'user': 403, 'anonymous': 403},
'delete': {'editor': 204, 'reviewer': 403, 'api': 403, 'user': 403, 'anonymous': 403}
}

def setUp(self):
@classmethod
def setUpTestData(cls):
set_group_permissions()


class ConditionsTests(TestListViewMixin, ConditionsTestCase):

url_names = {
'list': 'conditions'
'list_view': 'conditions'
}


class ConditionTests(TestModelAPIViewMixin, ConditionsTestCase):
class ConditionTests(TestModelViewsetMixin, ConditionsTestCase):

instances = Condition.objects.all()

api_url_name = 'internal-conditions:condition'
url_names = {
'viewset': 'internal-conditions:condition'
}

def prepare_create_instance(self, instance):
instance.key += '_new'
return instance


class AttributeTests(TestListAPIViewMixin, ConditionsTestCase):
class AttributeTests(TestListViewsetMixin, ConditionsTestCase):

instances = Attribute.objects.all()

api_url_name = 'internal-conditions:attribute'
url_names = {
'viewset': 'internal-conditions:attribute'
}


class RelationTests(TestListAPIViewMixin, ConditionsTestCase):
class RelationTests(TestListViewsetMixin, ConditionsTestCase):

api_url_name = 'internal-conditions:relation'
api_status_map = {
'list': {'editor': 200, 'reviewer': 200, 'api': 200, 'user': 200, 'anonymous': 403}
url_names = {
'viewset': 'internal-conditions:relation'
}
status_map = {
'list_viewset': {'editor': 200, 'reviewer': 200, 'api': 200, 'user': 200, 'anonymous': 403}
}


class ConditionExportTests(TestExportViewMixin, ConditionsTestCase):

url_names = {
'export': 'conditions_export'
'export_view': 'conditions_export'
}


Expand All @@ -97,8 +111,9 @@ class ConditionImportTests(TestImportViewMixin, TestCase):
import_file = 'testing/xml/conditions.xml'


class ConditionAPITests(TestListAPIViewMixin, TestRetrieveAPIViewMixin, ConditionsTestCase):
class ConditionAPITests(TestListViewsetMixin, TestRetrieveViewsetMixin, ConditionsTestCase):

instances = Condition.objects.all()

api_url_name = 'api-v1-conditions:condition'
url_names = {
'viewset': 'api-v1-conditions:condition'
}
Loading

0 comments on commit 1913fab

Please sign in to comment.