import os
import pytest
import re
+import xmltodict
#############
# CONSTANTS #
return message_bytes.decode('ascii')
return decode
+@pytest.fixture(scope='session')
+def saveB64Artifact(b64_decode):
+ """
+ Decode base64 string provided to disk
+
+ base64_message: base64 encoded string
+ file_basename: file basename where to write
+ isXML: decoded data corresponds to xml string. In this case, also json equivalente representation is written to disk
+ """
+ def save_b64_artifact(base64_message, file_basename, isXML = True):
+
+ targetFile = file_basename + ".txt"
+ data = b64_decode(base64_message)
+
+ if isXML:
+ targetFile = file_basename + ".xml"
+
+ _file = open(targetFile, "w")
+ n = _file.write(data)
+ _file.close()
+
+ if isXML:
+ targetFile = file_basename + ".json"
+ xml_dict = xmltodict.parse(data)
+ data = json.dumps(xml_dict, indent = 4, sort_keys=True)
+
+ _file = open(targetFile, "w")
+ n = _file.write(data)
+ _file.close()
+
+ return save_b64_artifact
+
+
# HTTP communication:
class RestClient(object):
"""A client helper to perform rest operations: GET, POST.