예제 #1
0
 def testValidateListOfLists(self):
     s = ExpandedDataNodeSerializer(data={
         'contents': [[['word', 'drow'], ['word', 'drow']],
                      [['word', 'drow'], ['word', 'drow']]]
     },
                                    context={'type': 'string'})
     self.assertTrue(s.is_valid(raise_exception=True))
예제 #2
0
 def testValidateDict(self):
     s = ExpandedDataNodeSerializer(
         data={'contents': {
             'type': 'integer',
             'contents': 3
         }},
         context={'type': 'integer'})
     self.assertTrue(s.is_valid(raise_exception=True))
예제 #3
0
 def testNegValidationError(self):
     s = ExpandedDataNodeSerializer(
         data={'contents': [[["string"], [{
             "not": "string"
         }]]]},
         context={'type': 'string'})
     with self.assertRaises(serializers.ValidationError):
         s.is_valid(raise_exception=True)
예제 #4
0
 def testValidateListOfDicts(self):
     s = ExpandedDataNodeSerializer(data={
         'contents': [{
             'type': 'integer',
             'contents': 3
         }, {
             'type': 'integer',
             'contents': 4
         }]
     },
                                    context={'type': 'string'})
     self.assertTrue(s.is_valid(raise_exception=True))
예제 #5
0
 def testNegValidateMismatchedObjectTypes(self):
     s = ExpandedDataNodeSerializer(data={
         'contents': [[{
             'type': 'integer',
             'contents': 3
         }], [{
             'type': 'string',
             'contents': 'a'
         }]]
     },
                                    context={'type': 'string'})
     with self.assertRaises(serializers.ValidationError):
         s.is_valid(raise_exception=True)
예제 #6
0
 def testCreateEmptyList(self):
     s = ExpandedDataNodeSerializer(data={'contents': []},
                                    context={'type': 'string'})
     s.is_valid(raise_exception=True)
     m = s.save()
     data = ExpandedDataNodeSerializer(m, context=get_mock_context()).data
     self.assertEqual(data['contents'], [])
예제 #7
0
 def testCreateDict(self):
     raw_data = {'type': 'integer', 'value': 3}
     s = ExpandedDataNodeSerializer(data={'contents': raw_data},
                                    context={'type': 'integer'})
     s.is_valid(raise_exception=True)
     m = s.save()
     data = ExpandedDataNodeSerializer(m, context=get_mock_context()).data
     self.assertEqual(data['contents']['value'], raw_data['value'])
예제 #8
0
 def testCreateList(self):
     raw_data = ['word', 'draw']
     s = ExpandedDataNodeSerializer(data={'contents': raw_data},
                                    context={'type': 'string'})
     s.is_valid(raise_exception=True)
     m = s.save()
     data = ExpandedDataNodeSerializer(m, context=get_mock_context()).data
     self.assertEqual(data['contents'][0]['value'], raw_data[0])
예제 #9
0
 def testDataToData(self):
     raw_data = "something"
     s = ExpandedDataNodeSerializer(data={'contents': raw_data},
                                    context={
                                        'type': 'string',
                                        'request': get_mock_request()
                                    })
     s.is_valid(raise_exception=True)
     s.save()
     self.assertEqual(s.data['contents']['value'], raw_data)
예제 #10
0
 def to_representation(self, instance):
     if not isinstance(instance, models.Model):
         # If the Serializer was instantiated with data instead of a model,
         # "instance" is an OrderedDict.
         return super(DataChannelSerializer, self).to_representation(
             instance)
     else:
         assert isinstance(instance, DataChannel)
         representation = super(DataChannelSerializer, self)\
             .to_representation(instance)
         if instance.data_node is not None:
             data_node_serializer = ExpandedDataNodeSerializer(
                 instance.data_node,
                 context=self.context)
             representation['data'] = data_node_serializer.data
         return representation
예제 #11
0
 def testNegValidateNonuniformDepth(self):
     s = ExpandedDataNodeSerializer(data={'contents': [3, [4, 5]]})
     with self.assertRaises(serializers.ValidationError):
         s.is_valid(raise_exception=True)
예제 #12
0
 def testNegValidateMismatchedTypes(self):
     s = ExpandedDataNodeSerializer(data={'contents': [[3, 4], ['a', 'b']]})
     with self.assertRaises(serializers.ValidationError):
         s.is_valid(raise_exception=True)
예제 #13
0
 def testNegValidateMixed(self):
     s = ExpandedDataNodeSerializer(data={'contents': ['x', 3]})
     with self.assertRaises(serializers.ValidationError):
         s.is_valid(raise_exception=True)
예제 #14
0
 def testValidateString(self):
     raw_data = "[3,[]]]"
     s = ExpandedDataNodeSerializer(data={'contents': raw_data},
                                    context={'type': 'string'})
     self.assertTrue(s.is_valid(raise_exception=True))
예제 #15
0
 def testValidateFloat(self):
     raw_data = 3.2
     s = ExpandedDataNodeSerializer(data={'contents': raw_data},
                                    context={'type': 'float'})
     self.assertTrue(s.is_valid(raise_exception=True))
예제 #16
0
 def testValidateBoolean(self):
     raw_data = False
     s = ExpandedDataNodeSerializer(data={'contents': raw_data},
                                    context={'type': 'boolean'})
     self.assertTrue(s.is_valid(raise_exception=True))
예제 #17
0
 def testValidateLists(self):
     for data in [['word', 'draw'], [3.2, 2.3], [7, 3], [True, False]]:
         s = ExpandedDataNodeSerializer(data={'contents': data})
         self.assertTrue(s.is_valid(raise_exception=True))
예제 #18
0
 def testValidateEmptyList(self):
     s = ExpandedDataNodeSerializer(data={'contents': []},
                                    context={'type': 'string'})
     self.assertTrue(s.is_valid(raise_exception=True))
예제 #19
0
 def testValidateInteger(self):
     raw_data = 7
     s = ExpandedDataNodeSerializer(data={'contents': raw_data},
                                    context={'type': 'integer'})
     self.assertTrue(s.is_valid(raise_exception=True))