Exemplo n.º 1
0
Arquivo: views.py Projeto: rerb/stars
class InstitutionToolMixinTest(ProtectedFormMixinViewTest):
    """
        Provides a base TestCase for views that inherit from
        InstitutionToolMixin.
    """
    blessed_user_level = None  # user_level that should be allowed to GET
    blocked_user_level = None  # user_level that should be blocked
    middleware = ProtectedFormMixinViewTest.middleware + [MessageMiddleware]

    def setUp(self):
        super(InstitutionToolMixinTest, self).setUp()
        self.institution = InstitutionFactory(slug='on-the-beach-soldier')
        self.account = StarsAccountFactory(institution=self.institution)
        self.request.user = self.account.user
        creditset = CreditSetFactory()
        self.submission = SubmissionSetFactory(institution=self.institution,
                                               creditset=creditset)

    def open_gate(self):
        self._assign_user_level(self.blessed_user_level)

    def close_gate(self):
        self._assign_user_level(self.blocked_user_level)

    def _assign_user_level(self, user_level):
        self.account.user_level = user_level
        self.account.save()

    def _get_pk(self):
        """
            Provides the value for the kwarg named 'pk' that's
            passed to the view's on_view() product.
        """
        return ''

    def test_success_url_is_loadable(self, **kwargs):
        if kwargs != {}:
            super(InstitutionToolMixinTest, self).test_get_succeeds(**kwargs)
        else:
            super(InstitutionToolMixinTest, self).test_get_succeeds(
                institution_slug=self.institution.slug, pk=self._get_pk())

    def test_get_succeeds(self, **kwargs):
        if kwargs != {}:
            super(InstitutionToolMixinTest, self).test_get_succeeds(**kwargs)
        else:
            super(InstitutionToolMixinTest, self).test_get_succeeds(
                institution_slug=self.institution.slug, pk=self._get_pk())

    def test_get_is_blocked(self, **kwargs):
        if kwargs != {}:
            super(InstitutionToolMixinTest, self).test_get_is_blocked(**kwargs)
        else:
            super(InstitutionToolMixinTest, self).test_get_is_blocked(
                institution_slug=self.institution.slug, pk=self._get_pk())
Exemplo n.º 2
0
Arquivo: views.py Projeto: rerb/stars
class UserCanEditSubmissionMixinTest(ProtectedViewTest):
    """
        Provides a base TestCase for views that inherit from
        UserCanEditSubmissionMixin.
    """
    def setUp(self):
        super(UserCanEditSubmissionMixinTest, self).setUp()
        self.institution = InstitutionFactory(slug='on-the-beach-soldier')
        self.account = StarsAccountFactory(institution=self.institution)
        self.request.user = self.account.user
        creditset = CreditSetFactory()
        self.submission = SubmissionSetFactory(institution=self.institution,
                                               creditset=creditset)

    def open_gate(self):
        self._make_submission_editable()
        self.account.user_level = 'submit'
        self.account.save()

    def close_gate(self):
        self._make_submission_uneditable()

    def _make_submission_editable(self):
        self.submission.status = 'f'
        self.institution.current_submission = self.submission

    def _make_submission_uneditable(self):
        self.submission.status = 'r'

    def test_get_succeeds(self, **kwargs):
        super(UserCanEditSubmissionMixinTest,
              self).test_get_succeeds(institution_slug=self.institution.slug,
                                      submissionset=str(self.submission.id),
                                      **kwargs)

    def test_get_is_blocked(self, **kwargs):
        super(UserCanEditSubmissionMixinTest,
              self).test_get_is_blocked(institution_slug=self.institution.slug,
                                        submissionset=str(self.submission.id),
                                        **kwargs)