示例#1
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
            })
示例#2
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
        }])
示例#3
0
    def test_minimum(self):
        generate = EachLike(1, minimum=2).generate()

        self.assertEqual(generate, {
            'json_class': 'Pact::ArrayLike',
            'contents': 1,
            'min': 2
        })
示例#4
0
 def test_each_like(self):
     self.assertEqual(from_term(EachLike({'a': 1})), {
         'json_class': 'Pact::ArrayLike',
         'contents': {
             'a': 1
         },
         'min': 1
     })
示例#5
0
    def test_default_options(self):
        generate = EachLike(1).generate()

        self.assertEqual(generate, {
            'json_class': 'Pact::ArrayLike',
            'contents': 1,
            'min': 1
        })
示例#6
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}]])
示例#7
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')
示例#8
0
 def test_each_like_minimum(self):
     self.assertEqual(get_generated_values(EachLike({'a': 1}, minimum=5)),
                      [{
                          'a': 1
                      }] * 5)
示例#9
0
 def test_each_like(self):
     self.assertEqual(get_generated_values(EachLike({'a': 1})), [{'a': 1}])