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