1
- import httplib as http
2
- import urlparse
1
+ from rest_framework import status as http_status
2
+ from future . moves . urllib . parse import urlparse , urljoin , parse_qs
3
3
4
4
import mock
5
5
import responses
@@ -25,11 +25,11 @@ def test_oauth_start(self):
25
25
service_name = self .ADDON_SHORT_NAME
26
26
)
27
27
res = self .app .get (url , auth = self .user .auth )
28
- assert res .status_code == http . FOUND
29
- redirect_url = urlparse . urlparse (res .location )
30
- redirect_params = urlparse . parse_qs (redirect_url .query )
31
- provider_url = urlparse . urlparse (self .Provider ().auth_url )
32
- provider_params = urlparse . parse_qs (provider_url .query )
28
+ assert res .status_code == http_status . HTTP_302_FOUND
29
+ redirect_url = urlparse (res .location )
30
+ redirect_params = parse_qs (redirect_url .query )
31
+ provider_url = urlparse (self .Provider ().auth_url )
32
+ provider_params = parse_qs (provider_url .query )
33
33
for param , value in redirect_params .items ():
34
34
if param == 'state' : # state may change between calls
35
35
continue
@@ -43,7 +43,7 @@ def test_oauth_finish(self):
43
43
with mock .patch .object (self .Provider , 'auth_callback' ) as mock_callback :
44
44
mock_callback .return_value = True
45
45
res = self .app .get (url , auth = self .user .auth )
46
- assert_equal (res .status_code , http . OK )
46
+ assert_equal (res .status_code , http_status . HTTP_200_OK )
47
47
name , args , kwargs = mock_callback .mock_calls [0 ]
48
48
assert_equal (kwargs ['user' ]._id , self .user ._id )
49
49
@@ -53,7 +53,7 @@ def test_delete_external_account(self):
53
53
external_account_id = self .external_account ._id
54
54
)
55
55
res = self .app .delete (url , auth = self .user .auth )
56
- assert_equal (res .status_code , http . OK )
56
+ assert_equal (res .status_code , http_status . HTTP_200_OK )
57
57
self .user .reload ()
58
58
for account in self .user .external_accounts .all ():
59
59
assert_not_equal (account ._id , self .external_account ._id )
@@ -66,7 +66,7 @@ def test_delete_external_account_not_owner(self):
66
66
external_account_id = self .external_account ._id
67
67
)
68
68
res = self .app .delete (url , auth = other_user .auth , expect_errors = True )
69
- assert_equal (res .status_code , http . FORBIDDEN )
69
+ assert_equal (res .status_code , http_status . HTTP_403_FORBIDDEN )
70
70
71
71
class OAuthAddonConfigViewsTestCaseMixin (OAuthAddonTestCaseMixin ):
72
72
@@ -94,7 +94,7 @@ def test_import_auth(self):
94
94
res = self .app .put_json (url , {
95
95
'external_account_id' : ea ._id
96
96
}, auth = self .user .auth )
97
- assert_equal (res .status_code , http . OK )
97
+ assert_equal (res .status_code , http_status . HTTP_200_OK )
98
98
assert_in ('result' , res .json )
99
99
node_settings .reload ()
100
100
assert_equal (node_settings .external_account ._id , ea ._id )
@@ -113,7 +113,7 @@ def test_import_auth_invalid_account(self):
113
113
res = self .app .put_json (url , {
114
114
'external_account_id' : ea ._id
115
115
}, auth = self .user .auth , expect_errors = True )
116
- assert_equal (res .status_code , http . FORBIDDEN )
116
+ assert_equal (res .status_code , http_status . HTTP_403_FORBIDDEN )
117
117
118
118
def test_import_auth_cant_write_node (self ):
119
119
ea = self .ExternalAccountFactory ()
@@ -130,15 +130,15 @@ def test_import_auth_cant_write_node(self):
130
130
res = self .app .put_json (url , {
131
131
'external_account_id' : ea ._id
132
132
}, auth = user .auth , expect_errors = True )
133
- assert_equal (res .status_code , http . FORBIDDEN )
133
+ assert_equal (res .status_code , http_status . HTTP_403_FORBIDDEN )
134
134
135
135
def test_set_config (self ):
136
136
self .node_settings .set_auth (self .external_account , self .user )
137
137
url = self .project .api_url_for ('{0}_set_config' .format (self .ADDON_SHORT_NAME ))
138
138
res = self .app .put_json (url , {
139
139
'selected' : self .folder
140
140
}, auth = self .user .auth )
141
- assert_equal (res .status_code , http . OK )
141
+ assert_equal (res .status_code , http_status . HTTP_200_OK )
142
142
self .project .reload ()
143
143
assert_equal (
144
144
self .project .logs .latest ().action ,
@@ -150,7 +150,7 @@ def test_get_config(self):
150
150
url = self .project .api_url_for ('{0}_get_config' .format (self .ADDON_SHORT_NAME ))
151
151
with mock .patch .object (type (self .Serializer ()), 'credentials_are_valid' , return_value = True ):
152
152
res = self .app .get (url , auth = self .user .auth )
153
- assert_equal (res .status_code , http . OK )
153
+ assert_equal (res .status_code , http_status . HTTP_200_OK )
154
154
assert_in ('result' , res .json )
155
155
serialized = self .Serializer ().serialize_settings (
156
156
self .node_settings ,
@@ -164,17 +164,17 @@ def test_get_config_unauthorized(self):
164
164
user = AuthUserFactory ()
165
165
self .project .add_contributor (user , permissions = permissions .READ , auth = self .auth , save = True )
166
166
res = self .app .get (url , auth = user .auth , expect_errors = True )
167
- assert_equal (res .status_code , http . FORBIDDEN )
167
+ assert_equal (res .status_code , http_status . HTTP_403_FORBIDDEN )
168
168
169
169
def test_get_config_not_logged_in (self ):
170
170
url = self .project .api_url_for ('{0}_get_config' .format (self .ADDON_SHORT_NAME ))
171
171
res = self .app .get (url , auth = None , expect_errors = True )
172
- assert_equal (res .status_code , http . FOUND )
172
+ assert_equal (res .status_code , http_status . HTTP_302_FOUND )
173
173
174
174
def test_account_list_single (self ):
175
175
url = api_url_for ('{0}_account_list' .format (self .ADDON_SHORT_NAME ))
176
176
res = self .app .get (url , auth = self .user .auth )
177
- assert_equal (res .status_code , http . OK )
177
+ assert_equal (res .status_code , http_status . HTTP_200_OK )
178
178
assert_in ('accounts' , res .json )
179
179
assert_equal (len (res .json ['accounts' ]), 1 )
180
180
@@ -185,14 +185,14 @@ def test_account_list_multiple(self):
185
185
186
186
url = api_url_for ('{0}_account_list' .format (self .ADDON_SHORT_NAME ))
187
187
res = self .app .get (url , auth = self .user .auth )
188
- assert_equal (res .status_code , http . OK )
188
+ assert_equal (res .status_code , http_status . HTTP_200_OK )
189
189
assert_in ('accounts' , res .json )
190
190
assert_equal (len (res .json ['accounts' ]), 2 )
191
191
192
192
def test_account_list_not_authorized (self ):
193
193
url = api_url_for ('{0}_account_list' .format (self .ADDON_SHORT_NAME ))
194
194
res = self .app .get (url , auth = None , expect_errors = True )
195
- assert_equal (res .status_code , http . FOUND )
195
+ assert_equal (res .status_code , http_status . HTTP_302_FOUND )
196
196
197
197
def test_folder_list (self ):
198
198
# Note: if your addon's folder_list view makes API calls
@@ -202,13 +202,13 @@ def test_folder_list(self):
202
202
self .node_settings .save ()
203
203
url = self .project .api_url_for ('{0}_folder_list' .format (self .ADDON_SHORT_NAME ))
204
204
res = self .app .get (url , auth = self .user .auth )
205
- assert_equal (res .status_code , http . OK )
205
+ assert_equal (res .status_code , http_status . HTTP_200_OK )
206
206
# TODO test result serialization?
207
207
208
208
def test_deauthorize_node (self ):
209
209
url = self .project .api_url_for ('{0}_deauthorize_node' .format (self .ADDON_SHORT_NAME ))
210
210
res = self .app .delete (url , auth = self .user .auth )
211
- assert_equal (res .status_code , http . OK )
211
+ assert_equal (res .status_code , http_status . HTTP_200_OK )
212
212
self .node_settings .reload ()
213
213
assert_is_none (self .node_settings .external_account )
214
214
assert_false (self .node_settings .has_auth )
@@ -256,7 +256,7 @@ def test_set_config(self):
256
256
'external_list_id' : self .folder .json ['id' ],
257
257
'external_list_name' : self .folder .name ,
258
258
}, auth = self .user .auth )
259
- assert_equal (res .status_code , http . OK )
259
+ assert_equal (res .status_code , http_status . HTTP_200_OK )
260
260
self .project .reload ()
261
261
assert_equal (
262
262
self .project .logs .latest ().action ,
@@ -271,7 +271,7 @@ def test_get_config(self):
271
271
self .node_settings .save ()
272
272
url = self .project .api_url_for ('{0}_get_config' .format (self .ADDON_SHORT_NAME ))
273
273
res = self .app .get (url , auth = self .user .auth )
274
- assert_equal (res .status_code , http . OK )
274
+ assert_equal (res .status_code , http_status . HTTP_200_OK )
275
275
assert_in ('result' , res .json )
276
276
result = res .json ['result' ]
277
277
serialized = self .Serializer (
@@ -287,7 +287,7 @@ def test_folder_list(self):
287
287
self .node_settings .save ()
288
288
url = self .project .api_url_for ('{0}_citation_list' .format (self .ADDON_SHORT_NAME ))
289
289
res = self .app .get (url , auth = self .user .auth )
290
- assert_equal (res .status_code , http . OK )
290
+ assert_equal (res .status_code , http_status . HTTP_200_OK )
291
291
292
292
def test_check_credentials (self ):
293
293
with mock .patch .object (self .client , 'client' , new_callable = mock .PropertyMock ) as mock_client :
@@ -412,4 +412,4 @@ def test_citation_list_non_linked_or_child_non_authorizer(self):
412
412
auth = non_authorizing_user .auth ,
413
413
expect_errors = True
414
414
)
415
- assert_equal (res .status_code , http . FORBIDDEN )
415
+ assert_equal (res .status_code , http_status . HTTP_403_FORBIDDEN )
0 commit comments