Exemple #1
0
    def setUp(self):
        super(CloseMenuActionTests, self).setUp()

        self.action = CloseMenuAction()
Exemple #2
0
class CloseMenuActionTests(ActionsTestCase):
    """Unit tests for CloseMenuAction."""

    fixtures = ['test_users']

    def setUp(self):
        super(CloseMenuActionTests, self).setUp()

        self.action = CloseMenuAction()

    def test_should_render_for_owner(self):
        """Testing CloseMenuAction.should_render for owner of review request"""
        review_request = self.create_review_request(publish=True)

        request = RequestFactory().request()
        request.user = review_request.submitter

        self.assertTrue(
            self.action.should_render({
                'review_request': review_request,
                'request': request,
                'perms': {
                    'reviews': {
                        'can_change_status': False,
                    },
                },
            }))

    def test_should_render_for_owner_unpublished(self):
        """Testing CloseMenuAction.should_render for owner of review
        unpublished review request
        """
        review_request = self.create_review_request(public=False)

        request = RequestFactory().request()
        request.user = review_request.submitter

        self.assertTrue(
            self.action.should_render({
                'review_request': review_request,
                'request': request,
                'perms': {
                    'reviews': {
                        'can_change_status': False,
                    },
                },
            }))

    def test_should_render_for_user(self):
        """Testing CloseMenuAction.should_render for normal user"""
        review_request = self.create_review_request(publish=True)

        request = RequestFactory().request()
        request.user = User.objects.create(username='******')

        self.assertFalse(
            self.action.should_render({
                'review_request': review_request,
                'request': request,
                'perms': {
                    'reviews': {
                        'can_change_status': False,
                    },
                },
            }))

    def test_should_render_user_with_can_change_status(self):
        """Testing CloseMenuAction.should_render for user with
        can_change_status permission
        """
        review_request = self.create_review_request(publish=True)

        request = RequestFactory().request()
        request.user = User.objects.create(username='******')

        self.assertTrue(
            self.action.should_render({
                'review_request': review_request,
                'request': request,
                'perms': {
                    'reviews': {
                        'can_change_status': True,
                    },
                },
            }))

    def test_should_render_user_with_can_change_status_and_unpublished(self):
        """Testing CloseMenuAction.should_render for user with
        can_change_status permission and unpublished review request
        """
        review_request = self.create_review_request(public=False)

        request = RequestFactory().request()
        request.user = User.objects.create(username='******')

        self.assertFalse(
            self.action.should_render({
                'review_request': review_request,
                'request': request,
                'perms': {
                    'reviews': {
                        'can_change_status': True,
                    },
                },
            }))

    def test_should_render_with_discarded(self):
        """Testing CloseMenuAction.should_render with discarded review request
        """
        review_request = \
            self.create_review_request(status=ReviewRequest.DISCARDED)

        request = RequestFactory().request()
        request.user = review_request.submitter

        self.assertFalse(
            self.action.should_render({
                'review_request': review_request,
                'request': request,
                'perms': {
                    'reviews': {
                        'can_change_status': False,
                    },
                },
            }))

    def test_should_render_with_submitted(self):
        """Testing CloseMenuAction.should_render with submitted review request
        """
        review_request = \
            self.create_review_request(status=ReviewRequest.SUBMITTED)

        request = RequestFactory().request()
        request.user = review_request.submitter

        self.assertFalse(
            self.action.should_render({
                'review_request': review_request,
                'request': request,
                'perms': {
                    'reviews': {
                        'can_change_status': False,
                    },
                },
            }))
Exemple #3
0
class CloseMenuActionTests(ActionsTestCase):
    """Unit tests for CloseMenuAction."""

    fixtures = ['test_users']

    def setUp(self):
        super(CloseMenuActionTests, self).setUp()

        self.action = CloseMenuAction()

    def test_should_render_for_owner(self):
        """Testing CloseMenuAction.should_render for owner of review request"""
        review_request = self.create_review_request(publish=True)

        request = RequestFactory().request()
        request.user = review_request.submitter

        self.assertTrue(self.action.should_render({
            'review_request': review_request,
            'request': request,
            'perms': {
                'reviews': {
                    'can_change_status': False,
                },
            },
        }))

    def test_should_render_for_owner_unpublished(self):
        """Testing CloseMenuAction.should_render for owner of review
        unpublished review request
        """
        review_request = self.create_review_request(public=False)

        request = RequestFactory().request()
        request.user = review_request.submitter

        self.assertTrue(self.action.should_render({
            'review_request': review_request,
            'request': request,
            'perms': {
                'reviews': {
                    'can_change_status': False,
                },
            },
        }))

    def test_should_render_for_user(self):
        """Testing CloseMenuAction.should_render for normal user"""
        review_request = self.create_review_request(publish=True)

        request = RequestFactory().request()
        request.user = User.objects.create(username='******')

        self.assertFalse(self.action.should_render({
            'review_request': review_request,
            'request': request,
            'perms': {
                'reviews': {
                    'can_change_status': False,
                },
            },
        }))

    def test_should_render_user_with_can_change_status(self):
        """Testing CloseMenuAction.should_render for user with
        can_change_status permission
        """
        review_request = self.create_review_request(publish=True)

        request = RequestFactory().request()
        request.user = User.objects.create(username='******')

        self.assertTrue(self.action.should_render({
            'review_request': review_request,
            'request': request,
            'perms': {
                'reviews': {
                    'can_change_status': True,
                },
            },
        }))

    def test_should_render_user_with_can_change_status_and_unpublished(self):
        """Testing CloseMenuAction.should_render for user with
        can_change_status permission and unpublished review request
        """
        review_request = self.create_review_request(public=False)

        request = RequestFactory().request()
        request.user = User.objects.create(username='******')

        self.assertFalse(self.action.should_render({
            'review_request': review_request,
            'request': request,
            'perms': {
                'reviews': {
                    'can_change_status': True,
                },
            },
        }))

    def test_should_render_with_discarded(self):
        """Testing CloseMenuAction.should_render with discarded review request
        """
        review_request = \
            self.create_review_request(status=ReviewRequest.DISCARDED)

        request = RequestFactory().request()
        request.user = review_request.submitter

        self.assertFalse(self.action.should_render({
            'review_request': review_request,
            'request': request,
            'perms': {
                'reviews': {
                    'can_change_status': False,
                },
            },
        }))

    def test_should_render_with_submitted(self):
        """Testing CloseMenuAction.should_render with submitted review request
        """
        review_request = \
            self.create_review_request(status=ReviewRequest.SUBMITTED)

        request = RequestFactory().request()
        request.user = review_request.submitter

        self.assertFalse(self.action.should_render({
            'review_request': review_request,
            'request': request,
            'perms': {
                'reviews': {
                    'can_change_status': False,
                },
            },
        }))
Exemple #4
0
    def setUp(self):
        super(CloseMenuActionTests, self).setUp()

        self.action = CloseMenuAction()
Exemple #5
0
class CloseMenuActionTests(ReadOnlyActionTestsMixin, ActionsTestCase):
    """Unit tests for CloseMenuAction."""

    action = CloseMenuAction()
    fixtures = ['test_users']

    def _create_request_context(self,
                                can_change_status=True,
                                public=True,
                                status=ReviewRequest.PENDING_REVIEW,
                                user=None):
        """Create and return objects for use in the request context.

        Args:
            can_change_status (bool, optional):
                Whether the ``can_change_status`` permission should be set.

            public (bool, optional):
                Whether the review request should be public.

            status (unicode, optional):
                The status for the review request.

            user (django.contrib.auth.models.User, optional):
                An optional user to set as the owner of the request.

            *args (tuple):
                Additional positional arguments (unused).

            **kwargs (dict):
                Additional keyword arguments (unused).

        Returns:
            dict:
            Additional context to use when testing read-only actions.
        """
        review_request = self.create_review_request(public=public,
                                                    status=status)
        self.request.user = user or review_request.submitter

        return {
            'review_request': review_request,
            'request': self.request,
            'perms': {
                'reviews': {
                    'can_change_status': can_change_status,
                },
            },
        }

    def test_should_render_for_owner(self):
        """Testing CloseMenuAction.should_render for owner of review request"""
        self.assertTrue(
            self.action.should_render(self._create_request_context()))

    def test_should_render_for_owner_unpublished(self):
        """Testing CloseMenuAction.should_render for owner of review
        unpublished review request
        """
        self.assertTrue(
            self.action.should_render(
                self._create_request_context(public=False)))

    def test_should_render_for_user(self):
        """Testing CloseMenuAction.should_render for normal user"""
        self.assertFalse(
            self.action.should_render(
                self._create_request_context(can_change_status=False,
                                             user=User.objects.create_user(
                                                 username='******',
                                                 email='*****@*****.**'))))

    def test_should_render_user_with_can_change_status(self):
        """Testing CloseMenuAction.should_render for user with
        can_change_status permission
        """
        self.assertTrue(
            self.action.should_render(
                self._create_request_context(can_change_status=True,
                                             user=User.objects.create_user(
                                                 username='******',
                                                 email='*****@*****.**'))))

    def test_should_render_user_with_can_change_status_and_unpublished(self):
        """Testing CloseMenuAction.should_render for user with
        can_change_status permission and unpublished review request
        """
        self.assertFalse(
            self.action.should_render(
                self._create_request_context(can_change_status=True,
                                             public=False,
                                             user=User.objects.create_user(
                                                 username='******',
                                                 email='*****@*****.**'))))

    def test_should_render_with_discarded(self):
        """Testing CloseMenuAction.should_render with discarded review request
        """
        self.assertFalse(
            self.action.should_render(
                self._create_request_context(status=ReviewRequest.DISCARDED)))

    def test_should_render_with_submitted(self):
        """Testing CloseMenuAction.should_render with submitted review request
        """
        self.assertFalse(
            self.action.should_render(
                self._create_request_context(status=ReviewRequest.SUBMITTED)))