Beispiel #1
0
    def test_validate_previous(self):
        """
        Test whether custom validate_previous method returns a previous instance or
        raises a serializers.ValidationError.
        """
        plugin = self.plugin
        # create an 'fs' plugin instance
        pl_inst_fs = PluginInstance.objects.create(
            plugin=plugin,
            owner=self.user,
            compute_resource=plugin.compute_resource)
        # create a 'ds' plugin
        data = self.plugin_repr.copy()
        del data['parameters']
        data['name'] = 'testdsapp'
        data['type'] = 'ds'
        data['compute_resource'] = self.compute_resource
        (plugin, tf) = Plugin.objects.get_or_create(**data)
        data = {
            'plugin': plugin,
            'owner': self.user,
            'compute_resource': plugin.compute_resource
        }

        # create serializer for a 'ds' plugin instance
        plg_inst_serializer = PluginInstanceSerializer(data=data)
        plg_inst_serializer.is_valid(raise_exception=True)
        plg_inst_serializer.context = {'view': mock.Mock()}
        plg_inst_serializer.context['view'].get_object = mock.Mock(
            return_value=plugin)
        previous = plg_inst_serializer.validate_previous(pl_inst_fs.id)

        self.assertEqual(previous, pl_inst_fs)
        with self.assertRaises(serializers.ValidationError):
            plg_inst_serializer.validate_previous('')
Beispiel #2
0
 def test_validate_cpu_limit(self):
     """
     Test whether custom validate_cpu_limit raises a serializers.ValidationError when
     the cpu_limit is not within the limits provided by the corresponding plugin.
     """
     data = self.data
     plugin = self.plugin
     plg_inst_serializer = PluginInstanceSerializer(data=data)
     plg_inst_serializer.is_valid(raise_exception=True)
     plg_inst_serializer.context = {'view': mock.Mock()}
     plg_inst_serializer.context['view'].get_object = mock.Mock(
         return_value=plugin)
     with self.assertRaises(serializers.ValidationError):
         plg_inst_serializer.validate_cpu_limit(plugin.min_cpu_limit - 1)
     with self.assertRaises(serializers.ValidationError):
         plg_inst_serializer.validate_cpu_limit(plugin.max_cpu_limit + 1)
Beispiel #3
0
 def test_validate_value_within_interval(self):
     """
     Test whether custom validate_value_within_interval raises a
     serializers.ValidationError when the first argument is not within the interval
     provided by the second and third argument.
     """
     plugin = self.plugin
     plg_inst_serializer = PluginInstanceSerializer(plugin)
     with self.assertRaises(serializers.ValidationError):
         plg_inst_serializer.validate_value_within_interval(
             1, 2, 4, 'error: below')
     with self.assertRaises(serializers.ValidationError):
         plg_inst_serializer.validate_value_within_interval(
             5, 2, 4, 'error: above')
Beispiel #4
0
 def test_create(self):
     """
     Test whether overriden 'create' method adds default values for gpu_limit,
     number_of_workers, cpu_limit and memory_limit.
     """
     data = self.data
     plugin = self.plugin
     plg_inst_serializer = PluginInstanceSerializer(data=data)
     plg_inst_serializer.is_valid(raise_exception=True)
     plg_inst_serializer.context = {'view': mock.Mock()}
     plg_inst_serializer.context['view'].get_object = mock.Mock(
         return_value=plugin)
     plg_inst_serializer.create(data)
     self.assertEqual(data['gpu_limit'], plugin.min_gpu_limit)
     self.assertEqual(data['number_of_workers'],
                      plugin.min_number_of_workers)
     self.assertEqual(data['cpu_limit'], CPUInt(plugin.min_cpu_limit))
     self.assertEqual(data['memory_limit'],
                      MemoryInt(plugin.min_memory_limit))