Exemplo n.º 1
0
    def test_resolve_top_level_list_without_index(self):
        ws_response = WSResponse().with_attribute("//colour", "blue")

        test_data = [{
            "colour": "red"
        }, {
            "colour": "green"
        }, {
            "colour": "blue"
        }]

        self.assertTrue(ws_response.is_match(test_data))
Exemplo n.º 2
0
    def test_resolved_attribute_by_list_without_index_no_match(self):
        ws_response = WSResponse().with_attribute("body//colour", "yellow")

        test_data = {
            "body": [{
                "colour": "red"
            }, {
                "colour": "green"
            }, {
                "colour": "blue"
            }]
        }

        self.assertFalse(ws_response.is_match(test_data))
Exemplo n.º 3
0
    def test_resolved_attribute_by_list_index(self):
        ws_response = WSResponse().with_attribute("body/0/colour", "red")

        test_data = {
            "body": [{
                "colour": "red"
            }, {
                "colour": "green"
            }, {
                "colour": "blue"
            }]
        }

        self.assertTrue(ws_response.is_match(test_data))
Exemplo n.º 4
0
    def test_resolved_recursive_attribute_match(self):
        ws_response = WSResponse().with_attribute("body/first/second/third",
                                                  "value")

        test_data = {
            "type": "new_request",
            "body": {
                "first": {
                    "second": {
                        "third": "value",
                        "fourth": "not_value"
                    }
                }
            }
        }

        self.assertTrue(ws_response.is_match(test_data))
Exemplo n.º 5
0
    def test_resolve_by_key_when_list_fails(self):
        ws_response = WSResponse().with_attribute("body/colour", "red")

        test_data = {"body": ["red", "green", "blue"]}

        self.assertFalse(ws_response.is_match(test_data))
Exemplo n.º 6
0
    def test_resolve_by_index_when_dict_fails(self):
        ws_response = WSResponse().with_attribute("body/0/colour", "red")

        test_data = {"body": {"colour": "red"}}

        self.assertFalse(ws_response.is_match(test_data))
Exemplo n.º 7
0
    def test_resolved_attribute_by_just_list_index(self):
        ws_response = WSResponse().with_attribute("body/0/", "red")

        test_data = {"body": ["red", "green", "blue"]}

        self.assertTrue(ws_response.is_match(test_data))
Exemplo n.º 8
0
    def test_resolved_attribute_by_list_index_not_enough_elements(self):
        ws_response = WSResponse().with_attribute("body/0/colour", "red")

        test_data = {"body": []}

        self.assertFalse(ws_response.is_match(test_data))