Пример #1
0
 def test_prepare_response_invalid_response_json(self):
     json_as_string = "Not a json string"
     try:
         ActionUtility.prepare_response("The value of ${a.b.3} in ${a.b.d.0} is ${a.b.c}", json_as_string)
         assert False
     except HttpActionFailure as e:
         assert str(e) == 'Could not find value for keys in response'
Пример #2
0
 def test_prepare_response_string_empty_request_output(self):
     json1 = json.dumps("{}")
     try:
         ActionUtility.prepare_response("The value of ${a.b.3} in ${a.b.d.0} is ${a.b.e}", json1)
         assert False
     except HttpActionFailure:
         assert True
Пример #3
0
    def test_prepare_response(self):
        json1 = json.dumps({
            "a": {
                "b": {
                    "3": 2,
                    "43": 30,
                    "c": [],
                    "d": ['red', 'buggy', 'bumpers'],
                }
            }
        })
        response = ActionUtility.prepare_response("The value of ${a.b.3} in ${a.b.d.0} is ${a.b.c}", json1)
        assert response == 'The value of 2 in red is []'

        json2 = json.dumps({
            "data": [
                {"a": {
                    "b": {
                        "43": 30,
                        "c": [],
                        "d": ['red', 'buggy', 'bumpers'],
                    }}},
                {"a": {
                    "b": {
                        "43": 5,
                        "c": [1, 2],
                        "d": ['buggy', 'bumpers'],
                    }}}
            ]
        })
        response = ActionUtility.prepare_response("The value of ${data.0.a} in ${data.0.a.b} is ${data.0.a.b.d}", json2)
        assert response == 'The value of {"b": {"43": 30, "c": [], "d": ["red", "buggy", "bumpers"]}} in {"43": 30, "c": [], "d": ["red", "buggy", "bumpers"]} is [\'red\', \'buggy\', \'bumpers\']'
Пример #4
0
 def test_prepare_response_key_not_present(self):
     json1 = json.dumps({
         "a": {
             "b": {
                 "3": 2,
                 "43": 30,
                 "c": [],
                 "d": ['red', 'buggy', 'bumpers'],
             }
         }
     })
     try:
         ActionUtility.prepare_response("The value of ${a.b.3} in ${a.b.d.0} is ${a.b.e}", json1)
         assert False
     except HttpActionFailure:
         assert True
Пример #5
0
 def test_prepare_response_string_empty_response_string(self):
     json1 = json.dumps({
         "a": {
             "b": {
                 "3": 2,
                 "43": 30,
                 "c": [],
                 "d": ['red', 'buggy', 'bumpers'],
             }
         }
     })
     response = ActionUtility.prepare_response("", json1)
     assert response == '{"a": {"b": {"3": 2, "43": 30, "c": [], "d": ["red", "buggy", "bumpers"]}}}'
Пример #6
0
 def test_prepare_response_string_response(self):
     json1 = json.dumps({
         "a": {
             "b": {
                 "3": 2,
                 "43": 30,
                 "c": [],
                 "d": ['red', 'buggy', 'bumpers'],
             }
         }
     })
     response = ActionUtility.prepare_response("The value of red is 0", json1)
     assert response == "The value of red is 0"
Пример #7
0
 def test_prepare_response_as_string_and_expected_as_none(self):
     response = ActionUtility.prepare_response(
         "The value of 2 in red is []", None)
     assert response == 'The value of 2 in red is []'
Пример #8
0
 def test_prepare_response_as_json_and_expected_as_plain_string(self):
     json_as_string = "Not a json string"
     response = ActionUtility.prepare_response(
         "The value of 2 in red is []", json_as_string)
     assert response == 'The value of 2 in red is []'