Skip to content

Commit

Permalink
Merge pull request #8999 from Johnetordoff/even-more-py3-back-compat-…
Browse files Browse the repository at this point in the history
…changes

[Py3][ENG-129] Even more Py3 backwards compatibility changes
  • Loading branch information
pattisdr authored Sep 17, 2019
2 parents 36d1d8b + 3396128 commit 6c25eed
Show file tree
Hide file tree
Showing 139 changed files with 885 additions and 903 deletions.
8 changes: 4 additions & 4 deletions addons/base/generic_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Generic add-on view factories"""
# -*- coding: utf-8 -*-
import httplib as http
from rest_framework import status as http_status

from flask import request

Expand Down Expand Up @@ -28,12 +28,12 @@ def _import_auth(auth, node_addon, user_addon, **kwargs):
)

if not user_addon.external_accounts.filter(id=external_account.id).exists():
raise HTTPError(http.FORBIDDEN)
raise HTTPError(http_status.HTTP_403_FORBIDDEN)

try:
node_addon.set_auth(external_account, user_addon.owner)
except PermissionsError:
raise HTTPError(http.FORBIDDEN)
raise HTTPError(http_status.HTTP_403_FORBIDDEN)

node_addon.save()

Expand All @@ -60,7 +60,7 @@ def folder_list(addon_short_name, addon_full_name, get_folders):
def _folder_list(node_addon, **kwargs):
"""Returns a list of folders"""
if not node_addon.has_auth:
raise HTTPError(http.FORBIDDEN)
raise HTTPError(http_status.HTTP_403_FORBIDDEN)

folder_id = request.args.get('folderId')
return get_folders(node_addon, folder_id)
Expand Down
52 changes: 26 additions & 26 deletions addons/base/tests/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import httplib as http
import urlparse
from rest_framework import status as http_status
from future.moves.urllib.parse import urlparse, urljoin, parse_qs

import mock
import responses
Expand All @@ -25,11 +25,11 @@ def test_oauth_start(self):
service_name=self.ADDON_SHORT_NAME
)
res = self.app.get(url, auth=self.user.auth)
assert res.status_code == http.FOUND
redirect_url = urlparse.urlparse(res.location)
redirect_params = urlparse.parse_qs(redirect_url.query)
provider_url = urlparse.urlparse(self.Provider().auth_url)
provider_params = urlparse.parse_qs(provider_url.query)
assert res.status_code == http_status.HTTP_302_FOUND
redirect_url = urlparse(res.location)
redirect_params = parse_qs(redirect_url.query)
provider_url = urlparse(self.Provider().auth_url)
provider_params = parse_qs(provider_url.query)
for param, value in redirect_params.items():
if param == 'state': # state may change between calls
continue
Expand All @@ -43,7 +43,7 @@ def test_oauth_finish(self):
with mock.patch.object(self.Provider, 'auth_callback') as mock_callback:
mock_callback.return_value = True
res = self.app.get(url, auth=self.user.auth)
assert_equal(res.status_code, http.OK)
assert_equal(res.status_code, http_status.HTTP_200_OK)
name, args, kwargs = mock_callback.mock_calls[0]
assert_equal(kwargs['user']._id, self.user._id)

Expand All @@ -53,7 +53,7 @@ def test_delete_external_account(self):
external_account_id=self.external_account._id
)
res = self.app.delete(url, auth=self.user.auth)
assert_equal(res.status_code, http.OK)
assert_equal(res.status_code, http_status.HTTP_200_OK)
self.user.reload()
for account in self.user.external_accounts.all():
assert_not_equal(account._id, self.external_account._id)
Expand All @@ -66,7 +66,7 @@ def test_delete_external_account_not_owner(self):
external_account_id=self.external_account._id
)
res = self.app.delete(url, auth=other_user.auth, expect_errors=True)
assert_equal(res.status_code, http.FORBIDDEN)
assert_equal(res.status_code, http_status.HTTP_403_FORBIDDEN)

class OAuthAddonConfigViewsTestCaseMixin(OAuthAddonTestCaseMixin):

Expand Down Expand Up @@ -94,7 +94,7 @@ def test_import_auth(self):
res = self.app.put_json(url, {
'external_account_id': ea._id
}, auth=self.user.auth)
assert_equal(res.status_code, http.OK)
assert_equal(res.status_code, http_status.HTTP_200_OK)
assert_in('result', res.json)
node_settings.reload()
assert_equal(node_settings.external_account._id, ea._id)
Expand All @@ -113,7 +113,7 @@ def test_import_auth_invalid_account(self):
res = self.app.put_json(url, {
'external_account_id': ea._id
}, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, http.FORBIDDEN)
assert_equal(res.status_code, http_status.HTTP_403_FORBIDDEN)

def test_import_auth_cant_write_node(self):
ea = self.ExternalAccountFactory()
Expand All @@ -130,15 +130,15 @@ def test_import_auth_cant_write_node(self):
res = self.app.put_json(url, {
'external_account_id': ea._id
}, auth=user.auth, expect_errors=True)
assert_equal(res.status_code, http.FORBIDDEN)
assert_equal(res.status_code, http_status.HTTP_403_FORBIDDEN)

def test_set_config(self):
self.node_settings.set_auth(self.external_account, self.user)
url = self.project.api_url_for('{0}_set_config'.format(self.ADDON_SHORT_NAME))
res = self.app.put_json(url, {
'selected': self.folder
}, auth=self.user.auth)
assert_equal(res.status_code, http.OK)
assert_equal(res.status_code, http_status.HTTP_200_OK)
self.project.reload()
assert_equal(
self.project.logs.latest().action,
Expand All @@ -150,7 +150,7 @@ def test_get_config(self):
url = self.project.api_url_for('{0}_get_config'.format(self.ADDON_SHORT_NAME))
with mock.patch.object(type(self.Serializer()), 'credentials_are_valid', return_value=True):
res = self.app.get(url, auth=self.user.auth)
assert_equal(res.status_code, http.OK)
assert_equal(res.status_code, http_status.HTTP_200_OK)
assert_in('result', res.json)
serialized = self.Serializer().serialize_settings(
self.node_settings,
Expand All @@ -164,17 +164,17 @@ def test_get_config_unauthorized(self):
user = AuthUserFactory()
self.project.add_contributor(user, permissions=permissions.READ, auth=self.auth, save=True)
res = self.app.get(url, auth=user.auth, expect_errors=True)
assert_equal(res.status_code, http.FORBIDDEN)
assert_equal(res.status_code, http_status.HTTP_403_FORBIDDEN)

def test_get_config_not_logged_in(self):
url = self.project.api_url_for('{0}_get_config'.format(self.ADDON_SHORT_NAME))
res = self.app.get(url, auth=None, expect_errors=True)
assert_equal(res.status_code, http.FOUND)
assert_equal(res.status_code, http_status.HTTP_302_FOUND)

def test_account_list_single(self):
url = api_url_for('{0}_account_list'.format(self.ADDON_SHORT_NAME))
res = self.app.get(url, auth=self.user.auth)
assert_equal(res.status_code, http.OK)
assert_equal(res.status_code, http_status.HTTP_200_OK)
assert_in('accounts', res.json)
assert_equal(len(res.json['accounts']), 1)

Expand All @@ -185,14 +185,14 @@ def test_account_list_multiple(self):

url = api_url_for('{0}_account_list'.format(self.ADDON_SHORT_NAME))
res = self.app.get(url, auth=self.user.auth)
assert_equal(res.status_code, http.OK)
assert_equal(res.status_code, http_status.HTTP_200_OK)
assert_in('accounts', res.json)
assert_equal(len(res.json['accounts']), 2)

def test_account_list_not_authorized(self):
url = api_url_for('{0}_account_list'.format(self.ADDON_SHORT_NAME))
res = self.app.get(url, auth=None, expect_errors=True)
assert_equal(res.status_code, http.FOUND)
assert_equal(res.status_code, http_status.HTTP_302_FOUND)

def test_folder_list(self):
# Note: if your addon's folder_list view makes API calls
Expand All @@ -202,13 +202,13 @@ def test_folder_list(self):
self.node_settings.save()
url = self.project.api_url_for('{0}_folder_list'.format(self.ADDON_SHORT_NAME))
res = self.app.get(url, auth=self.user.auth)
assert_equal(res.status_code, http.OK)
assert_equal(res.status_code, http_status.HTTP_200_OK)
# TODO test result serialization?

def test_deauthorize_node(self):
url = self.project.api_url_for('{0}_deauthorize_node'.format(self.ADDON_SHORT_NAME))
res = self.app.delete(url, auth=self.user.auth)
assert_equal(res.status_code, http.OK)
assert_equal(res.status_code, http_status.HTTP_200_OK)
self.node_settings.reload()
assert_is_none(self.node_settings.external_account)
assert_false(self.node_settings.has_auth)
Expand Down Expand Up @@ -256,7 +256,7 @@ def test_set_config(self):
'external_list_id': self.folder.json['id'],
'external_list_name': self.folder.name,
}, auth=self.user.auth)
assert_equal(res.status_code, http.OK)
assert_equal(res.status_code, http_status.HTTP_200_OK)
self.project.reload()
assert_equal(
self.project.logs.latest().action,
Expand All @@ -271,7 +271,7 @@ def test_get_config(self):
self.node_settings.save()
url = self.project.api_url_for('{0}_get_config'.format(self.ADDON_SHORT_NAME))
res = self.app.get(url, auth=self.user.auth)
assert_equal(res.status_code, http.OK)
assert_equal(res.status_code, http_status.HTTP_200_OK)
assert_in('result', res.json)
result = res.json['result']
serialized = self.Serializer(
Expand All @@ -287,7 +287,7 @@ def test_folder_list(self):
self.node_settings.save()
url = self.project.api_url_for('{0}_citation_list'.format(self.ADDON_SHORT_NAME))
res = self.app.get(url, auth=self.user.auth)
assert_equal(res.status_code, http.OK)
assert_equal(res.status_code, http_status.HTTP_200_OK)

def test_check_credentials(self):
with mock.patch.object(self.client, 'client', new_callable=mock.PropertyMock) as mock_client:
Expand Down Expand Up @@ -412,4 +412,4 @@ def test_citation_list_non_linked_or_child_non_authorizer(self):
auth=non_authorizing_user.auth,
expect_errors=True
)
assert_equal(res.status_code, http.FORBIDDEN)
assert_equal(res.status_code, http_status.HTTP_403_FORBIDDEN)
Loading

0 comments on commit 6c25eed

Please sign in to comment.