X-Git-Url: https://git.teslayout.com/public/public/public/?p=anna.git;a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2Fresources%2Frest_api%2Fct%2Fconftest.py;fp=example%2Fdiameter%2Flauncher%2Fresources%2Frest_api%2Fct%2Fconftest.py;h=81f703bf000b3e6978043c984f90a28b5b3b87f1;hp=fd4f3396f050ab67effa7b74f819eff20d0c42e7;hb=d444f6e9cab931a4364c15b86ab221e55893f975;hpb=e782294456d0877aa8fc05aa931291ac79808eb3 diff --git a/example/diameter/launcher/resources/rest_api/ct/conftest.py b/example/diameter/launcher/resources/rest_api/ct/conftest.py index fd4f339..81f703b 100644 --- a/example/diameter/launcher/resources/rest_api/ct/conftest.py +++ b/example/diameter/launcher/resources/rest_api/ct/conftest.py @@ -9,6 +9,7 @@ import logging import os import pytest import re +import xmltodict ############# # CONSTANTS # @@ -128,6 +129,39 @@ def b64_decode(): 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.