예제 #1
0
 def test_nested(self):
     input = [
         EachLike({
             'username': Term('[a-zA-Z]+', 'firstlast'),
             'id': SomethingLike(123)})]
     self.assertEqual(
         get_generated_values(input),
         [[{'username': '******', 'id': 123}]])
예제 #2
0
    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})
예제 #3
0
    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}])
예제 #4
0

@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():
예제 #5
0
 (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
 }]]),
예제 #6
0
    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')
예제 #7
0
 def test_each_like_minimum(self):
     self.assertEqual(get_generated_values(EachLike({'a': 1}, minimum=5)),
                      [{'a': 1}] * 5)
예제 #8
0
 def test_each_like(self):
     self.assertEqual(
         get_generated_values(EachLike({'a': 1})), [{'a': 1}])
예제 #9
0
    def test_minimum(self):
        generate = EachLike(1, minimum=2).generate()

        self.assertEqual(
            generate,
            {'json_class': 'Pact::ArrayLike', 'contents': 1, 'min': 2})
예제 #10
0
 def test_each_like(self):
     self.assertEqual(
         from_term(EachLike({'a': 1})),
         {'json_class': 'Pact::ArrayLike', 'contents': {'a': 1}, 'min': 1})
예제 #11
0
    def test_default_options(self):
        generate = EachLike(1).generate()

        self.assertEqual(
            generate,
            {'json_class': 'Pact::ArrayLike', 'contents': 1, 'min': 1})