From 702bba228c6bac1de82addc8bfcd02250557ed90 Mon Sep 17 00:00:00 2001 From: Jordan Barrett Date: Wed, 18 Oct 2023 10:51:05 +0700 Subject: [PATCH] check request body against regex --- tests/test_charm.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_charm.py b/tests/test_charm.py index 3301ab1..2cca2b8 100644 --- a/tests/test_charm.py +++ b/tests/test_charm.py @@ -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\\""}' @@ -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