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): 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_minimum(self): generate = EachLike(1, minimum=2).generate() self.assertEqual(generate, { 'json_class': 'Pact::ArrayLike', 'contents': 1, 'min': 2 })
def test_each_like(self): self.assertEqual(from_term(EachLike({'a': 1})), { 'json_class': 'Pact::ArrayLike', 'contents': { 'a': 1 }, 'min': 1 })
def test_default_options(self): generate = EachLike(1).generate() self.assertEqual(generate, { 'json_class': 'Pact::ArrayLike', 'contents': 1, '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_minimum_assertion_error(self): with self.assertRaises(AssertionError) as e: EachLike(1, minimum=0) self.assertEqual(str(e.exception), 'Minimum must be greater than or equal to 1')
def test_each_like_minimum(self): self.assertEqual(get_generated_values(EachLike({'a': 1}, minimum=5)), [{ 'a': 1 }] * 5)
def test_each_like(self): self.assertEqual(get_generated_values(EachLike({'a': 1})), [{'a': 1}])