1
- from django_hosts . resolvers import reverse
1
+ from django . urls import reverse
2
2
3
- from .base import APISubdomainTestCase
3
+ from .base import AuthenticatedAPITestCase
4
4
from ..models import DocumentationLink
5
5
6
6
7
- class UnauthedDocumentationLinkAPITests (APISubdomainTestCase ):
7
+ class UnauthedDocumentationLinkAPITests (AuthenticatedAPITestCase ):
8
8
def setUp (self ):
9
9
super ().setUp ()
10
10
self .client .force_authenticate (user = None )
11
11
12
12
def test_detail_lookup_returns_401 (self ):
13
- url = reverse ('bot:documentationlink-detail' , args = ('whatever' ,), host = 'api' )
13
+ url = reverse ('api: bot:documentationlink-detail' , args = ('whatever' ,))
14
14
response = self .client .get (url )
15
15
16
16
self .assertEqual (response .status_code , 401 )
17
17
18
18
def test_list_returns_401 (self ):
19
- url = reverse ('bot:documentationlink-list' , host = 'api ' )
19
+ url = reverse ('api: bot:documentationlink-list' )
20
20
response = self .client .get (url )
21
21
22
22
self .assertEqual (response .status_code , 401 )
23
23
24
24
def test_create_returns_401 (self ):
25
- url = reverse ('bot:documentationlink-list' , host = 'api ' )
25
+ url = reverse ('api: bot:documentationlink-list' )
26
26
response = self .client .post (url , data = {'hi' : 'there' })
27
27
28
28
self .assertEqual (response .status_code , 401 )
29
29
30
30
def test_delete_returns_401 (self ):
31
- url = reverse ('bot:documentationlink-detail' , args = ('whatever' ,), host = 'api' )
31
+ url = reverse ('api: bot:documentationlink-detail' , args = ('whatever' ,))
32
32
response = self .client .delete (url )
33
33
34
34
self .assertEqual (response .status_code , 401 )
35
35
36
36
37
- class EmptyDatabaseDocumentationLinkAPITests (APISubdomainTestCase ):
37
+ class EmptyDatabaseDocumentationLinkAPITests (AuthenticatedAPITestCase ):
38
38
def test_detail_lookup_returns_404 (self ):
39
- url = reverse ('bot:documentationlink-detail' , args = ('whatever' ,), host = 'api' )
39
+ url = reverse ('api: bot:documentationlink-detail' , args = ('whatever' ,))
40
40
response = self .client .get (url )
41
41
42
42
self .assertEqual (response .status_code , 404 )
43
43
44
44
def test_list_all_returns_empty_list (self ):
45
- url = reverse ('bot:documentationlink-list' , host = 'api ' )
45
+ url = reverse ('api: bot:documentationlink-list' )
46
46
response = self .client .get (url )
47
47
48
48
self .assertEqual (response .status_code , 200 )
49
49
self .assertEqual (response .json (), [])
50
50
51
51
def test_delete_returns_404 (self ):
52
- url = reverse ('bot:documentationlink-detail' , args = ('whatever' ,), host = 'api' )
52
+ url = reverse ('api: bot:documentationlink-detail' , args = ('whatever' ,))
53
53
response = self .client .delete (url )
54
54
55
55
self .assertEqual (response .status_code , 404 )
56
56
57
57
58
- class DetailLookupDocumentationLinkAPITests (APISubdomainTestCase ):
58
+ class DetailLookupDocumentationLinkAPITests (AuthenticatedAPITestCase ):
59
59
@classmethod
60
60
def setUpTestData (cls ):
61
61
cls .doc_link = DocumentationLink .objects .create (
@@ -71,27 +71,27 @@ def setUpTestData(cls):
71
71
}
72
72
73
73
def test_detail_lookup_unknown_package_returns_404 (self ):
74
- url = reverse ('bot:documentationlink-detail' , args = ('whatever' ,), host = 'api' )
74
+ url = reverse ('api: bot:documentationlink-detail' , args = ('whatever' ,))
75
75
response = self .client .get (url )
76
76
77
77
self .assertEqual (response .status_code , 404 )
78
78
79
79
def test_detail_lookup_created_package_returns_package (self ):
80
- url = reverse ('bot:documentationlink-detail' , args = (self .doc_link .package ,), host = 'api' )
80
+ url = reverse ('api: bot:documentationlink-detail' , args = (self .doc_link .package ,))
81
81
response = self .client .get (url )
82
82
83
83
self .assertEqual (response .status_code , 200 )
84
84
self .assertEqual (response .json (), self .doc_json )
85
85
86
86
def test_list_all_packages_shows_created_package (self ):
87
- url = reverse ('bot:documentationlink-list' , host = 'api ' )
87
+ url = reverse ('api: bot:documentationlink-list' )
88
88
response = self .client .get (url )
89
89
90
90
self .assertEqual (response .status_code , 200 )
91
91
self .assertEqual (response .json (), [self .doc_json ])
92
92
93
93
def test_create_invalid_body_returns_400 (self ):
94
- url = reverse ('bot:documentationlink-list' , host = 'api ' )
94
+ url = reverse ('api: bot:documentationlink-list' )
95
95
response = self .client .post (url , data = {'i' : 'am' , 'totally' : 'valid' })
96
96
97
97
self .assertEqual (response .status_code , 400 )
@@ -103,7 +103,7 @@ def test_create_invalid_url_returns_400(self):
103
103
'inventory_url' : 'totally an url'
104
104
}
105
105
106
- url = reverse ('bot:documentationlink-list' , host = 'api ' )
106
+ url = reverse ('api: bot:documentationlink-list' )
107
107
response = self .client .post (url , data = body )
108
108
109
109
self .assertEqual (response .status_code , 400 )
@@ -114,13 +114,13 @@ def test_create_invalid_package_name_returns_400(self):
114
114
with self .subTest (package_name = case ):
115
115
body = self .doc_json .copy ()
116
116
body ['package' ] = case
117
- url = reverse ('bot:documentationlink-list' , host = 'api ' )
117
+ url = reverse ('api: bot:documentationlink-list' )
118
118
response = self .client .post (url , data = body )
119
119
120
120
self .assertEqual (response .status_code , 400 )
121
121
122
122
123
- class DocumentationLinkCreationTests (APISubdomainTestCase ):
123
+ class DocumentationLinkCreationTests (AuthenticatedAPITestCase ):
124
124
def setUp (self ):
125
125
super ().setUp ()
126
126
@@ -130,27 +130,27 @@ def setUp(self):
130
130
'inventory_url' : 'https://docs.example.com'
131
131
}
132
132
133
- url = reverse ('bot:documentationlink-list' , host = 'api ' )
133
+ url = reverse ('api: bot:documentationlink-list' )
134
134
response = self .client .post (url , data = self .body )
135
135
136
136
self .assertEqual (response .status_code , 201 )
137
137
138
138
def test_package_in_full_list (self ):
139
- url = reverse ('bot:documentationlink-list' , host = 'api ' )
139
+ url = reverse ('api: bot:documentationlink-list' )
140
140
response = self .client .get (url )
141
141
142
142
self .assertEqual (response .status_code , 200 )
143
143
self .assertEqual (response .json (), [self .body ])
144
144
145
145
def test_detail_lookup_works_with_package (self ):
146
- url = reverse ('bot:documentationlink-detail' , args = (self .body ['package' ],), host = 'api' )
146
+ url = reverse ('api: bot:documentationlink-detail' , args = (self .body ['package' ],))
147
147
response = self .client .get (url )
148
148
149
149
self .assertEqual (response .status_code , 200 )
150
150
self .assertEqual (response .json (), self .body )
151
151
152
152
153
- class DocumentationLinkDeletionTests (APISubdomainTestCase ):
153
+ class DocumentationLinkDeletionTests (AuthenticatedAPITestCase ):
154
154
@classmethod
155
155
def setUpTestData (cls ):
156
156
cls .doc_link = DocumentationLink .objects .create (
@@ -160,13 +160,13 @@ def setUpTestData(cls):
160
160
)
161
161
162
162
def test_unknown_package_returns_404 (self ):
163
- url = reverse ('bot:documentationlink-detail' , args = ('whatever' ,), host = 'api' )
163
+ url = reverse ('api: bot:documentationlink-detail' , args = ('whatever' ,))
164
164
response = self .client .delete (url )
165
165
166
166
self .assertEqual (response .status_code , 404 )
167
167
168
168
def test_delete_known_package_returns_204 (self ):
169
- url = reverse ('bot:documentationlink-detail' , args = (self .doc_link .package ,), host = 'api' )
169
+ url = reverse ('api: bot:documentationlink-detail' , args = (self .doc_link .package ,))
170
170
response = self .client .delete (url )
171
171
172
172
self .assertEqual (response .status_code , 204 )
0 commit comments