Exemple #1
0
    def test_send_command_no_permission(self):
        """
        If the user doesn't have permission to run a command for this project, raise
        PermissionDenied.
        """
        user = UserFactory.create()
        project = ProjectFactory.create()

        with assert_raises(PermissionDenied):
            project.send_command(user, 'asdf')
    def test_queryset(self):
        """
        get_queryset should return all projects that the current user has permission to run
        commands on.
        """
        project1, project2, project3 = ProjectFactory.create_batch(3)
        user = UserFactory.create()
        assign_perm('can_run_commands', user, project1)
        assign_perm('can_run_commands', user, project2)

        self.client_login_user(user)
        response = self.client.get(reverse('projects.mine'))
        assert_equal(set(response.context['object_list']), set([project1, project2]))
Exemple #3
0
    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 log entry for it.
        """
        user = UserFactory.create()
        project = ProjectFactory.create(queue='qwer', project_name='blah')
        assign_perm('can_run_commands', user, project)

        with patch('captain.projects.models.shove') as shove:
            log = project.send_command(user, 'asdf')
        shove.send_command.assert_called_once_with('qwer', 'blah', 'asdf', log.pk)

        assert_equal(log.project, project)
        assert_equal(log.user, user)
        assert_equal(log.command, 'asdf')
    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])
 def _login_user(self, with_permission):
     user = UserFactory.create()
     self.client_login_user(user)
     if with_permission:
         assign_perm('can_run_commands', user, self.project)
     return user
Exemple #7
0
 def test_html_in_name(self):
     """If a user's display name has HTML in it it must be escaped."""
     user = UserFactory.create()
     user.profile.display_name = 'foo<span>bar</span>'
     output = user_display(user)
     assert_true(output.endswith('foo&lt;span&gt;bar&lt;/span&gt;'))