def test_validate_value_fail_path_does_not_exist(self):
     """
     Test whether overriden validate_value method raises a serializers.ValidationError
     when user tries to access a path that does not exist in the internal storage.
     """
     user = User.objects.get(username=self.username)
     path_parm_serializer = PathParameterSerializer(user=user)
     with mock.patch.object(SwiftManager, 'path_exists',
                            return_value=False) as path_exists_mock:
         with self.assertRaises(serializers.ValidationError):
             path_parm_serializer.validate_value(self.username)
         path_exists_mock.assert_called_with(self.username)
Ejemplo n.º 2
0
 def test_validate_value_fail_denied_acces_other_user_space(self):
     """
     Test whether overriden validate_value method raises a serializers.ValidationError
     when user tries to access another user's space.
     """
     path_parm_serializer = PathParameterSerializer(user=self.user)
     with self.assertRaises(serializers.ValidationError):
         value = "{}/uploads, anotheruser".format(self.username)
         path_parm_serializer.validate_value(value)
     with self.assertRaises(serializers.ValidationError):
         value = "{}, anotheruser/uploads".format(self.username,
                                                  self.username)
         path_parm_serializer.validate_value(value)
Ejemplo n.º 3
0
 def test_validate_value_fail_invalid_feed_path(self):
     """
     Test whether overriden validate_value method raises a serializers.ValidationError
     when user tries to access another user's invalid feed path.
     """
     user = User.objects.get(username=self.username)
     user1 = User.objects.create_user(username=self.other_username,
                                      password=self.other_password)
     plugin = self.plugin
     pl_inst = PluginInstance.objects.create(
         plugin=plugin,
         owner=user1,
         compute_resource=plugin.compute_resources.all()[0])
     path_parm_serializer = PathParameterSerializer(user=user)
     # but feed id
     with self.assertRaises(serializers.ValidationError):
         path_parm_serializer.validate_value(self.other_username +
                                             '/feed_butnumber')
     # feed id does not exist in the DB
     with self.assertRaises(serializers.ValidationError):
         path_parm_serializer.validate_value(self.other_username +
                                             '/feed_%s' %
                                             (pl_inst.feed.id + 1))
     # user is not owner of this existing feed
     with self.assertRaises(serializers.ValidationError):
         path_parm_serializer.validate_value(self.other_username +
                                             '/feed_%s' % pl_inst.feed.id)
Ejemplo n.º 4
0
 def test_validate_value_fail_acces_denied_to_root(self):
     """
     Test whether overriden validate_value method raises a serializers.ValidationError
     when user tries to access an invalid root path.
     """
     path_parm_serializer = PathParameterSerializer(user=self.user)
     with self.assertRaises(serializers.ValidationError):
         path_parm_serializer.validate_value("./")
     with self.assertRaises(serializers.ValidationError):
         path_parm_serializer.validate_value(".")
     with self.assertRaises(serializers.ValidationError):
         path_parm_serializer.validate_value("/")
Ejemplo n.º 5
0
 def test_validate_value_success(self):
     """
     Test whether overriden validate_value method successfully returns a valid
     string of paths separated by comma.
     """
     user = User.objects.get(username=self.username)
     user1 = User.objects.create_user(username=self.other_username,
                                      password=self.other_password)
     plugin = self.plugin
     pl_inst = PluginInstance.objects.create(
         plugin=plugin,
         owner=user1,
         compute_resource=plugin.compute_resources.all()[0])
     pl_inst.feed.owner.set([user1, user])
     path_parm_serializer = PathParameterSerializer(user=user)
     value = "{}, {}/feed_{} ".format(self.username, self.other_username,
                                      pl_inst.feed.id)
     returned_value = path_parm_serializer.validate_value(value)
     self.assertEqual(
         returned_value,
         "{},{}/feed_{}".format(self.username, self.other_username,
                                pl_inst.feed.id))