Skip to content

Commit

Permalink
check request body against regex
Browse files Browse the repository at this point in the history
  • Loading branch information
barrettj12 committed Oct 18, 2023
1 parent 7547fbf commit 702bba2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tests/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_metrics_endpoint_relation_created(self, open):
mock_opener.expect(
url='http://localhost/metrics-users',
method='POST',
# TODO: test body
body_regex=r'{"username": "juju-metrics-r\d+", "password": ".*"}',
response=mockResponse(
headers=mockHeaders(content_type='application/json'),
body='{"message":"created user \\"juju-metrics-r0\\""}'
Expand All @@ -88,15 +88,16 @@ class mockOpener:
def __init__(self, test_case):
self.test = test_case

def expect(self, url, method, response):
def expect(self, url, method, body_regex, response):
self.url = url
self.method = method

self.body_regex = body_regex
self.response = response

def open(self, request, timeout):
self.test.assertEqual(request.full_url, self.url)
self.test.assertEqual(request.method, self.method)
self.test.assertRegex(str(request.data), expected_regex=self.body_regex)

return self.response

Expand Down

0 comments on commit 702bba2

Please sign in to comment.