示例#1
0
    def test_valid_command(self, get_object):
        """
        If the user submits a valid command, send it to shove and redirect back to the project.
        """
        # Mock send_command on the project returned by get_object to inject it into the view.
        self.project.send_command = Mock()
        get_object.return_value = self.project

        instance1, instance2 = ShoveInstanceFactory.create_batch(2, active=True)
        self.project.shove_instances.add(instance1, instance2)

        user = self._login_user(True)
        response = self._run_command(command='blah', shove_instances=[instance1.pk, instance2.pk])
        self.assertRedirects(response, self.project.get_absolute_url())
        self.project.send_command.assert_called_once_with(user, 'blah',
                                                          CONTAINS(instance1, instance2))
    def test_send_command_has_permission(self):
        """
        If the user has permission to run a command for this project,
        send the command to shove and create a sent command for it.
        """
        user = UserFactory.create()
        project = ProjectFactory.create(project_name='blah')
        assign_perm('can_run_commands', user, project)

        instance1, instance2 = ShoveInstanceFactory.create_batch(2, active=True)
        project.shove_instances.add(instance1, instance2)

        with patch.object(ShoveInstance, 'send_command', autospec=True) as send_command:
            sent_command = project.send_command(user, 'asdf', [instance1, instance2])
            send_command.assert_has_calls([call(instance1, project, sent_command),
                                           call(instance2, project, sent_command)],
                                          any_order=True)

        assert_equal(sent_command.project, project)
        assert_equal(sent_command.user, user)
        assert_equal(sent_command.command, 'asdf')
    def test_send_command_inactive_shoves(self):
        """
        If any of the shove instances given are not in the set of active
        shove instances for this project, raise a ValueError.
        """
        user = UserFactory.create()
        project = ProjectFactory.create()
        assign_perm('can_run_commands', user, project)

        instance1, instance2 = ShoveInstanceFactory.create_batch(2, active=True)
        project.shove_instances.add(instance1)
        with assert_raises(ValueError):
            project.send_command(user, 'asdf', [instance1, instance2])

        # Now try with an inactive instance that is part of the
        # project's instances.
        instance2.active = False
        instance2.save()
        project.shove_instances.add(instance2)
        with assert_raises(ValueError):
            project.send_command(user, 'asdf', [instance1, instance2])
示例#4
0
 def setUp(self):
     self.project = ProjectFactory.create()
     self.shove_instances = ShoveInstanceFactory.create_batch(2)
     self.project.shove_instances.add(*self.shove_instances)
     self.url = reverse('projects.details.schedule', args=(self.project.pk,))