diff options
-rw-r--r-- | robotframework-onap/ONAPLibrary/RequestsHelper.py | 7 | ||||
-rw-r--r-- | robotframework-onap/tests/ONAPLibrary/RequestsHelperTests.py | 28 |
2 files changed, 29 insertions, 6 deletions
diff --git a/robotframework-onap/ONAPLibrary/RequestsHelper.py b/robotframework-onap/ONAPLibrary/RequestsHelper.py index f3a0ad5..ec0ef2d 100644 --- a/robotframework-onap/ONAPLibrary/RequestsHelper.py +++ b/robotframework-onap/ONAPLibrary/RequestsHelper.py @@ -90,9 +90,12 @@ class RequestsHelper(object): @staticmethod def _format_md5(md5_input): - if md5_input is not None and isinstance(md5_input, str): + string_input = md5_input + if md5_input is not None: + if isinstance(md5_input, str): + string_input = md5_input.encode('utf-8') md5 = hashlib.md5() - md5.update(md5_input.encode('utf-8')) + md5.update(string_input) return Base64Keywords().base64_encode(md5.hexdigest()) else: return None diff --git a/robotframework-onap/tests/ONAPLibrary/RequestsHelperTests.py b/robotframework-onap/tests/ONAPLibrary/RequestsHelperTests.py index 29a0584..11d3cfe 100644 --- a/robotframework-onap/tests/ONAPLibrary/RequestsHelperTests.py +++ b/robotframework-onap/tests/ONAPLibrary/RequestsHelperTests.py @@ -44,7 +44,27 @@ class RequestsHelperTests(TestCase): def test_post(self): with requests_mock.mock() as m: rh = RequestsHelper() - m.get('http://test.com/', text='data') - resp = rh.get_request(alias="alias", endpoint="http://test.com", data_path="/", sdc_user="test123", - accept="application/json", content_type="application/json", files="test/123") - self.assertEqual("data", resp.text)
\ No newline at end of file + m.post('http://test.com/', text='data') + resp = rh.post_request(alias="alias", endpoint="http://test.com", data_path="/", sdc_user="test123", + accept="application/json", content_type="application/json", files={'file':"test/123"}) + self.assertEqual("data", resp.text) + + def test_md5_string(self): + with requests_mock.mock() as m: + rh = RequestsHelper() + m.post('http://test.com/', text='data', additional_matcher=self._match_md5_request_header) + resp = rh.post_request(alias="alias", endpoint="http://test.com", data_path="/", sdc_user="test123", + accept="application/json", content_type="text/string", data="test/123") + self.assertEqual("data", resp.text) + + def test_md5_bytes(self): + with requests_mock.mock() as m: + rh = RequestsHelper() + m.post('http://test.com/', text='data', additional_matcher=self._match_md5_request_header) + resp = rh.post_request(alias="alias", endpoint="http://test.com", data_path="/", sdc_user="test123", + accept="application/json", content_type="text/string", data=b"test/123") + self.assertEqual("data", resp.text) + + @staticmethod + def _match_md5_request_header(request): + return (request.headers.get('Content-MD5', None)) is not None |