From de71ae77044d45e2de18558c3c835a951a384503 Mon Sep 17 00:00:00 2001 From: Tanner Prestegard <tanner.prestegard@ligo.org> Date: Fri, 19 Jul 2019 08:03:20 -0500 Subject: [PATCH] Python 3: fix b64encode usage in tests --- gracedb/api/tests/test_authentication.py | 26 +++++++++----- gracedb/api/tests/test_backends.py | 44 ++++++++++++++++-------- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/gracedb/api/tests/test_authentication.py b/gracedb/api/tests/test_authentication.py index a43591594..ecb04cf80 100644 --- a/gracedb/api/tests/test_authentication.py +++ b/gracedb/api/tests/test_authentication.py @@ -34,9 +34,12 @@ class TestGraceDbBasicAuthentication(GraceDbApiTestBase): """User can authenticate to API with correct password""" # Set up and make request url = api_reverse('api:root') - user_and_pass = b64encode(b"{username}:{password}".format( - username=self.lvem_user.username, password=self.password)) \ - .decode("ascii") + user_and_pass = b64encode( + "{username}:{password}".format( + username=self.lvem_user.username, + password=self.password + ).encode() + ).decode("ascii") headers = { 'HTTP_AUTHORIZATION': 'Basic {0}'.format(user_and_pass), } @@ -56,8 +59,12 @@ class TestGraceDbBasicAuthentication(GraceDbApiTestBase): """User can't authenticate with wrong password""" # Set up and make request url = api_reverse('api:root') - user_and_pass = b64encode(b"{username}:{password}".format( - username=self.lvem_user.username, password='b4d')).decode("ascii") + user_and_pass = b64encode( + "{username}:{password}".format( + username=self.lvem_user.username, + password='b4d' + ).encode() + ).decode("ascii") headers = { 'HTTP_AUTHORIZATION': 'Basic {0}'.format(user_and_pass), } @@ -76,9 +83,12 @@ class TestGraceDbBasicAuthentication(GraceDbApiTestBase): # Set up and make request url = api_reverse('api:root') - user_and_pass = b64encode(b"{username}:{password}".format( - username=self.lvem_user.username, password=self.password)) \ - .decode("ascii") + user_and_pass = b64encode( + "{username}:{password}".format( + username=self.lvem_user.username, + password=self.password + ).encode() + ).decode("ascii") headers = { 'HTTP_AUTHORIZATION': 'Basic {0}'.format(user_and_pass), } diff --git a/gracedb/api/tests/test_backends.py b/gracedb/api/tests/test_backends.py index e0caec2b4..7c451a6d1 100644 --- a/gracedb/api/tests/test_backends.py +++ b/gracedb/api/tests/test_backends.py @@ -45,9 +45,12 @@ class TestGraceDbBasicAuthentication(GraceDbApiTestBase): """User can authenticate to API with correct password""" # Set up request request = self.factory.get(api_reverse('api:root')) - user_and_pass = b64encode(b"{username}:{password}".format( - username=self.lvem_user.username, password=self.password)) \ - .decode("ascii") + user_and_pass = b64encode( + "{username}:{password}".format( + username=self.lvem_user.username, + password=self.password + ).encode() + ).decode("ascii") request.META['HTTP_AUTHORIZATION'] = 'Basic {0}'.format(user_and_pass) # Authentication attempt @@ -60,8 +63,12 @@ class TestGraceDbBasicAuthentication(GraceDbApiTestBase): """User can't authenticate with wrong password""" # Set up request request = self.factory.get(api_reverse('api:root')) - user_and_pass = b64encode(b"{username}:{password}".format( - username=self.lvem_user.username, password='b4d')).decode("ascii") + user_and_pass = b64encode( + "{username}:{password}".format( + username=self.lvem_user.username, + password='b4d' + ).encode() + ).decode("ascii") request.META['HTTP_AUTHORIZATION'] = 'Basic {0}'.format(user_and_pass) # Authentication attempt should fail @@ -77,9 +84,12 @@ class TestGraceDbBasicAuthentication(GraceDbApiTestBase): # Set up request request = self.factory.get(api_reverse('api:root')) - user_and_pass = b64encode(b"{username}:{password}".format( - username=self.lvem_user.username, password=self.password)) \ - .decode("ascii") + user_and_pass = b64encode( + "{username}:{password}".format( + username=self.lvem_user.username, + password=self.password + ).encode() + ).decode("ascii") request.META['HTTP_AUTHORIZATION'] = 'Basic {0}'.format(user_and_pass) # Authentication attempt should fail @@ -91,9 +101,12 @@ class TestGraceDbBasicAuthentication(GraceDbApiTestBase): """User can't authenticate to a non-API URL path""" # Set up request request = self.factory.get(reverse('home')) - user_and_pass = b64encode(b"{username}:{password}".format( - username=self.lvem_user.username, password=self.password)) \ - .decode("ascii") + user_and_pass = b64encode( + "{username}:{password}".format( + username=self.lvem_user.username, + password=self.password + ).encode() + ).decode("ascii") request.META['HTTP_AUTHORIZATION'] = 'Basic {0}'.format(user_and_pass) # Try to authenticate @@ -108,9 +121,12 @@ class TestGraceDbBasicAuthentication(GraceDbApiTestBase): # Set up request request = self.factory.get(api_reverse('api:root')) - user_and_pass = b64encode(b"{username}:{password}".format( - username=self.lvem_user.username, password=self.password)) \ - .decode("ascii") + user_and_pass = b64encode( + "{username}:{password}".format( + username=self.lvem_user.username, + password=self.password + ).encode() + ).decode("ascii") request.META['HTTP_AUTHORIZATION'] = 'Basic {0}'.format(user_and_pass) # Authentication attempt should fail -- GitLab