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_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}])
@pytest.mark.parametrize( "input, output", [ (None, None), (False, False), ("testing", "testing"), (123, 123), (3.14, 3.14), ( {"id": 123, "info": {"active": False, "user": "******"}}, {"id": 123, "info": {"active": False, "user": "******"}}, ), ([1, 123, "sample"], [1, 123, "sample"]), (EachLike({"a": 1}), [{"a": 1}]), (EachLike({"a": 1}, minimum=5), [{"a": 1}] * 5), (Like(123), 123), (Term("[a-f0-9]+", "abc123"), "abc123"), (Equals(["a", Like("b")]), ["a", "b"]), ( [EachLike({"username": Term("[a-zA-Z]+", "firstlast"), "id": Like(123)})], [[{"username": "******", "id": 123}]], ), ], ) def test_generation(input, output): assert get_generated_values(input) == output def test_matching_rules_v2_invald_type():
(3.14, 3.14), ({ 'id': 123, 'info': { 'active': False, 'user': '******' } }, { 'id': 123, 'info': { 'active': False, 'user': '******' } }), ([1, 123, 'sample'], [1, 123, 'sample']), (EachLike({'a': 1}), [{ 'a': 1 }]), (EachLike({'a': 1}, minimum=5), [{ 'a': 1 }] * 5), (Like(123), 123), (Term('[a-f0-9]+', 'abc123'), 'abc123'), (Equals(['a', Like('b')]), ['a', 'b']), ([EachLike({ 'username': Term('[a-zA-Z]+', 'firstlast'), 'id': Like(123) })], [[{ '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}])
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})