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 @@
#
##############################################################################
import base64
import hashlib
import json
import platform
import random
from base64 import b64encode
from DateTime import DateTime
......@@ -47,8 +47,6 @@ class ShaDirMixin(object):
self.portal = self.getPortal()
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_sha512sum = hashlib.sha512(self.file_content).hexdigest()
self.distribution = 'pypi'
......@@ -58,21 +56,20 @@ class ShaDirMixin(object):
libc_version = '%s %s' % (platform.libc_ver()[0], platform.libc_ver()[1])
self.architecture = '%s %s' % (platform.machine(), libc_version)
self.data_list = [json.dumps({'file': self.file_name,
'urlmd5': self.urlmd5,
self.data_list = [json.dumps({
'sha512': self.file_sha512sum,
'creation_date': str(self.creation_date),
'expiration_date': str(self.expiration_date),
'distribution': self.distribution,
'architecture': self.architecture}),
"User SIGNATURE goes here."]
b64encode("User SIGNATURE goes here.")]
self.data = json.dumps(self.data_list)
self.sha512sum = hashlib.sha512(self.data).hexdigest()
self.header_dict = {
'Content-Type': 'application/json',
'Authorization': 'Basic %s' % (base64.encodestring('ERP5TypeTestCase:').strip())
'Authorization': 'Basic ' + b64encode('ERP5TypeTestCase:'),
}
module = self.portal.web_site_module
......
......@@ -27,11 +27,12 @@
#
##############################################################################
import hashlib
import httplib
import urlparse
import json
import random
from base64 import b64encode
from unittest import expectedFailure
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from erp5.component.test.ShaDirMixin import ShaDirMixin
......@@ -214,17 +215,15 @@ class TestShaDir(ShaDirMixin, ERP5TypeTestCase):
self.postInformation()
self.tic()
urlmd5_2 = 'anotherurlmd5' + str(random.random())
sha512_2 = 'anothersha512_2' + str(random.random())
sha512_2 = hashlib.sha512(str(random.random())).hexdigest()
key_2 = 'another_key' + str(random.random())
data_list_2 = [json.dumps({'file': self.file_name,
'urlmd5': urlmd5_2,
data_list_2 = [json.dumps({
'sha512': sha512_2,
'creation_date': str(self.creation_date),
'expiration_date': str(self.expiration_date),
'distribution': self.distribution,
'architecture': self.architecture}),
"User SIGNATURE goes here."]
b64encode("User SIGNATURE goes here.")]
data_2 = json.dumps(data_list_2)
self.postInformation(key_2, data_2)
self.tic()
......
......@@ -146,14 +146,10 @@ class TestShaDirExternal(ShaDirMixin, ShaSecurityMixin, ERP5TypeTestCase):
self.assertEqual(302, result.status)
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
data = json.loads(self.data)
data[0] = json.loads(data[0])
data[0].pop('file')
del data[0]['sha512']
data[0] = json.dumps(data[0])
data = json.dumps(data)
......@@ -165,7 +161,6 @@ class TestShaDirExternal(ShaDirMixin, ShaSecurityMixin, ERP5TypeTestCase):
data = result.read()
finally:
connection.close()
self.assertTrue("Required field 'file' is missing" in data, data)
self.assertEqual(500, result.status)
self.assertEqual(400, result.status)
self.assertEqual('text/html; charset=utf-8',
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