Exemple #1
0
def test_001_i_want_to_check_global_data_on_admin_interface(
        h2ac_admin, admin_global_variable):

    # Check that there is no global variables here
    response = h2ac_admin.get(ADMIN_GLOBAL_VARIABLE_URI)
    assert response["status"] == 204

    # Configure and check global variables:
    admin_global_variable(string2dict(GLOBAL_VARIABLE_1_2_3))
    response = h2ac_admin.get(ADMIN_GLOBAL_VARIABLE_URI)
    h2ac_admin.assert_response__status_body_headers(
        response, 200, string2dict(GLOBAL_VARIABLE_1_2_3))

    # Now, get specific variable:
    response = h2ac_admin.get(ADMIN_GLOBAL_VARIABLE_URI + "?name=var1")
    h2ac_admin.assert_response__status_body_headers(response, 200, "value1")

    # Delete var1 twice to check 200 and 204:
    response = h2ac_admin.delete(ADMIN_GLOBAL_VARIABLE_URI + "?name=var1")
    assert response["status"] == 200
    response = h2ac_admin.delete(ADMIN_GLOBAL_VARIABLE_URI + "?name=var1")
    assert response["status"] == 204

    # Global deletion twice to check 200 and 204:
    response = h2ac_admin.delete(ADMIN_GLOBAL_VARIABLE_URI)
    assert response["status"] == 200
    response = h2ac_admin.delete(ADMIN_GLOBAL_VARIABLE_URI)
    assert response["status"] == 204

    response = h2ac_admin.get(ADMIN_GLOBAL_VARIABLE_URI)
    h2ac_admin.assert_response__status_body_headers(response, 204, "")
Exemple #2
0
def test_045_requestBodyStringToResponseObject(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="request.body", target="response.body.json.object"))

  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST), requestHeaders=None) # request body will be interpreted as string
  responseBodyRef = "{\"node1\":{\"node2\":\"value-of-node1-node2\"}}"
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #3
0
def test_048_mathCalculationToResponseInteger(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="math.1+2+3+5+8", target="response.body.json.integer./math-calculation"))

  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  responseBodyRef = { "foo":"bar-1", "math-calculation":19 }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #4
0
def test_047_requestBodyJsonToResponseString(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="request.body", target="response.body.json.string"))

  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  responseBodyRef = { "foo":"bar-1" } # request body json is ignored as cannot be set as target string. The template request body is configured instead
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #5
0
def test_006_inState(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="inState", target="response.body.json.string./in-state"))

  # Traffic
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  responseBodyRef = { "foo":"bar-1", "in-state":"initial" }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #6
0
def test_022_valueToResponseBodyJsonStringPath(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="value.[{\\\"id\\\":\\\"2000\\\"},{\\\"id\\\":\\\"2001\\\"}]", target="response.body.json.jsonstring./array"))

  # Traffic
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  responseBodyRef = { "foo":"bar-1", "array": [ { "id": "2000" }, { "id": "2001" } ] }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #7
0
def test_007_inStateToResponseBodyBoolean(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="inState", target="response.body.json.boolean./boolean"))

  # Traffic
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  assert response["status"] == 200
  assert response["body"] == "true"
Exemple #8
0
def test_016_requestHeader(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="request.header.test-id", target="response.body.json.string./request-header-test-id"))

  # Traffic
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST), { "test-type":"development", "test-id":"general" })
  responseBodyRef = { "foo":"bar-1", "request-header-test-id":"general" }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #9
0
def test_015_objectPathToResponsePath(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="request.body./node1/node2", target="response.body.json.string./request/node1/node2"))

  # Traffic
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  responseBodyRef = { "foo":"bar-1", "request":{ "node1": { "node2": "value-of-node1-node2" } } }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #10
0
def test_014_valueToResponseBodyUnsignedPath(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="value.111", target="response.body.json.unsigned./transferredValue"))

  # Traffic
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  responseBodyRef = { "foo":"bar-1", "transferredValue":111 }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #11
0
def test_030_responseToResponseBodyObjectPath(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="response.body", target="response.body.json.object./responseAgain"))

  # Traffic
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  responseBodyRef = { "foo":"bar-1", "responseAgain": { "foo":"bar-1" } }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #12
0
def test_042_transferFixedValueToResponseBodyPathWithReplacedVariablesAsJsonstring(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="value.[\\\"aa\\\",\\\"bb\\\"]", target="response.body.json.jsonstring./@{var1}/@{var2}"))

  # Traffic
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  responseBodyRef = { "foo":"bar-1", "var1value": { "var2value": [ "aa", "bb" ] } }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #13
0
def test_035_replaceVariablesAtResponseBodyPathAndTransferToResponseBodyStringPath(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_AND_VAR1_VAR2_PROVISION_TEMPLATE, id=1, queryp='', source="response.body./@{var1}/@{var2}", target="response.body.json.string./result"))

  # Traffic
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  responseBodyRef = { "foo":"bar-1", "var1value": { "var2value": "value-of-var1value-var2value" }, "result": "value-of-var1value-var2value" }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #14
0
def test_046_requestBodyStringToResponseString(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="request.body", target="response.body.json.string"))

  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST), requestHeaders=None) # request body will be interpreted as string
  responseBodyRef = "{\"node1\":{\"node2\":\"value-of-node1-node2\"}}" # although it seems a json, application/json content-type was missing,
                                                                       # so, it is interpreted like any other string.
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #15
0
def test_044_transferFixedValueToVariableNameWithReplacedVariables(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_TWO_TRANSFERS_PROVISION_TEMPLATE, id=1, queryp='', source="value.var1valuevalue", target="var.@{var1}", source2="var.@{var1}", target2="response.body.json.string./result"))

  # Traffic
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  responseBodyRef = { "foo":"bar-1", "result": "var1valuevalue" }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #16
0
def test_002_randomset(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="randomset.rock|paper|scissors", target="response.body.json.string./randomset"))

  # Traffic
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  choice = response["body"]["randomset"]
  responseBodyRef = { "foo":"bar-1", "randomset":choice }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #17
0
def test_004_strftime(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="strftime.Now it's %I:%M%p.", target="response.body.json.string./strftime"))

  # Traffic
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  value = response["body"]["strftime"]
  responseBodyRef = { "foo":"bar-1", "strftime":value }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #18
0
def test_043_transferFixedValueToHeaderNameWithReplacedVariables(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="value.header-value", target="response.header.@{var1}-@{var2}"))

  # Traffic
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  responseBodyRef = { "foo":"bar-1" }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef, headersDict = {})
  myHeader = response["headers"]["var1value-var2value"][0]
  assert(myHeader.decode('utf-8') == "header-value")
Exemple #19
0
def test_005_timestampNs(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="timestamp.ns", target="response.body.json.unsigned./nanoseconds-timestamp"))

  # Traffic
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  responseBodyRef = { "foo":"bar-1", "nanoseconds-timestamp":0 }
  # Replace unknown node to allow comparing:
  response["body"]["nanoseconds-timestamp"] = 0
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #20
0
def test_033_replaceVariablesAtRandomsetAndTransferToResponseBodyStringPath(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="randomset.@{var1}|@{var2}", target="response.body.json.string./result"))

  # Traffic
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  choice = response["body"]["result"]
  responseBodyRef = { "foo":"bar-1", "result":choice }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
  assert(choice == "var1value" or choice == "var2value")
Exemple #21
0
def test_032_replaceVariablesAtStrftimeAndTransferToResponseBodyStringPath(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="strftime.Now it's %I:%M%p and var1 is @{var1}.", target="response.body.json.string./result"))

  # Traffic
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  value = response["body"]["result"]
  responseBodyRef = { "foo":"bar-1", "result":value }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
  pos = value.find('and var1 is var1value.')
  assert(pos != -1)
Exemple #22
0
def test_001_i_want_to_configure_schemas_and_corresponding_provision_on_admin_interface(
        admin_server_provision, admin_schema):

    admin_server_provision(
        string2dict(SCHEMAS_PROVISION_TEMPLATE,
                    reqId="myRequestsSchemaId",
                    resId="myResponsesSchemaId",
                    responseBodyField="bar"))
    admin_schema(
        string2dict(MY_REQUESTS_SCHEMA_ID_TEMPLATE,
                    id="myRequestsSchemaId",
                    requiredProperty="foo"))
    admin_schema(
        string2dict(MY_REQUESTS_SCHEMA_ID_TEMPLATE,
                    id="myResponsesSchemaId",
                    requiredProperty="bar"))
Exemple #23
0
def test_002_i_want_to_check_global_data_on_admin_interface_due_to_traffic(
        h2ac_admin, h2ac_traffic, admin_server_provision,
        admin_global_variable):

    # Configure global variables var1, var2 and var3:
    admin_global_variable(string2dict(GLOBAL_VARIABLE_1_2_3))

    # Provision
    admin_server_provision(
        string2dict(
            GLOBAL_VARIABLE_PROVISION_TEMPLATE_GVARCREATED_GVARREMOVED_GVARANSWERED,
            gvarcreated="var4",
            gvarremoved="var2",
            gvaranswered="varMissing"))

    # Traffic and global variables
    response = h2ac_traffic.post("/app/v1/foo/bar")
    h2ac_traffic.assert_response__status_body_headers(response, 200,
                                                      {"foo": "bar"})
    response = h2ac_admin.get(ADMIN_GLOBAL_VARIABLE_URI)
    h2ac_admin.assert_response__status_body_headers(response, 200, {
        "var1": "value1",
        "var3": "value3",
        "var4": "var4value"
    })

    # Provision
    admin_server_provision(
        string2dict(
            GLOBAL_VARIABLE_PROVISION_TEMPLATE_GVARCREATED_GVARREMOVED_GVARANSWERED,
            gvarcreated="var2",
            gvarremoved="var1",
            gvaranswered="var4"))

    # Traffic and global variables
    response = h2ac_traffic.post("/app/v1/foo/bar")
    h2ac_traffic.assert_response__status_body_headers(
        response, 200, {
            "foo": "bar",
            "gvaranswered": "var4value"
        })
    response = h2ac_admin.get(ADMIN_GLOBAL_VARIABLE_URI)
    h2ac_admin.assert_response__status_body_headers(response, 200, {
        "var2": "var2value",
        "var3": "value3",
        "var4": "var4value"
    })
Exemple #24
0
def test_018_requestUriPathToResponseBodyStringPath(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='?name=test', source="request.uri.path", target="response.body.json.string./requestUriPath"))

  # Traffic
  response = h2ac_traffic.post("/app/v1/foo/bar/1?name=test")
  responseBodyRef = {'foo': 'bar-1', 'requestUriPath': '/app/v1/foo/bar/1'}
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #25
0
def test_021_emptyValueToResponseBodyStringPath(admin_server_provision, h2ac_traffic):

  # Provision
  admin_server_provision(string2dict(TRANSFORM_FOO_BAR_PROVISION_TEMPLATE, id=1, queryp='', source="value.", target="response.body.json.string./value"))

  # Traffic
  response = h2ac_traffic.post("/app/v1/foo/bar/1")
  responseBodyRef = { "foo":"bar-1", "value":"" }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #26
0
def test_009_i_want_to_check_prioritymatchingregex_on_traffic_interface(
        admin_cleanup, admin_server_provision, h2ac_traffic):

    # Cleanup and set RegexMatching matching algorithm:
    admin_cleanup(matchingContent={"algorithm": "RegexMatching"})

    # Provisions
    admin_server_provision(
        string2dict(REGEX_FOO_BAR_PROVISION_TEMPLATE, id=55500, trailing=4))
    admin_server_provision(
        string2dict(REGEX_FOO_BAR_PROVISION_TEMPLATE, id=5551122, trailing=2))
    admin_server_provision(
        string2dict(REGEX_FOO_BAR_PROVISION_TEMPLATE, id=555112244,
                    trailing=0))

    # Send GET
    response = h2ac_traffic.get("/app/v1/id-555112244/ts-1615562841")
    responseBodyRef = {"foo": "bar-5551122"}
    h2ac_traffic.assert_response__status_body_headers(response, 200,
                                                      responseBodyRef)
Exemple #27
0
def test_024_eventBodyToResponseBodyPath(admin_cleanup, admin_server_provision, h2ac_traffic):

  # Cleanup
  admin_cleanup()

  # Provision
  admin_server_provision("no_filter_test.EventBody.provision.json")

  # Traffic

  # First time, there is nothing (no request number 0 exists), so, responseBody won't add event information:
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", string2dict(NESTED_NODE1_NODE2_REQUEST))
  responseBodyRef = { "foo":"bar-1" }
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)

  # Second time, we will have the previous traffic event as reference (number 0), and responseBody will add
  # the request body which was received. We will send now another different request body to make safer the test:
  response = h2ac_traffic.postDict("/app/v1/foo/bar/1", { "anotherRequest": "foo" })
  responseBodyRef["firstRequestBody"] = string2dict(NESTED_NODE1_NODE2_REQUEST)
  responseBodyRef["foo"] = "bar-1"
  h2ac_traffic.assert_response__status_body_headers(response, 200, responseBodyRef)
Exemple #28
0
def test_010_i_want_to_get_answer_for_default_provision_on_traffic_interface(
        admin_server_provision, h2ac_traffic):

    # Provision
    admin_server_provision(string2dict(FALLBACK_DEFAULT_PROVISION))

    # Send GET
    response = h2ac_traffic.get(
        "/app/v1/foo/bar/this-is-not-explicitly-provisioned")

    # Verify response
    responseBodyRef = {"foo": "default", "bar": "default"}
    h2ac_traffic.assert_response__status_body_headers(response, 200,
                                                      responseBodyRef)
Exemple #29
0
def test_002_i_want_to_retrieve_current_schemas_on_admin_interface(h2ac_admin):

    # Send GET
    response = h2ac_admin.get(ADMIN_SCHEMA_URI)

    # Verify response
    assert response["status"] == 200
    response0 = response["body"][0]
    response1 = response["body"][1]
    id0 = response0["id"]
    id1 = response1["id"]
    schemaReq = string2dict(MY_REQUESTS_SCHEMA_ID_TEMPLATE,
                            id="myRequestsSchemaId",
                            requiredProperty="foo")
    schemaRes = string2dict(MY_REQUESTS_SCHEMA_ID_TEMPLATE,
                            id="myResponsesSchemaId",
                            requiredProperty="bar")
    if id0 == "myRequestsSchemaId":
        assert response0 == schemaReq
        assert response1 == schemaRes
    else:
        assert response0 == schemaRes
        assert response1 == schemaReq
Exemple #30
0
def test_002_i_want_to_retrieve_current_provisions_on_admin_interface(
        admin_server_matching, h2ac_admin):

    # Configure to have provisions ordered:
    admin_server_matching({"algorithm": "RegexMatching"})

    # Send GET
    response = h2ac_admin.get(ADMIN_SERVER_PROVISION_URI)

    # Verify response
    assert response["status"] == 200
    for id in range(5):
        response_dict = response["body"][id]
        assert response_dict == string2dict(BASIC_FOO_BAR_PROVISION_TEMPLATE,
                                            id=id)