Commit 4be4a4bc authored by Jérome Perrin's avatar Jérome Perrin

web_shadir: PY3 compatibility

parent d8b6a25e
...@@ -52,5 +52,5 @@ class ShaCacheMixin(object): ...@@ -52,5 +52,5 @@ class ShaCacheMixin(object):
} }
self.shacache_url = self.shacache.absolute_url() self.shacache_url = self.shacache.absolute_url()
self.tic() self.tic()
self.data = 'Random Content. %s' % str(random.random()).encode() self.data = ('Random Content. %s' % random.random()).encode()
self.key = hashlib.sha512(self.data).hexdigest() self.key = hashlib.sha512(self.data).hexdigest()
...@@ -44,10 +44,9 @@ class ShaDirMixin(object): ...@@ -44,10 +44,9 @@ class ShaDirMixin(object):
Initialize the ERP5 site. Initialize the ERP5 site.
""" """
self.login() self.login()
self.portal = self.getPortal()
self.key = 'mykey' + str(random.random()) self.key = 'mykey' + str(random.random())
self.file_content = 'This is the content.' self.file_content = b'This is the content.'
self.file_sha512sum = hashlib.sha512(self.file_content).hexdigest() self.file_sha512sum = hashlib.sha512(self.file_content).hexdigest()
self.distribution = 'pypi' self.distribution = 'pypi'
self.creation_date = DateTime() self.creation_date = DateTime()
...@@ -62,14 +61,14 @@ class ShaDirMixin(object): ...@@ -62,14 +61,14 @@ class ShaDirMixin(object):
'expiration_date': str(self.expiration_date), 'expiration_date': str(self.expiration_date),
'distribution': self.distribution, 'distribution': self.distribution,
'architecture': self.architecture}), 'architecture': self.architecture}),
b64encode("User SIGNATURE goes here.")] b64encode(b"User SIGNATURE goes here.").decode()]
self.data = json.dumps(self.data_list) self.data = json.dumps(self.data_list).encode()
self.sha512sum = hashlib.sha512(self.data).hexdigest() self.sha512sum = hashlib.sha512(self.data).hexdigest()
self.header_dict = { self.header_dict = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Authorization': 'Basic ' + b64encode('ERP5TypeTestCase:'), 'Authorization': 'Basic ' + b64encode(b'ERP5TypeTestCase:').decode(),
} }
module = self.portal.web_site_module module = self.portal.web_site_module
......
...@@ -63,7 +63,7 @@ class TestShaDir(ShaDirMixin, ERP5TypeTestCase): ...@@ -63,7 +63,7 @@ class TestShaDir(ShaDirMixin, ERP5TypeTestCase):
finally: finally:
connection.close() connection.close()
self.assertEqual(result.status, six.moves.http_client.CREATED) self.assertEqual(result.status, six.moves.http_client.CREATED)
self.assertEqual(data, '') self.assertEqual(data, b'')
def getInformation(self, key=None): def getInformation(self, key=None):
""" """
...@@ -215,7 +215,7 @@ class TestShaDir(ShaDirMixin, ERP5TypeTestCase): ...@@ -215,7 +215,7 @@ class TestShaDir(ShaDirMixin, ERP5TypeTestCase):
self.postInformation() self.postInformation()
self.tic() self.tic()
sha512_2 = hashlib.sha512(str(random.random())).hexdigest() sha512_2 = hashlib.sha512(str(random.random()).encode()).hexdigest()
key_2 = 'another_key' + str(random.random()) key_2 = 'another_key' + str(random.random())
data_list_2 = [json.dumps({ data_list_2 = [json.dumps({
'sha512': sha512_2, 'sha512': sha512_2,
...@@ -223,7 +223,7 @@ class TestShaDir(ShaDirMixin, ERP5TypeTestCase): ...@@ -223,7 +223,7 @@ class TestShaDir(ShaDirMixin, ERP5TypeTestCase):
'expiration_date': str(self.expiration_date), 'expiration_date': str(self.expiration_date),
'distribution': self.distribution, 'distribution': self.distribution,
'architecture': self.architecture}), 'architecture': self.architecture}),
b64encode("User SIGNATURE goes here.")] b64encode(b"User SIGNATURE goes here.").decode()]
data_2 = json.dumps(data_list_2) data_2 = json.dumps(data_list_2)
self.postInformation(key_2, data_2) self.postInformation(key_2, data_2)
self.tic() self.tic()
......
...@@ -82,7 +82,7 @@ class TestShaCacheExternal(ShaCacheMixin, ShaSecurityMixin, ERP5TypeTestCase): ...@@ -82,7 +82,7 @@ class TestShaCacheExternal(ShaCacheMixin, ShaSecurityMixin, ERP5TypeTestCase):
data = result.read() data = result.read()
finally: finally:
connection.close() connection.close()
self.assertEqual(self.key, data) self.assertEqual(self.key, data.decode())
self.assertEqual(six.moves.http_client.CREATED, result.status) self.assertEqual(six.moves.http_client.CREATED, result.status)
# Check Document # Check Document
......
...@@ -202,7 +202,7 @@ class TestShaCacheSecurity(ShaCacheMixin, ShaSecurityMixin, SecurityTestCase): ...@@ -202,7 +202,7 @@ class TestShaCacheSecurity(ShaCacheMixin, ShaSecurityMixin, SecurityTestCase):
contribution_tool) contribution_tool)
document = self.portal.portal_contributions.newContent( document = self.portal.portal_contributions.newContent(
filename='test.txt', filename='test.txt',
data='test content', data=b'test content',
reference='test-reference') reference='test-reference')
document() document()
document.view() document.view()
......
...@@ -83,7 +83,7 @@ class TestShaDirExternal(ShaDirMixin, ShaSecurityMixin, ERP5TypeTestCase): ...@@ -83,7 +83,7 @@ class TestShaDirExternal(ShaDirMixin, ShaSecurityMixin, ERP5TypeTestCase):
data = result.read() data = result.read()
finally: finally:
connection.close() connection.close()
self.assertEqual('', data) self.assertEqual(b'', data)
self.assertEqual(201, result.status) self.assertEqual(201, result.status)
# Check Data Set # Check Data Set
...@@ -121,7 +121,7 @@ class TestShaDirExternal(ShaDirMixin, ShaSecurityMixin, ERP5TypeTestCase): ...@@ -121,7 +121,7 @@ class TestShaDirExternal(ShaDirMixin, ShaSecurityMixin, ERP5TypeTestCase):
data = result.read() data = result.read()
finally: finally:
connection.close() connection.close()
self.assertEqual(json.dumps([json.loads(self.data)]), data) self.assertEqual(json.dumps([json.loads(self.data)]), data.decode())
self.assertEqual(200, result.status) self.assertEqual(200, result.status)
self.assertEqual(self.content_type, result.getheader("content-type")) self.assertEqual(self.content_type, result.getheader("content-type"))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment