def test_validate_validate_app_parameters(self): """ Test whether custom validate method validates submitted plugin's parameters. """ plg_serializer = PluginSerializer() parameter_list = self.plg_repr['parameters'] parameter_list[0]['type'] = 'booleano' with io.BytesIO(json.dumps(self.plg_repr).encode()) as f: data = {'descriptor_file': f} with self.assertRaises(serializers.ValidationError): plg_serializer.validate(data)
def test_validate_check_required_parameters(self): """ Test whether the custom validate method raises a ValidationError when required 'parameters' descriptor is missing from the plugin app representation. """ plg_serializer = PluginSerializer() del self.plg_repr['parameters'] # remove required 'parameters' from representation with io.BytesIO(json.dumps(self.plg_repr).encode()) as f: data = {'descriptor_file': f} with self.assertRaises(serializers.ValidationError): plg_serializer.validate(data)
def test_validate_gpu_limits(self): """ Test whether custom validate method raises a ValidationError when the 'max_gpu_limit' is smaller than the 'max_gpu_limit'. """ plg_serializer = PluginSerializer() self.plg_repr['min_gpu_limit'] = 2 self.plg_repr['max_gpu_limit'] = 1 with io.BytesIO(json.dumps(self.plg_repr).encode()) as f: data = {'descriptor_file': f} with self.assertRaises(serializers.ValidationError): plg_serializer.validate(data)
def test_validate_validates_min_memory_limit(self): """ Test whether custom validate method validates the 'min_memory_limit' descriptor. """ plugin = Plugin.objects.get(name=self.plugin_name) plg_serializer = PluginSerializer(plugin) data = self.plugin_repr.copy() del data['parameters'] data['min_memory_limit'] = 10000 plg_serializer.validate_app_memory_descriptor = mock.Mock() plg_serializer.validate(data) plg_serializer.validate_app_memory_descriptor.assert_called_with(10000)
def test_validate_validates_max_number_of_workers(self): """ Test whether custom validate method validates the 'max_number_of_workers' descriptor. """ plugin = Plugin.objects.get(name=self.plugin_name) plg_serializer = PluginSerializer(plugin) data = self.plugin_repr.copy() del data['parameters'] data['max_number_of_workers'] = 5 plg_serializer.validate_app_workers_descriptor = mock.Mock() plg_serializer.validate(data) plg_serializer.validate_app_workers_descriptor.assert_called_with(5)
def test_validate_gpu_limits(self): """ Test whether custom validate method raises a ValidationError when the 'max_gpu_limit' is smaller than the 'max_gpu_limit'. """ plugin = Plugin.objects.get(name=self.plugin_name) plg_serializer = PluginSerializer(plugin) self.plugin_repr['min_gpu_limit'] = 2 self.plugin_repr['max_gpu_limit'] = 1 data = self.plugin_repr.copy() del data['parameters'] with self.assertRaises(serializers.ValidationError): plg_serializer.validate(data)
def test_validate_validates_max_memory_limit(self): """ Test whether custom validate method validates the 'max_memory_limit' descriptor. """ plugin = Plugin.objects.get(name=self.plugin_name) plg_serializer = PluginSerializer(plugin) data = self.plugin_repr.copy() del data['parameters'] data['max_memory_limit'] = 100000 plg_serializer.validate_app_memory_descriptor = mock.Mock() plg_serializer.validate(data) plg_serializer.validate_app_memory_descriptor.assert_called_with( {'name': 'max_memory_limit', 'value': 100000})
def test_validate_validates_max_number_of_workers(self): """ Test whether custom validate method validates the 'max_number_of_workers' descriptor. """ plugin = Plugin.objects.get(name=self.plugin_name) plg_serializer = PluginSerializer(plugin) data = self.plugin_repr.copy() del data['parameters'] data['max_number_of_workers'] = 5 plg_serializer.validate_app_workers_descriptor = mock.Mock() plg_serializer.validate(data) plg_serializer.validate_app_workers_descriptor.assert_called_with( {'name': 'max_number_of_workers', 'value': 5})
def test_validate_validates_max_cpu_limit(self): """ Test whether custom validate method validates the 'max_cpu_limit' descriptor. """ plugin = Plugin.objects.get(meta__name=self.plugin_name) plg_serializer = PluginSerializer(plugin) data = self.plugin_repr.copy() del data['parameters'] data['max_cpu_limit'] = 200 plg_serializer.validate_app_cpu_descriptor = mock.Mock() plg_serializer.validate(data) plg_serializer.validate_app_cpu_descriptor.assert_called_with({ 'name': 'max_cpu_limit', 'value': 200 })
def test_validate_remove_empty_max_memory_limit(self): """ Test whether the custom validate method removes 'max_memory_limit' descriptor from the validated data when it is the empty string. """ plugin = Plugin.objects.get(meta__name=self.plugin_name) plg_serializer = PluginSerializer(plugin) self.plg_repr['max_memory_limit'] = '' with io.BytesIO(json.dumps(self.plg_repr).encode()) as f: data = {'descriptor_file': f} self.assertNotIn('max_memory_limit', plg_serializer.validate(data))
def test_validate_update_validated_data(self): """ Test whether custom validate method updates validated data with the plugin app representation. """ plg_serializer = PluginSerializer() with io.BytesIO(json.dumps(self.plg_repr).encode()) as f: data = {'descriptor_file': f} new_data = plg_serializer.validate(data) self.assertIn('execshell', new_data) self.assertIn('selfpath', new_data) self.assertIn('selfexec', new_data) self.assertIn('parameters', new_data)