Skip to content

Commit

Permalink
Merge pull request #38 from andreroggeri/master
Browse files Browse the repository at this point in the history
Add metadata serialization/deserialization
  • Loading branch information
platinummonkey authored Feb 18, 2021
2 parents 7e67ea6 + 91fc9b6 commit 3c1c8e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions wiremock/resources/mappings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class MappingRequest(BaseAbstractEntity):
headers = JsonProperty("headers", klass=dict)
query_parameters = JsonProperty("queryParameters", klass=dict)
body_patterns = JsonProperty("bodyPatterns", klass=list, list_klass=dict)
metadata = JsonProperty("metadata", klass=dict)


@add_metaclass(BaseEntityMetaType)
Expand All @@ -148,6 +149,7 @@ class MappingResponse(BaseAbstractEntity):
status_message = JsonProperty("statusMessage")
transformer_parameters = JsonProperty("transformerParameters", klass=dict)
transformers = JsonProperty("transformers", klass=list)
metadata = JsonProperty("metadata", klass=dict)


class Mapping(BaseEntity):
Expand All @@ -159,6 +161,7 @@ class Mapping(BaseEntity):
new_scenario_state = JsonProperty("newScenarioState")
required_scenario_state = JsonProperty("requiredScenarioState")
scenario_name = JsonProperty("scenarioName")
metadata = JsonProperty('metadata', klass=dict)


@add_metaclass(BaseEntityMetaType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def test_mapping_request_serialization(self):
headers={"Accept": "stuff"},
query_parameters={"param": "1"},
body_patterns={"test": "test2"},
metadata={'key': 'value'}
)
serialized = e.get_json_data()
self.assertDictContainsKeyWithValue(serialized, "method", "GET")
Expand All @@ -86,6 +87,7 @@ def test_mapping_request_serialization(self):
self.assertDictContainsKeyWithValue(serialized, "headers", {"Accept": "stuff"})
self.assertDictContainsKeyWithValue(serialized, "queryParameters", {"param": "1"})
self.assertDictContainsKeyWithValue(serialized, "bodyPatterns", {"test": "test2"})
self.assertDictContainsKeyWithValue(serialized, "metadata", {"key": "value"})

@attr("unit", "serialization", "mappings")
def test_mapping_request_deserialization(self):
Expand All @@ -100,6 +102,7 @@ def test_mapping_request_deserialization(self):
"headers": {"Accept": "stuff"},
"queryParameters": {"param": "1"},
"bodyPatterns": {"test": "test2"},
'metadata': {'key': [1, 2, 3]},
}
e = MappingRequest.from_dict(serialized)
self.assertIsInstance(e, MappingRequest)
Expand All @@ -115,6 +118,7 @@ def test_mapping_request_deserialization(self):
self.assertEquals({"Accept": "stuff"}, e.headers)
self.assertEquals({"param": "1"}, e.query_parameters)
self.assertEquals({"test": "test2"}, e.body_patterns)
self.assertEquals({"key": [1, 2, 3]}, e.metadata)

@attr("unit", "serialization", "mappings")
def test_mapping_response_serialization(self):
Expand Down Expand Up @@ -241,14 +245,14 @@ def test_mapping_deserialization(self):

@attr("unit", "serialization", "mappings")
def test_all_mappings_serialization(self):
e = AllMappings(mappings=[Mapping(priority=1),], meta=MappingMeta(total=1))
e = AllMappings(mappings=[Mapping(priority=1), ], meta=MappingMeta(total=1))
serialized = e.get_json_data()
self.assertDictContainsKeyWithValue(serialized, "mappings", [{"priority": 1},])
self.assertDictContainsKeyWithValue(serialized, "mappings", [{"priority": 1}, ])
self.assertDictContainsKeyWithValue(serialized, "meta", {"total": 1})

@attr("unit", "serialization", "mappings")
def test_all_mappings_deserialization(self):
serialized = {"mappings": [{"priority": 1},], "meta": {"total": 1}}
serialized = {"mappings": [{"priority": 1}, ], "meta": {"total": 1}}
e = AllMappings.from_dict(serialized)
self.assertIsInstance(e, AllMappings)
self.assertIsInstance(e.mappings, list)
Expand Down

0 comments on commit 3c1c8e4

Please sign in to comment.