示例#1
0
 def test_validate_app_gpu_descriptor(self):
     """
     Test whether custom validate_app_gpu_descriptor method raises a ValidationError
     when the gpu descriptor cannot be converted to a non-negative integer.
     """
     with self.assertRaises(serializers.ValidationError):
         PluginSerializer.validate_app_gpu_descriptor('one')
     with self.assertRaises(serializers.ValidationError):
         PluginSerializer.validate_app_gpu_descriptor(-1)
 def test_validate_app_gpu_descriptor(self):
     """
     Test whether custom validate_app_gpu_descriptor method raises a ValidationError
     when the gpu descriptor cannot be converted to a non-negative integer.
     """
     with self.assertRaises(serializers.ValidationError):
         descriptor_dict = {'name': 'min_gpu_limit', 'value': 'one'}
         PluginSerializer.validate_app_gpu_descriptor(descriptor_dict)
     with self.assertRaises(serializers.ValidationError):
         descriptor_dict = {'name': 'max_gpu_limit', 'value': -1}
         PluginSerializer.validate_app_gpu_descriptor(descriptor_dict)
 def test_validate_app_gpu_descriptor(self):
     """
     Test whether custom validate_app_gpu_descriptor method raises a ValidationError
     when the gpu descriptor cannot be converted to a non-negative integer.
     """
     with self.assertRaises(serializers.ValidationError):
         descriptor_dict = {'name': 'min_gpu_limit', 'value': 'one'}
         PluginSerializer.validate_app_gpu_descriptor(descriptor_dict)
     with self.assertRaises(serializers.ValidationError):
         descriptor_dict = {'name': 'max_gpu_limit', 'value': -1}
         PluginSerializer.validate_app_gpu_descriptor(descriptor_dict)
示例#4
0
 def test_validate_validates_max_gpu_limit(self):
     """
     Test whether custom validate method validates the 'max_gpu_limit'
     descriptor.
     """
     plugin = Plugin.objects.get(name=self.plugin_name)
     plg_serializer = PluginSerializer(plugin)
     data = self.plugin_repr.copy()
     del data['parameters']
     data['max_gpu_limit'] = 2
     plg_serializer.validate_app_gpu_descriptor = mock.Mock()
     plg_serializer.validate(data)
     plg_serializer.validate_app_gpu_descriptor.assert_called_with(2)
 def test_validate_validates_max_gpu_limit(self):
     """
     Test whether custom validate method validates the 'max_gpu_limit'
     descriptor.
     """
     plugin = Plugin.objects.get(name=self.plugin_name)
     plg_serializer = PluginSerializer(plugin)
     data = self.plugin_repr.copy()
     del data['parameters']
     data['max_gpu_limit'] = 2
     plg_serializer.validate_app_gpu_descriptor = mock.Mock()
     plg_serializer.validate(data)
     plg_serializer.validate_app_gpu_descriptor.assert_called_with(
         {'name': 'max_gpu_limit', 'value': 2})