def test_nested(self): request = [ EachLike({ 'username': Term('[a-zA-Z]+', 'firstlast'), 'id': SomethingLike(123) }) ] self.assertEqual(from_term(request), [{ 'contents': { 'id': { 'contents': 123, 'json_class': 'Pact::SomethingLike' }, 'username': { 'data': { 'generate': 'firstlast', 'matcher': { 'json_class': 'Regexp', 'o': 0, 's': '[a-zA-Z]+' } }, 'json_class': 'Pact::Term' } }, 'json_class': 'Pact::ArrayLike', 'min': 1 }])
def test_nested_matchers(self): matcher = EachLike({ 'username': Term('[a-z]+', 'user'), 'id': SomethingLike(123) }) generate = matcher.generate() self.assertEqual( generate, { 'json_class': 'Pact::ArrayLike', 'contents': { 'username': { 'json_class': 'Pact::Term', 'data': { 'matcher': { 'json_class': 'Regexp', 's': '[a-z]+', 'o': 0 }, 'generate': 'user' } }, 'id': { 'json_class': 'Pact::SomethingLike', 'contents': 123 } }, 'min': 1 })
def test_nested(self): input = [ EachLike({ 'username': Term('[a-zA-Z]+', 'firstlast'), 'id': SomethingLike(123)})] self.assertEqual( get_generated_values(input), [[{'username': '******', 'id': 123}]])
def test_term(self): self.assertEqual( from_term(Term('[a-f0-9]+', 'abc123')), {'json_class': 'Pact::Term', 'data': { 'matcher': { 'json_class': 'Regexp', 's': '[a-f0-9]+', 'o': 0}, 'generate': 'abc123'}})
def test_regex(self): generate = Term('[a-zA-Z]', 'abcXYZ').generate() self.assertEqual( generate, {'json_class': 'Pact::Term', 'data': { 'matcher': { 'json_class': 'Regexp', 's': '[a-zA-Z]', 'o': 0}, 'generate': 'abcXYZ'}})
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' } }}})
def test_matcher_in_path_gets_converted(self): target = Request('GET', Term('\/.+', '/test-path')) result = target.json() self.assertTrue(isinstance(result['path'], dict))
def test_term(self): self.assertEqual(get_generated_values(Term('[a-f0-9]+', 'abc123')), 'abc123')