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