Skip to content

Commit

Permalink
Merge pull request #39 from andreroggeri/master
Browse files Browse the repository at this point in the history
Allow mapping to be deleted by metadata
  • Loading branch information
platinummonkey authored Feb 25, 2021
2 parents 9bbec90 + 4bfcd1a commit a6e3ce5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
10 changes: 10 additions & 0 deletions wiremock/resources/mappings/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def endpoint(cls):
def endpoint_single(cls):
return "/mappings/{id}"

@classmethod
def endpoint_delete_by_metadata(cls):
return "/mappings/remove-by-metadata"

@classmethod
def entity_class(cls):
return MappingResponse
Expand Down Expand Up @@ -72,5 +76,11 @@ def delete_mapping(cls, mapping_id, parameters={}):
response = cls.REST_CLIENT.delete(cls.get_base_uri(cls.endpoint_single(), **ids), headers=make_headers(), params=parameters)
return cls.REST_CLIENT.handle_response(response)

@classmethod
def delete_mapping_by_metadata(cls, metadata, parameters={}):
response = cls.REST_CLIENT.post(cls.get_base_uri(cls.endpoint_delete_by_metadata()), headers=make_headers(), params=parameters, json=metadata)

return cls.REST_CLIENT.handle_response(response)


__all__ = ["Mappings"]
16 changes: 15 additions & 1 deletion wiremock/tests/resource_tests/mappings_tests/resource_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_create_mapping(self):
@attr("unit", "mappings", "resource")
@responses.activate
def test_retrieve_all_mappings(self):
e = AllMappings(mappings=[Mapping(id="1234-5678", priority=1),], meta=MappingMeta(total=1))
e = AllMappings(mappings=[Mapping(id="1234-5678", priority=1), ], meta=MappingMeta(total=1))
resp = e.get_json_data()
responses.add(responses.GET, "http://localhost/__admin/mappings", json=resp, status=200)

Expand Down Expand Up @@ -87,3 +87,17 @@ def test_delete_mapping(self):

r = Mappings.delete_mapping(e)
self.assertEquals(200, r.status_code)

@attr("unit", "mappings", "resource")
@responses.activate
def test_delete_mapping_by_metadata(self):
responses.add(responses.POST, "http://localhost/__admin/mappings/remove-by-metadata", body='{}', status=200)

r = Mappings.delete_mapping_by_metadata({
"matchesJsonPath": {
"expression": "$.some.key",
"equalTo": "SomeValue"
}
})

self.assertEquals(200, r.status_code)

0 comments on commit a6e3ce5

Please sign in to comment.