summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2018-03-25 07:57:01 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2018-04-05 12:25:54 (GMT)
commitd342971a45a0405c4db60323e71ac25f1547dc0a (patch)
tree1579651ae20a9961bea42936873a17a8ffeea502
parent7ac7c48f672b610a1518b4af167f16265f3ce921 (diff)
downloaddjango-mellon-d342971a45a0405c4db60323e71ac25f1547dc0a.zip
django-mellon-d342971a45a0405c4db60323e71ac25f1547dc0a.tar.gz
django-mellon-d342971a45a0405c4db60323e71ac25f1547dc0a.tar.bz2
python3: use open() to open files
-rw-r--r--mellon/adapters.py2
-rw-r--r--mellon/utils.py2
-rw-r--r--tests/test_default_adapter.py2
-rw-r--r--tests/test_utils.py8
-rw-r--r--tests/test_views.py2
-rw-r--r--tests/utils.py2
6 files changed, 9 insertions, 9 deletions
diff --git a/mellon/adapters.py b/mellon/adapters.py
index bbf56e1..8be35d2 100644
--- a/mellon/adapters.py
+++ b/mellon/adapters.py
@@ -46,7 +46,7 @@ class DefaultAdapter(object):
idp['METADATA'] = response.content
elif 'METADATA' in idp:
if idp['METADATA'].startswith('/'):
- idp['METADATA'] = file(idp['METADATA']).read()
+ idp['METADATA'] = open(idp['METADATA']).read()
else:
self.logger.error(u'missing METADATA or METADATA_URL in %d-th idp', i)
continue
diff --git a/mellon/utils.py b/mellon/utils.py
index 90464c1..6affd8a 100644
--- a/mellon/utils.py
+++ b/mellon/utils.py
@@ -25,7 +25,7 @@ def create_metadata(request):
for public_key in app_settings.PUBLIC_KEYS:
if public_key.startswith('/'):
# clean PEM file
- public_key = ''.join(file(public_key).read().splitlines()[1:-1])
+ public_key = ''.join(open(public_key).read().splitlines()[1:-1])
public_keys.append(public_key)
name_id_formats = app_settings.NAME_ID_FORMATS
cache[entity_id] = render_to_string('mellon/metadata.xml', {
diff --git a/tests/test_default_adapter.py b/tests/test_default_adapter.py
index 9214781..d52b432 100644
--- a/tests/test_default_adapter.py
+++ b/tests/test_default_adapter.py
@@ -12,7 +12,7 @@ from mellon.backends import SAMLBackend
pytestmark = pytest.mark.django_db
idp = {
- 'METADATA': file('tests/metadata.xml').read(),
+ 'METADATA': open('tests/metadata.xml').read(),
}
saml_attributes = {
'name_id_format': lasso.SAML2_NAME_IDENTIFIER_FORMAT_PERSISTENT,
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 49084f7..f984b86 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -61,7 +61,7 @@ def test_create_server_invalid_metadata_file(mocker, rf, private_settings, caplo
]
request = rf.get('/')
assert not 'failed with error' in caplog.text
- with mock.patch('mellon.adapters.file', mock.mock_open(read_data='yyy'), create=True):
+ with mock.patch('mellon.adapters.open', mock.mock_open(read_data='yyy'), create=True):
with HTTMock(error_500):
server = create_server(request)
assert len(server.providers) == 0
@@ -75,7 +75,7 @@ def test_create_server_good_metadata_file(mocker, rf, private_settings, caplog):
]
request = rf.get('/')
with mock.patch(
- 'mellon.adapters.file', mock.mock_open(read_data=file('tests/metadata.xml').read()),
+ 'mellon.adapters.open', mock.mock_open(read_data=open('tests/metadata.xml').read()),
create=True):
server = create_server(request)
assert 'ERROR' not in caplog.text
@@ -85,7 +85,7 @@ def test_create_server_good_metadata_file(mocker, rf, private_settings, caplog):
def test_create_server_good_metadata(mocker, rf, private_settings, caplog):
private_settings.MELLON_IDENTITY_PROVIDERS = [
{
- 'METADATA': file('tests/metadata.xml').read(),
+ 'METADATA': open('tests/metadata.xml').read(),
}
]
request = rf.get('/')
@@ -131,7 +131,7 @@ def test_create_metadata(rf, private_settings, caplog):
private_settings.MELLON_NAME_ID_FORMATS = [lasso.SAML2_NAME_IDENTIFIER_FORMAT_UNSPECIFIED]
private_settings.MELLON_DEFAULT_ASSERTION_CONSUMER_BINDING = 'artifact'
request = rf.get('/')
- with mock.patch('mellon.utils.file', mock.mock_open(read_data='BEGIN\nyyy\nEND'), create=True):
+ with mock.patch('mellon.utils.open', mock.mock_open(read_data='BEGIN\nyyy\nEND'), create=True):
metadata = create_metadata(request)
assert_xml_constraints(
metadata.encode('utf-8'),
diff --git a/tests/test_views.py b/tests/test_views.py
index 2cbc9b4..8cdcadd 100644
--- a/tests/test_views.py
+++ b/tests/test_views.py
@@ -83,7 +83,7 @@ def test_metadata(private_settings, client):
},
]
- with mock.patch('mellon.utils.file', mock.mock_open(read_data='BEGIN\nyyy\nEND'), create=True):
+ with mock.patch('mellon.utils.open', mock.mock_open(read_data='BEGIN\nyyy\nEND'), create=True):
response = client.get('/metadata/')
assert_xml_constraints(
response.content,
diff --git a/tests/utils.py b/tests/utils.py
index 366fe7b..388e6c0 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -13,7 +13,7 @@ def html_response(url, request):
@all_requests
def metadata_response(url, request):
- return response(200, content=file('tests/metadata.xml').read())
+ return response(200, content=open('tests/metadata.xml').read())
def reset_caplog(cap):