Beispiel #1
0
    def setUp(self):
        super(RegistrationEmbargoViewsTestCase, self).setUp()
        self.user = AuthUserFactory()
        self.project = ProjectFactory(creator=self.user)
        self.draft = DraftRegistrationFactory(branched_from=self.project)
        self.registration = RegistrationFactory(project=self.project, creator=self.user)

        current_month = timezone.now().strftime('%B')
        current_year = timezone.now().strftime('%Y')

        self.valid_make_public_payload = json.dumps({
            u'embargoEndDate': u'Fri, 01, {month} {year} 00:00:00 GMT'.format(
                month=current_month,
                year=current_year
            ),
            u'registrationChoice': 'immediate',
            u'summary': unicode(fake.sentence())
        })
        valid_date = timezone.now() + datetime.timedelta(days=180)
        self.valid_embargo_payload = json.dumps({
            u'embargoEndDate': unicode(valid_date.strftime('%a, %d, %B %Y %H:%M:%S')) + u' GMT',
            u'registrationChoice': 'embargo',
            u'summary': unicode(fake.sentence())
        })
        self.invalid_embargo_date_payload = json.dumps({
            u'embargoEndDate': u"Thu, 01 {month} {year} 05:00:00 GMT".format(
                month=current_month,
                year=str(int(current_year) - 1)
            ),
            u'registrationChoice': 'embargo',
            u'summary': unicode(fake.sentence())
        })
Beispiel #2
0
 def test_current_version_number_with_non_contiguous_version_numbers(self):
     wiki = WikiFactory()
     for i in range(1, 9):
         WikiVersion(wiki_page=wiki, identifier=i, content=fake.sentence()).save()
     for i in range(2, 6):
         WikiVersion(wiki_page=wiki, identifier=i, content=fake.sentence()).save()
     assert wiki.current_version_number == 5
     latest_version = wiki.versions.order_by('-created')[0]
     assert latest_version.is_current
     assert wiki.get_version(5) == latest_version
Beispiel #3
0
    def setUp(self):
        super(RegistrationRetractionModelsTestCase, self).setUp()

        self.user = UserFactory()
        self.registration = RegistrationFactory(creator=self.user, is_public=True)
        self.valid_justification = fake.sentence()
        self.invalid_justification = fake.text(max_nb_chars=3000)
 def test_invalid_rejection_token_raises_InvalidSanctionRejectionToken(self):
     self.registration.embargo_registration(self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10))
     self.registration.save()
     assert_true(self.registration.is_pending_embargo)
     with assert_raises(InvalidSanctionRejectionToken):
         self.registration.embargo.disapprove_embargo(self.user, fake.sentence())
     assert_true(self.registration.is_pending_embargo)
 def test_GET_approve_registration_without_embargo_raises_HTTPBad_Request(self):
     assert_false(self.registration.pending_embargo)
     res = self.app.get(
         self.registration.web_url_for('node_registration_embargo_approve', token=fake.sentence()),
         auth=self.user.auth,
         expect_errors=True
     )
     assert_equal(res.status_code, 400)
 def test_GET_from_unauthorized_user_raises_HTTPForbidden(self):
     unauthorized_user = AuthUserFactory()
     res = self.app.get(
         self.registration.web_url_for('node_registration_embargo_approve', token=fake.sentence()),
         auth=unauthorized_user.auth,
         expect_errors=True
     )
     assert_equal(res.status_code, 403)
Beispiel #7
0
 def test_prereg(self):
     meta = {
         'q1': {
             'value': fake.sentence()
         }
     }
     
     node = factories.NodeFactory(creator=self.osf_user)
     prereg_pending = []
     for i in range(3):
         draft = factories.DraftRegistrationFactory(
             branched_from=node, 
             registration_schema=self.prereg_schema,
             registration_metadata=meta
         )
         draft.submit_for_review(
             self.osf_user, {
                 'registration_choice': 'immediate'
             },
             save=True
         )
         prereg_pending.append(draft)
     non_prereg_pending = []
     for i in range(3):            
         draft = factories.DraftRegistrationFactory(
             branched_from=node, 
             registration_schema=self.other_schema
         )
         draft.submit_for_review(
             self.osf_user, {
                 'registration_choice': 'immediate'
             },
             save=True
         )
         non_prereg_pending.append(draft)
     prereg_not_pending = []
     for i in range(3):
         draft = factories.DraftRegistrationFactory(
             branched_from=node, 
             registration_schema=self.prereg_schema
         )
         prereg_not_pending.append(draft)
     non_prereg_not_pending = []
     for i in range(3):            
         draft = factories.DraftRegistrationFactory(
             branched_from=node, 
             registration_schema=self.other_schema
         )
         non_prereg_not_pending.append(draft)
     
     url = reverse('pre_reg:prereg')        
     res = self.client.get(url)
     
     assert_equal(res.status_code, http.OK)
     assert_in('drafts', res.context)
     assert_equal(len(res.context['drafts']), len(prereg_pending))
     for draft in res.context['drafts']:
         assert_in(draft['pk'], [d._id for d in prereg_pending])
Beispiel #8
0
    def setUp(self):
        super(RegistrationRetractionModelsTestCase, self).setUp()
        self.mock_registration_update = mock.patch('website.project.tasks.on_registration_updated')
        self.mock_registration_update.start()

        self.user = UserFactory()
        self.registration = RegistrationFactory(creator=self.user, is_public=True)
        self.valid_justification = fake.sentence()
        self.invalid_justification = fake.text(max_nb_chars=3000)
    def test_invalid_approval_token_raises_InvalidRetractionApprovalToken(self):
        self.registration.retract_registration(self.user)
        self.registration.save()
        assert_true(self.registration.pending_retraction)

        with assert_raises(InvalidRetractionApprovalToken):
            self.registration.retraction.approve_retraction(self.user, fake.sentence())
        assert_true(self.registration.pending_retraction)
        assert_false(self.registration.is_retracted)
Beispiel #10
0
    def setUp(self):
        super(RegistrationRetractionViewsTestCase, self).setUp()
        self.user = AuthUserFactory()
        self.registered_from = ProjectFactory(creator=self.user, is_public=True)
        self.registration = RegistrationFactory(project=self.registered_from, is_public=True)

        self.retraction_post_url = self.registration.api_url_for('node_registration_retraction_post')
        self.retraction_get_url = self.registration.web_url_for('node_registration_retraction_get')
        self.justification = fake.sentence()
 def test_invalid_rejection_token_raises_InvalidSanctionRejectionToken(self):
     self.registration.require_approval(
         self.user
     )
     self.registration.save()
     assert_true(self.registration.is_pending_registration)
     with assert_raises(InvalidSanctionRejectionToken):
         self.registration.registration_approval.reject(self.user, fake.sentence())
     assert_true(self.registration.is_pending_registration)
Beispiel #12
0
    def test_invalid_rejection_token_raises_InvalidSanctionRejectionToken(self):
        self.registration.retract_registration(self.user)
        self.registration.save()
        assert_true(self.registration.is_pending_retraction)

        with assert_raises(InvalidSanctionRejectionToken):
            self.registration.retraction.disapprove_retraction(self.user, fake.sentence())
        assert_true(self.registration.is_pending_retraction)
        assert_false(self.registration.is_retracted)
 def test_invalid_disapproval_token_raises_InvalidEmbargoDisapprovalToken(self):
     self.registration.embargo_registration(
         self.user,
         datetime.datetime.utcnow() + datetime.timedelta(days=10)
     )
     self.registration.save()
     assert_true(self.registration.pending_embargo)
     with assert_raises(InvalidEmbargoDisapprovalToken):
         self.registration.embargo.disapprove_embargo(self.user, fake.sentence())
     assert_true(self.registration.pending_embargo)
     assert_false(self.registration.embargo_end_date)
Beispiel #14
0
def render_generations_from_parent(parent, creator, num_generations):
    current_gen = parent
    for generation in xrange(0, num_generations):
        next_gen = NodeFactory(
            parent=current_gen,
            creator=creator,
            title=fake.sentence(),
            description=fake.paragraph()
        )
        current_gen = next_gen
    return current_gen
    def test_GET_approve_with_invalid_token_returns_HTTPBad_Request(self):
        self.registration.embargo_registration(
            self.user,
            datetime.datetime.utcnow() + datetime.timedelta(days=10)
        )
        self.registration.save()
        assert_true(self.registration.pending_embargo)

        res = self.app.get(
            self.registration.web_url_for('node_registration_embargo_approve', token=fake.sentence()),
            auth=self.user.auth,
            expect_errors=True
        )
        assert_equal(res.status_code, 400)
Beispiel #16
0
def create_fake_project(creator, n_users, privacy, n_components, name, n_tags, presentation_name, is_registration):
    auth = Auth(user=creator)
    project_title = name if name else fake.sentence()
    if not is_registration:
        project = ProjectFactory(
            title=project_title,
            description=fake.paragraph(),
            creator=creator
        )
    else:
        project = RegistrationFactory(
            title=project_title,
            description=fake.paragraph(),
            creator=creator
        )
    project.set_privacy(privacy)
    for _ in range(n_users):
        contrib = create_fake_user()
        project.add_contributor(contrib, auth=auth)
    if isinstance(n_components, int):
        for _ in range(n_components):
            NodeFactory(
                project=project,
                title=fake.sentence(),
                description=fake.paragraph(),
                creator=creator
            )
    elif isinstance(n_components, list):
        render_generations_from_node_structure_list(project, creator, n_components)
    for _ in range(n_tags):
        project.add_tag(fake.word(), auth=auth)
    if presentation_name is not None:
        project.add_tag(presentation_name, auth=auth)
        project.add_tag('poster', auth=auth)

    project.save()
    return project
Beispiel #17
0
 def setUp(self):
     super(RegistrationRetractionApprovalDisapprovalViewsTestCase, self).setUp()
     self.user = AuthUserFactory()
     self.registered_from = ProjectFactory(is_public=True, creator=self.user)
     self.registration = RegistrationFactory(is_public=True, project=self.registered_from)
     self.registration.retract_registration(self.user)
     self.registration.save()
     self.approval_token = self.registration.retraction.approval_state[self.user._id]['approval_token']
     self.rejection_token = self.registration.retraction.approval_state[self.user._id]['rejection_token']
     self.corrupt_token = fake.sentence()
     self.token_without_sanction = tokens.encode({
         'action': 'approve_retraction',
         'user_id': self.user._id,
         'sanction_id': 'invalid id'
     })
    def setUp(self):
        super(RegistrationEmbargoViewsTestCase, self).setUp()
        ensure_schemas()
        self.user = AuthUserFactory()
        self.project = ProjectFactory(creator=self.user)
        self.registration = RegistrationFactory(project=self.project, creator=self.user)

        current_month = datetime.datetime.now().strftime("%B")
        current_year = datetime.datetime.now().strftime("%Y")

        self.valid_make_public_payload = json.dumps(
            {
                u"embargoEndDate": u"Fri, 01, {month} {year} 00:00:00 GMT".format(
                    month=current_month, year=current_year
                ),
                u"registrationChoice": "immediate",
                u"summary": unicode(fake.sentence()),
            }
        )
        valid_date = datetime.datetime.now() + datetime.timedelta(days=180)
        self.valid_embargo_payload = json.dumps(
            {
                u"embargoEndDate": unicode(valid_date.strftime("%a, %d, %B %Y %H:%M:%S")) + u" GMT",
                u"registrationChoice": "embargo",
                u"summary": unicode(fake.sentence()),
            }
        )
        self.invalid_embargo_date_payload = json.dumps(
            {
                u"embargoEndDate": u"Thu, 01 {month} {year} 05:00:00 GMT".format(
                    month=current_month, year=str(int(current_year) - 1)
                ),
                u"registrationChoice": "embargo",
                u"summary": unicode(fake.sentence()),
            }
        )
    def test_GET_disapprove_with_invalid_token_returns_HTTPBad_Request(self):
        self.registration.retract_registration(self.user)
        self.registration.save()
        assert_true(self.registration.pending_retraction)

        res = self.app.get(
            self.registration.web_url_for('node_registration_retraction_disapprove', token=fake.sentence()),
            auth=self.auth,
            expect_errors=True
        )
        assert_equal(res.status_code, 400)