Commit 70d11122 authored by Julien Muchembled's avatar Julien Muchembled

erp5_web_shadir: update tests

See commit c45c2295
("erp5_web_shadir: more useful checks").
parent de87a9b0
Pipeline #26488 failed with stage
in 0 seconds
...@@ -27,11 +27,11 @@ ...@@ -27,11 +27,11 @@
# #
############################################################################## ##############################################################################
import base64
import hashlib import hashlib
import json import json
import platform import platform
import random import random
from base64 import b64encode
from DateTime import DateTime from DateTime import DateTime
...@@ -47,8 +47,6 @@ class ShaDirMixin(object): ...@@ -47,8 +47,6 @@ class ShaDirMixin(object):
self.portal = self.getPortal() self.portal = self.getPortal()
self.key = 'mykey' + str(random.random()) self.key = 'mykey' + str(random.random())
self.file_name = 'file.txt'
self.urlmd5 = hashlib.md5(self.key).hexdigest()
self.file_content = 'This is the content.' self.file_content = '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'
...@@ -58,21 +56,20 @@ class ShaDirMixin(object): ...@@ -58,21 +56,20 @@ class ShaDirMixin(object):
libc_version = '%s %s' % (platform.libc_ver()[0], platform.libc_ver()[1]) libc_version = '%s %s' % (platform.libc_ver()[0], platform.libc_ver()[1])
self.architecture = '%s %s' % (platform.machine(), libc_version) self.architecture = '%s %s' % (platform.machine(), libc_version)
self.data_list = [json.dumps({'file': self.file_name, self.data_list = [json.dumps({
'urlmd5': self.urlmd5,
'sha512': self.file_sha512sum, 'sha512': self.file_sha512sum,
'creation_date': str(self.creation_date), 'creation_date': str(self.creation_date),
'expiration_date': str(self.expiration_date), 'expiration_date': str(self.expiration_date),
'distribution': self.distribution, 'distribution': self.distribution,
'architecture': self.architecture}), 'architecture': self.architecture}),
"User SIGNATURE goes here."] b64encode("User SIGNATURE goes here.")]
self.data = json.dumps(self.data_list) self.data = json.dumps(self.data_list)
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 %s' % (base64.encodestring('ERP5TypeTestCase:').strip()) 'Authorization': 'Basic ' + b64encode('ERP5TypeTestCase:'),
} }
module = self.portal.web_site_module module = self.portal.web_site_module
......
...@@ -27,11 +27,12 @@ ...@@ -27,11 +27,12 @@
# #
############################################################################## ##############################################################################
import hashlib
import httplib import httplib
import urlparse import urlparse
import json import json
import random import random
from base64 import b64encode
from unittest import expectedFailure from unittest import expectedFailure
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from erp5.component.test.ShaDirMixin import ShaDirMixin from erp5.component.test.ShaDirMixin import ShaDirMixin
...@@ -214,17 +215,15 @@ class TestShaDir(ShaDirMixin, ERP5TypeTestCase): ...@@ -214,17 +215,15 @@ class TestShaDir(ShaDirMixin, ERP5TypeTestCase):
self.postInformation() self.postInformation()
self.tic() self.tic()
urlmd5_2 = 'anotherurlmd5' + str(random.random()) sha512_2 = hashlib.sha512(str(random.random())).hexdigest()
sha512_2 = 'anothersha512_2' + str(random.random())
key_2 = 'another_key' + str(random.random()) key_2 = 'another_key' + str(random.random())
data_list_2 = [json.dumps({'file': self.file_name, data_list_2 = [json.dumps({
'urlmd5': urlmd5_2,
'sha512': sha512_2, 'sha512': sha512_2,
'creation_date': str(self.creation_date), 'creation_date': str(self.creation_date),
'expiration_date': str(self.expiration_date), 'expiration_date': str(self.expiration_date),
'distribution': self.distribution, 'distribution': self.distribution,
'architecture': self.architecture}), 'architecture': self.architecture}),
"User SIGNATURE goes here."] b64encode("User SIGNATURE goes here.")]
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()
......
...@@ -146,14 +146,10 @@ class TestShaDirExternal(ShaDirMixin, ShaSecurityMixin, ERP5TypeTestCase): ...@@ -146,14 +146,10 @@ class TestShaDirExternal(ShaDirMixin, ShaSecurityMixin, ERP5TypeTestCase):
self.assertEqual(302, result.status) self.assertEqual(302, result.status)
def test_external_post_with_wrong_data(self): def test_external_post_with_wrong_data(self):
"""
The data which is sent to the server must follow a JSON schema.
If the data does not follow the schema it must return the error.
"""
# Removing a required property # Removing a required property
data = json.loads(self.data) data = json.loads(self.data)
data[0] = json.loads(data[0]) data[0] = json.loads(data[0])
data[0].pop('file') del data[0]['sha512']
data[0] = json.dumps(data[0]) data[0] = json.dumps(data[0])
data = json.dumps(data) data = json.dumps(data)
...@@ -165,7 +161,6 @@ class TestShaDirExternal(ShaDirMixin, ShaSecurityMixin, ERP5TypeTestCase): ...@@ -165,7 +161,6 @@ class TestShaDirExternal(ShaDirMixin, ShaSecurityMixin, ERP5TypeTestCase):
data = result.read() data = result.read()
finally: finally:
connection.close() connection.close()
self.assertTrue("Required field 'file' is missing" in data, data) self.assertEqual(400, result.status)
self.assertEqual(500, result.status)
self.assertEqual('text/html; charset=utf-8', self.assertEqual('text/html; charset=utf-8',
result.getheader("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