-
Notifications
You must be signed in to change notification settings - Fork 47
/
tests.py
130 lines (93 loc) · 3.21 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from django.test import TestCase
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.conditions.models import Condition
from .models import OptionSet, Option
class OptionsTestCase(TestCase):
fixtures = (
'users.json',
'groups.json',
'accounts.json',
'conditions.json',
'domain.json',
'options.json',
)
languages = (
'en',
)
users = (
('editor', 'editor'),
('reviewer', 'reviewer'),
('user', 'user'),
('api', 'api'),
('anonymous', None),
)
status_map = {
'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
}
}
@classmethod
def setUpTestData(cls):
set_group_permissions()
class OptionsTests(TestListViewMixin, OptionsTestCase):
url_names = {
'list_view': 'options'
}
class OptionSetTests(TestModelViewsetMixin, OptionsTestCase):
instances = OptionSet.objects.all()
url_names = {
'viewset': 'internal-options:optionset'
}
def prepare_create_instance(self, instance):
instance.key += '_new'
return instance
class OptionTests(TestModelViewsetMixin, OptionsTestCase):
instances = Option.objects.all()
url_names = {
'viewset': 'internal-options:option'
}
def prepare_create_instance(self, instance):
instance.key += '_new'
return instance
class ConditionTests(TestListViewsetMixin, TestRetrieveViewsetMixin, OptionsTestCase):
instances = Condition.objects.all()
url_names = {
'viewset': 'internal-options:condition'
}
class OptionsExportTests(TestExportViewMixin, OptionsTestCase):
url_names = {
'export_view': 'options_export'
}
class OptionsImportTests(TestImportViewMixin, TestCase):
import_file = 'testing/xml/options.xml'
class OptionSetAPITests(TestListViewsetMixin, TestRetrieveViewsetMixin, OptionsTestCase):
instances = OptionSet.objects.all()
url_names = {
'viewset': 'api-v1-options:optionset'
}
class OptionAPITests(TestListViewsetMixin, TestRetrieveViewsetMixin, OptionsTestCase):
instances = Option.objects.all()
url_names = {
'viewset': 'api-v1-options:option'
}