Ejemplo n.º 1
0
 def test_object_in_array_field(self):
     data = {'node': '5', 'user': {'abc': 123}}
     try:
         json_outgoing.convert(schema1, data)
         self.assertTrue(False)
     except TypeError as ex:
         self.assertEqual('user: Should be an array', ex.args[0])
Ejemplo n.º 2
0
 def test_array_element_type_mismatch(self):
     data = {'user': ['abc', 5, 'xxxxxxx']}
     try:
         json_outgoing.convert(schema1, data)
         self.assertTrue(False)
     except TypeError as ex:
         self.assertEqual('user.1: Should be a string', ex.args[0])
Ejemplo n.º 3
0
 def test_string_in_object_field(self):
     data = {'tag': 'abc'}
     try:
         json_outgoing.convert(schema1, data)
         self.assertTrue(False)
     except TypeError as ex:
         self.assertEqual('tag: Should be an object', ex.args[0])
Ejemplo n.º 4
0
 def test_integer_in_string_field(self):
     data = {'node': 5}
     try:
         json_outgoing.convert(schema1, data)
         self.assertTrue(False)
     except TypeError as ex:
         self.assertEqual('node: Should be a string', ex.args[0])
Ejemplo n.º 5
0
 def test_integer_in_string_map(self):
     data = {'name': 1.99, 'spec': {'def': 1, 'size': 'xyz'}}
     try:
         json_outgoing.convert(schema4, data)
         self.assertTrue(False)
     except TypeError as ex:
         self.assertEqual('spec.def: Should be a string', ex.args[0])
Ejemplo n.º 6
0
 def test_string_in_string_map_field(self):
     data = {'name': 1.99, 'spec': 'def'}
     try:
         json_outgoing.convert(schema4, data)
         self.assertTrue(False)
     except TypeError as ex:
         self.assertEqual('spec: Should be an object', ex.args[0])
Ejemplo n.º 7
0
 def test_none_inside(self):
     data = {'node': 'abc', 'user': ['def', None, 'f'], 'tag': {'name': None, 'level': 2}}
     result = json_outgoing.convert(schema2, data)
     self.assertEqual(data, result)
Ejemplo n.º 8
0
 def test_all_none(self):
     data = {'node': None, 'user': None, 'tag': None}
     result = json_outgoing.convert(schema2, data, ROOT)
     self.assertEqual(data, result)
Ejemplo n.º 9
0
 def test_return_array_of_object(self):
     data = {'event': [{'name': 'abc'}, None, {'alarm': False}]}
     expected = {'event': [{'name': 'abc'}, None, {'alarm': False}]}
     result = json_outgoing.convert(schema1, data)
     self.assertEqual(expected, result)
Ejemplo n.º 10
0
 def test_return_object(self):
     data = {'tag': {'name': 'abc'}}
     expected = {'tag': {'name': 'abc'}}
     result = json_outgoing.convert(schema1, data)
     self.assertEqual(expected, result)
Ejemplo n.º 11
0
 def test_return_array(self):
     data = {'user': ['abc', None, 'xxxxxx']}
     expected = {'user': ['abc', None, 'xxxxxx']}
     result = json_outgoing.convert(schema1, data)
     self.assertEqual(expected, result)
Ejemplo n.º 12
0
 def test_return_array(self):
     data = [{'user': '******'}]
     result = json_outgoing.convert(schema7, data)
     self.assertEqual(data, result)
Ejemplo n.º 13
0
 def test_any(self):
     data = {'f1': 'v1', 'f2': 78, 'f3': False, 'f4': {'a': 5, 'b': '7'}, 'f5': ['123', 456], 'f6': 'xyz'}
     result = json_outgoing.convert(schema6, data)
     expected = {'f1': 'v1', 'f2': 78, 'f3': False, 'f4': {'a': 5, 'b': '7'}, 'f5': ['123', 456]}
     self.assertEqual(expected, result)
Ejemplo n.º 14
0
 def test_to_string(self):
     data = {'object_id': 56, 'userIds': [3, 7]}
     result = json_outgoing.convert(schema5, data)
     expected = {'object_id': '56', 'userIds': ['3', '7']}
     self.assertEqual(expected, result)
Ejemplo n.º 15
0
 def test_return_number_and_string_map(self):
     data = {'name': 1.99, 'spec': {'def': "1", 'size': 'xyz'}}
     result = json_outgoing.convert(schema4, data)
     self.assertEqual(data, result)
Ejemplo n.º 16
0
 def test_redundant_field(self):
     data = {'node': 'abcd', 'xxx': 6}
     result = json_outgoing.convert(schema3, data)
     expected = {'node': 'abcd'}
     self.assertEqual(expected, result)