Exemplo n.º 1
0
Arquivo: views.py Projeto: rerb/stars
 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)
Exemplo n.º 2
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.º 3
0
 def make_account(pending, email):
     if pending:
         return PendingAccountFactory(user_email=email,
                                      institution=self.institution)
     else:
         return StarsAccountFactory(user=UserFactory(email=email),
                                    institution=self.institution)
Exemplo n.º 4
0
    def setUp(self):
        super(ValueErrorTest, self).setUp()

        self.institution = InstitutionFactory()
        self.account = StarsAccountFactory(institution=self.institution,
                                           user_level='admin')
        self.request.user = self.account.user

        self.field = DocumentationFieldFactory(type='boolean')
        self.submission = init_submissionset(self.institution,
                                             self.account.user)

        self.field.credit.identifier = u"CR-1"
        self.field.credit.save()
        self.credit = self.field.credit

        self.subcategory = self.credit.subcategory
        self.subcategory.title = u"subcategory"
        self.subcategory.save()

        self.subcategory.category.abbreviation = "CAT"
        self.subcategory.category.save()
        self.category = self.subcategory.category

        self.rp = ResponsiblePartyFactory(institution=self.institution)

        self.view_kwargs = {
            "institution_slug": self.institution.slug,
            "submissionset": str(self.submission.id),
            "category_abbreviation": self.category.abbreviation,
            "subcategory_slug": self.subcategory.slug,
            "credit_identifier": self.credit.identifier
        }
Exemplo n.º 5
0
Arquivo: views.py Projeto: rerb/stars
 def test_redirect_when_many_stars_accounts(self):
     """Is the redirection when the user has >1 STARS accounts correct?"""
     for i in (1, 2):
         StarsAccountFactory(user=self.request.user)
     with patch('stars.apps.tool.views.reverse') as reverse_mock:
         try:
             self.view_class.as_view()(request=self.request)
         except SuspiciousOperation:  # Django doesn't like reverse mocked.
             pass
         reverse_mock.assert_called_with('select-institution')
Exemplo n.º 6
0
Arquivo: views.py Projeto: rerb/stars
 def test_redirect_when_one_stars_account(self):
     """Is the redirection when the user has one STARS account correct?"""
     stars_account = StarsAccountFactory(user=self.request.user)
     with patch('stars.apps.tool.views.reverse') as reverse_mock:
         try:
             self.view_class.as_view()(request=self.request)
         except SuspiciousOperation:  # Django doesn't like reverse mocked.
             pass
         reverse_mock.assert_called_with(
             'tool-summary',
             kwargs={'institution_slug': stars_account.institution.slug})
Exemplo n.º 7
0
Arquivo: views.py Projeto: rerb/stars
 def setUp(self):
     """
         Creates some data to show on the page.
         Gives ViewTest.test_get_succeeds a little bit
         more of a work out.
     """
     super(SelectInstitutionViewTest, self).setUp()
     institution = InstitutionFactory()
     stars_account = StarsAccountFactory(institution=institution,
                                         user=UserFactory())
     self.request.user = stars_account.user
Exemplo n.º 8
0
 def setUp(self):
     if skip_live_server_tests():
         raise unittest.SkipTest()
     super(StarsLiveServerTest, self).setUp()
     self.plain_text_password = '******'
     self.user = UserFactory(username='******',
                             password=self.plain_text_password)
     self.institution = InstitutionFactory()
     self.stars_account = StarsAccountFactory(user=self.user,
                                              institution=self.institution,
                                              user_level='admin')
     self.login()
Exemplo n.º 9
0
    def setUp(self):
        super(SRT87Test, self).setUp()

        # initialize the creditset and institution
        self.institution = InstitutionFactory()
        self.account = StarsAccountFactory(institution=self.institution,
                                           user_level='admin')
        self.request.user = self.account.user

        self.field = DocumentationFieldFactory(type='numeric',
                                               required=True,
                                               min_range=0)

        # Set up titles for the url
        self.field.credit.identifier = u"CR-1"
        self.field.credit.validation_rules = (
            "if A < 0: errors['B'] = 'you have errors'")
        self.field.credit.save()
        self.credit = self.field.credit

        self.subcategory = self.credit.subcategory
        self.subcategory.title = u"subcategory"
        self.subcategory.save()

        self.subcategory.category.abbreviation = "CAT"
        self.subcategory.category.save()
        self.category = self.subcategory.category

        tabular_field_dict = {
            "numRows": 1,
            "fields": [['']],
            "rowHeadings": ["Row 1"],
            "colHeadings": ["Col 1"],
            "numCols": 1
        }
        self.tabular_field = DocumentationFieldFactory(
            type='tabular',
            required=True,
            tabular_fields=tabular_field_dict,
            credit=self.credit)
        # create a submission set to work with
        self.submission = init_submissionset(self.institution,
                                             self.account.user)

        self.rp = ResponsiblePartyFactory(institution=self.institution)

        self.view_kwargs = {
            "institution_slug": self.institution.slug,
            "submissionset": str(self.submission.id),
            "category_abbreviation": self.category.abbreviation,
            "subcategory_slug": self.subcategory.slug,
            "credit_identifier": self.credit.identifier
        }
Exemplo n.º 10
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)
Exemplo n.º 11
0
    def test_lists_stars_and_pending_accounts(self):
        """Are both StarsAccounts and PendingAccounts listed?"""
        accounts = [self.account]
        for i in xrange(4):
            accounts.append(StarsAccountFactory(institution=self.institution))

        pending_accounts = list()
        for account in accounts:
            pending_accounts.append(
                PendingAccountFactory(institution=self.institution))

        view = views.AccountListView.as_view()(
            self.request, institution_slug=self.institution.slug)
        soup = BeautifulSoup(view.rendered_content)
        table = soup.find('table')
        tbody = table.findChild('tbody')
        rows = tbody.findChildren('tr')
        self.assertEqual(len(rows), len(accounts) + len(pending_accounts))
Exemplo n.º 12
0
    def test_user_with_one_stars_account(self):
        """Do each of the old paths return 200 if user has only 1 StarsAccount?
        """
        user = User.objects.create_user(username='******', password='******')
        user.save()
        institution = InstitutionFactory()
        StarsAccountFactory(user=user,
                            institution=institution,
                            user_level='admin',
                            terms_of_service=True)
        submission_set = SubmissionSetFactory(institution=institution)
        institution.current_submission = submission_set
        institution.save()

        test_client = test.client.Client()
        self.assertTrue(
            test_client.login(username=user.username, password='******'))

        for old_path in OLD_PATHS_TO_PRESERVE:
            path = '/' + old_path
            response = test_client.get(path, follow=True)
            self.assertEqual(response.status_code, 200)
Exemplo n.º 13
0
 def setUp(self):
     super(SubmissionSummaryViewTest, self).setUp()
     self.institution = InstitutionFactory()
     self.account = StarsAccountFactory(institution=self.institution)
     self.request.user = self.account.user
     self.submission = SubmissionSetFactory(institution=self.institution)
Exemplo n.º 14
0
Arquivo: views.py Projeto: rerb/stars
 def setUp(self):
     super(SubmissionSetIsNotLockedMixinTest, self).setUp()
     self.institution = InstitutionFactory(slug='hey-baby-you-look-lonely')
     self.account = StarsAccountFactory(institution=self.institution)
     self.request.user = self.account.user
     self.submission = SubmissionSetFactory(institution=self.institution)