Skip to content

Commit e382eb4

Browse files
Add tests for #36 SomethingLike not supporting Terms
1 parent 05b4d70 commit e382eb4

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

e2e/app.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
status=200,
3030
headers={'Content-Type': 'application/json'},
3131
response=json.dumps({'results': [
32-
{'username': 'bob', 'id': 101, 'groups': [234, 123]},
33-
{'username': 'sue', 'id': 102, 'groups': [345, 123]}]})),
32+
{'username': 'bob', 'id': 101, 'groups': [234, 123],
33+
'meta': {'name': 'favorite-color', 'value': 'blue'}},
34+
{'username': 'sue', 'id': 102, 'groups': [345, 123],
35+
'meta': {'name': 'supervisor', 'value': 'mary'}}]})),
3436
'no users exist': Response(
3537
status=200,
3638
headers={'Content-Type': 'application/json'},

e2e/contracts/test_e2e.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ def test_nested(self):
112112
'username': Term('\w+', 'bob'),
113113
'id': SomethingLike(123),
114114
'groups': EachLike(123),
115+
'meta': SomethingLike({
116+
'name': Term('.+', 'sample'),
117+
'value': Term('.+', 'data')
118+
})
115119
}, minimum=2)}))
116120

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

121125
self.assertEqual(results.json(), {
122126
'results': [
123-
{'username': 'bob', 'id': 123, 'groups': [123]},
124-
{'username': 'bob', 'id': 123, 'groups': [123]}]})
127+
{'username': 'bob', 'id': 123, 'groups': [123],
128+
'meta': {'name': 'sample', 'value': 'data'}},
129+
{'username': 'bob', 'id': 123, 'groups': [123],
130+
'meta': {'name': 'sample', 'value': 'data'}}]})
125131

126132
def test_falsey_bodies(self):
127133
(pact

pact/test/test_matchers.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,31 @@ def test_invalid_types(self):
6969

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

72-
def test_call(self):
72+
def test_basic_type(self):
7373
generate = SomethingLike(123).generate()
7474

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

79+
def test_complex_type(self):
80+
generate = SomethingLike({'name': Term('.+', 'admin')}).generate()
81+
82+
self.assertEqual(
83+
generate,
84+
{'json_class': 'Pact::SomethingLike',
85+
'contents': {'name': {
86+
'json_class': 'Pact::Term',
87+
'data': {
88+
'matcher': {
89+
'json_class': 'Regexp',
90+
's': '.+',
91+
'o': 0
92+
},
93+
'generate': 'admin'
94+
}
95+
}}})
96+
7997

8098
class TermTestCase(TestCase):
8199
def test_regex(self):

0 commit comments

Comments
 (0)