docker-images/anna-adml-http/opt/
# Component test (pytest)
-__pycache__
+example/diameter/launcher/resources/rest_api/ct/**/__pycache__
+example/diameter/launcher/resources/rest_api/ct/helpers/*.xml
+example/diameter/launcher/resources/rest_api/ct/helpers/*.json
+example/diameter/launcher/resources/rest_api/ct/helpers/*.txt
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.
--- /dev/null
+import pytest
+
+
+@pytest.mark.helpers
+def test_001_save_answermsg2e(saveB64Artifact, admlc):
+
+ requestBody = { "name":"afHost.afRealm.com" }
+ responseBodyRef = { "success":"true", "response":"Forced node is now 'afHost.afRealm.com'" }
+
+ # Send POST
+ response = admlc.postDict("/node", requestBody)
+
+ # Verify response
+ admlc.assert_response__status_body_headers(response, 200, responseBodyRef)
+
+ # Send POST
+ response = admlc.postDict("/answermsg2e", { "action":"" })
+
+ # Verify response
+ assert response["status"] == 200
+ assert response["body"]["success"] == "true"
+
+ # Save artifact from base64 encoded string received
+ saveB64Artifact(response["body"]["response"], "helpers/answermsg2e", False) # it is direct text content
+
+@pytest.mark.helpers
+def test_002_save_answermsg2c(saveB64Artifact, admlc):
+
+ requestBody = { "name":"ownHostId.operatorRealm.com" }
+ responseBodyRef = { "success":"true", "response":"Forced node is now 'ownHostId.operatorRealm.com'" }
+
+ # Send POST
+ response = admlc.postDict("/node", requestBody)
+
+ # Verify response
+ admlc.assert_response__status_body_headers(response, 200, responseBodyRef)
+
+ # Send POST
+ response = admlc.postDict("/answermsg2c", { "action":"" })
+
+ # Verify response
+ assert response["status"] == 200
+ assert response["body"]["success"] == "true"
+
+ # Save artifact from base64 encoded string received
+ saveB64Artifact(response["body"]["response"], "helpers/answermsg2c", False) # it is direct text content
--- /dev/null
+import pytest
+
+
+@pytest.mark.helpers
+def test_001_save_decoded(saveB64Artifact, b64_encode, resources, admlc):
+
+ diameterHex = resources("aaa.hex")
+ #requestBody = resources("aaa-diameterHex.json.in", diameterHex=diameterHex.rstrip())
+ requestBodyDict = { "diameterHex":"{}".format(diameterHex.rstrip()) }
+
+ # reponse field in response body, should carry the base64 encoding for xml message decoded by ADML:
+ xmlExpected = resources("aaa.xml")
+ responseBodyRef = { "success":"true", "response":"{}".format(b64_encode(xmlExpected)) }
+
+ # Send POST
+ response = admlc.postDict("/decode", requestBodyDict)
+
+ # Verify response
+ admlc.assert_response__status_body_headers(response, 200, responseBodyRef)
+
+ # Save artifact from base64 encoded string received
+ saveB64Artifact(response["body"]["response"], "helpers/decode")
--- /dev/null
+import pytest
+
+
+@pytest.mark.helpers
+def test_001_save_msg_loaded(saveB64Artifact, b64_encode, resources, admlc):
+
+ requestBody = resources("aar-diameterJson-request.json")
+
+ # reponse field in response body, should carry the base64 encoding for xml message loaded by ADML:
+ xmlExpected = resources("aar.xml")
+ responseBodyRef = { "success":"true", "response":"{}".format(b64_encode(xmlExpected)) }
+
+ # Send POST
+ response = admlc.post("/loadmsg", requestBody)
+
+ ### Verify response
+ admlc.assert_response__status_body_headers(response, 200, responseBodyRef)
+
+ # Save artifact from base64 encoded string received
+ saveB64Artifact(response["body"]["response"], "helpers/loadmsg")
--- /dev/null
+import pytest
+
+@pytest.mark.helpers
+def test_001_save_node(saveB64Artifact, admlc):
+
+ requestBody = { "name":"afHost.afRealm.com" }
+ responseBodyRef = { "success":"true", "response":"Forced node is now 'afHost.afRealm.com'" }
+
+ # Send POST
+ response = admlc.postDict("/node", requestBody)
+
+ # Verify response
+ admlc.assert_response__status_body_headers(response, 200, responseBodyRef)
+
+ requestBody = { "name":"" }
+
+ # Send POST
+ response = admlc.postDict("/node", requestBody)
+
+ # Verify response is ok (omit response content because it is informative and have dynamic data (timing)):
+ assert response["status"] == 200
+ assert response["body"]["success"] == "true"
+
+ # Save artifact from base64 encoded string received
+ saveB64Artifact(response["body"]["response"], "helpers/node")
+
--- /dev/null
+import pytest
+
+
+@pytest.mark.helpers
+def test_001_save_oam(saveB64Artifact, admlc):
+
+ # Send GET
+ response = admlc.get("/show-oam")
+
+ # Verify response is ok (omit response content because it is informative and have dynamic data (timing)):
+ assert response["status"] == 200
+ assert response["body"]["success"] == "true"
+
+ # Save artifact from base64 encoded string received
+ saveB64Artifact(response["body"]["response"], "helpers/show-oam")
+
--- /dev/null
+import pytest
+
+
+@pytest.mark.helpers
+def test_001_save_statistics(saveB64Artifact, admlc):
+
+ # Send GET
+ response = admlc.get("/show-stats")
+
+ # Verify response is ok (omit response content because it is informative and have dynamic data (timing)):
+ assert response["status"] == 200
+ assert response["body"]["success"] == "true"
+
+ # Save artifact from base64 encoded string received
+ saveB64Artifact(response["body"]["response"], "helpers/show-stats")
+
--- /dev/null
+import pytest
+
+
+@pytest.mark.dynamic_helpers
+@pytest.mark.xfail(reason="To be used after dynamic mark execution")
+def test_001_save_test_look(saveB64Artifact, admlc):
+
+ # Send POST
+ response = admlc.postDict("/test-look", { "id":5000 })
+
+ # Verify response is ok (omit response content because it is informative and have dynamic data (timing)):
+ assert response["status"] == 200
+ assert response["body"]["success"] == "true"
+
+ # Save artifact from base64 encoded string received
+ saveB64Artifact(response["body"]["response"], "helpers/test-look")
+
--- /dev/null
+import pytest
+
+
+@pytest.mark.helpers
+def test_001_save_test_summary_counts(saveB64Artifact, admlc):
+
+ # Send GET
+ response = admlc.post("/test-summary-counts")
+
+ # Verify response is ok (omit response content because it is informative and have dynamic data (timing)):
+ assert response["status"] == 200
+ assert response["body"]["success"] == "true"
+
+ # Save artifact from base64 encoded string received
+ saveB64Artifact(response["body"]["response"], "helpers/test-summary-counts", False) # it is direct text content
+
--- /dev/null
+import pytest
+
+
+@pytest.mark.helpers
+def test_001_save_test_summary_states(saveB64Artifact, admlc):
+
+ # Send GET
+ response = admlc.post("/test-summary-states")
+
+ # Verify response is ok (omit response content because it is informative and have dynamic data (timing)):
+ assert response["status"] == 200
+ assert response["body"]["success"] == "true"
+
+ # Save artifact from base64 encoded string received
+ saveB64Artifact(response["body"]["response"], "helpers/test-summary-states", False) # it is direct text content
+
--- /dev/null
+import pytest
+
+
+@pytest.mark.helpers
+def test_001_save_test_summary(saveB64Artifact, admlc):
+
+ # Send GET
+ response = admlc.post("/test-summary")
+
+ # Verify response is ok (omit response content because it is informative and have dynamic data (timing)):
+ assert response["status"] == 200
+ assert response["body"]["success"] == "true"
+
+ # Save artifact from base64 encoded string received
+ saveB64Artifact(response["body"]["response"], "helpers/test-summary")
+
[pytest]
-addopts = -v --junitxml=/tmp/junit.xml -n 0 -m "not dynamic"
+addopts = -v --junitxml=/tmp/junit.xml -n 0 -m "not dynamic and not helpers"
log_format=%(asctime)s|%(name)s|%(filename)s:%(lineno)d|%(levelname)s|%(message)s
log_date_format = %Y-%m-%d %H:%M:%S
# Markers
markers =
dynamic: this test requires ADML dynamic test library enabled (/opt/adml/dynlibs)
+ helpers: auxiliary helpers to check ADML state and reports
+ dynamic_helpers: auxiliary helpers for dynamic context
pytest-ordering
pytest-xdist
+xmltodict
"@version": "1",
"avp": [
{
- "@data": "tc_01_FullAVPs;afNodeHostname.afNodeHostRealm.com;1;859608",
+ "@data": "FullAVPs;afNodeHostname.afNodeHostRealm.com;1;859608",
"@name": "Session-Id"
},
{
"@name": "Auth-Application-Id"
},
{
- "@data": "sapcOwnHostId.operatorRealm.com",
+ "@data": "ownHostId.operatorRealm.com",
"@name": "Origin-Host"
},
{
-010000f80000010901000014000c73c30004cee4000001024000000c01000014000001074000004274635f30315f46756c6c415650733b61664e6f6465486f73746e616d652e61664e6f6465486f73745265616c6d2e636f6d3b313b38353936303800000000010840000027736170634f776e486f737449642e6f70657261746f725265616c6d2e636f6d000000010c4000000c000007d1000001164000000c551192a700000128400000196f70657261746f725265616c6d2e636f6d0000000000027480000038000028af0000010a4000000c000028af0000027580000010000028af000000010000027680000010000028af00000013
+010000ec0000010901000014000c73c30004cee4000001074000003c46756c6c415650733b61664e6f6465486f73746e616d652e61664e6f6465486f73745265616c6d2e636f6d3b313b383539363038000001024000000c0100001400000108400000236f776e486f737449642e6f70657261746f725265616c6d2e636f6d0000000128400000196f70657261746f725265616c6d2e636f6d0000000000010c4000000c000007d100000274c0000038000028af0000010a4000000c000028af0000027580000010000028af000000010000027680000010000028af00000013000001164000000c551192a7
\ No newline at end of file
<message version="1" name="AA-Answer" application-id="16777236" hop-by-hop-id="816067" end-to-end-id="315108">
- <avp name="Session-Id" data="tc_01_FullAVPs;afNodeHostname.afNodeHostRealm.com;1;859608"/>
+ <avp name="Session-Id" data="FullAVPs;afNodeHostname.afNodeHostRealm.com;1;859608"/>
<avp name="Auth-Application-Id" data="16777236"/>
- <avp name="Origin-Host" data="sapcOwnHostId.operatorRealm.com"/>
+ <avp name="Origin-Host" data="ownHostId.operatorRealm.com"/>
<avp name="Origin-Realm" data="operatorRealm.com"/>
<avp name="Result-Code" data="2001" alias="DIAMETER_SUCCESS"/>
<avp name="Supported-Features">