Skip to content

Commit

Permalink
Add tests for #36 SomethingLike not supporting Terms
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewbalvanz-wf committed Jul 16, 2017
1 parent 05b4d70 commit e382eb4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
6 changes: 4 additions & 2 deletions e2e/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
status=200,
headers={'Content-Type': 'application/json'},
response=json.dumps({'results': [
{'username': 'bob', 'id': 101, 'groups': [234, 123]},
{'username': 'sue', 'id': 102, 'groups': [345, 123]}]})),
{'username': 'bob', 'id': 101, 'groups': [234, 123],
'meta': {'name': 'favorite-color', 'value': 'blue'}},
{'username': 'sue', 'id': 102, 'groups': [345, 123],
'meta': {'name': 'supervisor', 'value': 'mary'}}]})),
'no users exist': Response(
status=200,
headers={'Content-Type': 'application/json'},
Expand Down
10 changes: 8 additions & 2 deletions e2e/contracts/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def test_nested(self):
'username': Term('\w+', 'bob'),
'id': SomethingLike(123),
'groups': EachLike(123),
'meta': SomethingLike({
'name': Term('.+', 'sample'),
'value': Term('.+', 'data')
})
}, minimum=2)}))

with pact:
Expand All @@ -120,8 +124,10 @@ def test_nested(self):

self.assertEqual(results.json(), {
'results': [
{'username': 'bob', 'id': 123, 'groups': [123]},
{'username': 'bob', 'id': 123, 'groups': [123]}]})
{'username': 'bob', 'id': 123, 'groups': [123],
'meta': {'name': 'sample', 'value': 'data'}},
{'username': 'bob', 'id': 123, 'groups': [123],
'meta': {'name': 'sample', 'value': 'data'}}]})

def test_falsey_bodies(self):
(pact
Expand Down
20 changes: 19 additions & 1 deletion pact/test/test_matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,31 @@ def test_invalid_types(self):

self.assertIn('matcher must be one of ', str(e.exception))

def test_call(self):
def test_basic_type(self):
generate = SomethingLike(123).generate()

self.assertEqual(
generate,
{'json_class': 'Pact::SomethingLike', 'contents': 123})

def test_complex_type(self):
generate = SomethingLike({'name': Term('.+', 'admin')}).generate()

self.assertEqual(
generate,
{'json_class': 'Pact::SomethingLike',
'contents': {'name': {
'json_class': 'Pact::Term',
'data': {
'matcher': {
'json_class': 'Regexp',
's': '.+',
'o': 0
},
'generate': 'admin'
}
}}})


class TermTestCase(TestCase):
def test_regex(self):
Expand Down

0 comments on commit e382eb4

Please sign in to comment.