예제 #1
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
        }])
예제 #2
0
 def test_each_like(self):
     self.assertEqual(from_term(EachLike({'a': 1})), {
         'json_class': 'Pact::ArrayLike',
         'contents': {
             'a': 1
         },
         'min': 1
     })
예제 #3
0
 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'}})
예제 #4
0
 def test_unknown_type(self):
     with self.assertRaises(ValueError):
         from_term(set())
예제 #5
0
 def test_something_like(self):
     self.assertEqual(from_term(SomethingLike(123)), {
         'json_class': 'Pact::SomethingLike',
         'contents': 123
     })
예제 #6
0
 def test_list(self):
     term = [1, 123, 'sample']
     self.assertEqual(from_term(term), term)
예제 #7
0
 def test_float(self):
     self.assertEqual(from_term(3.14), 3.14)
예제 #8
0
 def test_int(self):
     self.assertEqual(from_term(123), 123)
예제 #9
0
 def test_unicode(self):
     self.assertEqual(from_term(u'testing'), 'testing')
예제 #10
0
 def test_none(self):
     self.assertIsNone(from_term(None))
예제 #11
0
 def test_dict(self):
     expected = {'administrator': False, 'id': 123, 'username': '******'}
     self.assertEqual(from_term(expected), expected)