Exemple #1
0
    def test_archive_success_escaped_file_names(self):
        file_tree = file_tree_factory(0, 0, 0)
        fake_file = file_factory(name='>and&and<')
        fake_file_name = strip_html(fake_file['name'])
        file_tree['children'] = [fake_file]

        node = factories.NodeFactory(creator=self.user)
        data = {
            ('q_' + fake_file_name): {
                'value': fake.word(),
                'extra': [{
                    'sha256': fake_file['extra']['hashes']['sha256'],
                    'viewUrl': '/project/{0}/files/osfstorage{1}'.format(
                        node._id,
                        fake_file['path']
                    ),
                    'selectedFileName': fake_file_name,
                    'nodeId': node._id
                }]
            }
        }
        schema = generate_schema_from_data(data)
        draft = factories.DraftRegistrationFactory(branched_from=node, registration_schema=schema, registered_metadata=data)

        with test_utils.mock_archive(node, schema=schema, data=data, autocomplete=True, autoapprove=True) as registration:
            with mock.patch.object(BaseStorageAddon, '_get_file_tree', mock.Mock(return_value=file_tree)):
                job = factories.ArchiveJobFactory(initiator=registration.creator)
                archive_success(registration._id, job._id)
                registration.reload()
                for key, question in registration.registered_meta[schema._id].items():
                    assert_equal(question['extra'][0]['selectedFileName'], fake_file_name)
Exemple #2
0
    def test_archive_failure_different_name_same_sha(self):
        file_tree = file_tree_factory(0, 0, 0)
        fake_file = file_factory()
        fake_file2 = file_factory(sha256=fake_file['extra']['hashes']['sha256'])
        file_tree['children'] = [fake_file2]

        node = factories.NodeFactory(creator=self.user)
        data = {
            ('q_' + fake_file['name']): {
                'value': fake.word(),
                'extra': [{
                    'sha256': fake_file['extra']['hashes']['sha256'],
                    'viewUrl': '/project/{0}/files/osfstorage{1}'.format(
                        node._id,
                        fake_file['path']
                    ),
                    'selectedFileName': fake_file['name'],
                    'nodeId': node._id
                }]
            }
        }
        schema = generate_schema_from_data(data)
        draft = factories.DraftRegistrationFactory(branched_from=node, registration_schema=schema, registered_metadata=data)

        with test_utils.mock_archive(node, schema=schema, data=data, autocomplete=True, autoapprove=True) as registration:
            with mock.patch.object(BaseStorageAddon, '_get_file_tree', mock.Mock(return_value=file_tree)):
                job = factories.ArchiveJobFactory(initiator=registration.creator)
                draft.registered_node = registration
                draft.save()
                with assert_raises(ArchivedFileNotFound):
                    archive_success(registration._id, job._id)
Exemple #3
0
    def test_on_complete_embargo_creates_registration_for_draft_initiator(
            self, mock_enquque):
        user = factories.UserFactory()
        end_date = timezone.now() + datetime.timedelta(
            days=366)  # <- leap year
        approval = DraftRegistrationApproval(
            meta={
                'registration_choice': 'embargo',
                'embargo_end_date': end_date.isoformat()
            })
        approval.save()
        project = factories.ProjectFactory(creator=user)
        registration_schema = MetaSchema.objects.get(name='Prereg Challenge',
                                                     schema_version=2)
        draft = factories.DraftRegistrationFactory(
            branched_from=project,
            registration_schema=registration_schema,
        )
        draft.approval = approval
        draft.save()

        approval._on_complete(user)
        draft.reload()
        registered_node = draft.registered_node
        assert registered_node is not None
        assert registered_node.is_pending_embargo
        assert registered_node.registered_user == draft.initiator
Exemple #4
0
    def test_approval_after_initiator_is_merged_into_another_user(
            self, mock_enqueue):
        approver = factories.UserFactory()
        administer_permission = Permission.objects.get(
            codename='administer_prereg')
        approver.user_permissions.add(administer_permission)
        approver.save()

        mergee = factories.UserFactory(fullname='Manny Mergee')
        merger = factories.UserFactory(fullname='Merve Merger')
        project = factories.ProjectFactory(creator=mergee)
        registration_schema = RegistrationSchema.objects.get(
            name='Prereg Challenge', schema_version=2)
        draft = factories.DraftRegistrationFactory(
            branched_from=project,
            registration_schema=registration_schema,
        )
        merger.merge_user(mergee)
        approval = DraftRegistrationApproval(
            meta={'registration_choice': 'immediate'})
        approval.save()
        draft.approval = approval
        draft.save()
        approval.approve(approver)

        draft.reload()
        registered_node = draft.registered_node
        assert registered_node.registered_user == merger
Exemple #5
0
    def test_approval_after_initiator_is_merged_into_another_user(
            self, mock_enqueue):
        approver = factories.UserFactory()
        approver.add_system_tag(settings.PREREG_ADMIN_TAG)

        mergee = factories.UserFactory(fullname='Manny Mergee')
        merger = factories.UserFactory(fullname='Merve Merger')
        project = factories.ProjectFactory(creator=mergee)
        registration_schema = MetaSchema.objects.get(name='Prereg Challenge',
                                                     schema_version=2)
        draft = factories.DraftRegistrationFactory(
            branched_from=project,
            registration_schema=registration_schema,
        )
        merger.merge_user(mergee)
        approval = DraftRegistrationApproval(
            meta={'registration_choice': 'immediate'})
        approval.save()
        draft.approval = approval
        draft.save()
        approval.approve(approver)

        draft.reload()
        registered_node = draft.registered_node
        assert registered_node.registered_user == merger
Exemple #6
0
    def test_drafts_for_user_omits_registered(self):
        prereg_schema = MetaSchema.find_one(
            Q('name', 'eq', 'Prereg Challenge') & Q('schema_version', 'eq', 2))

        d1 = factories.DraftRegistrationFactory(
            initiator=self.user, registration_schema=prereg_schema)
        d2 = factories.DraftRegistrationFactory(
            initiator=self.user, registration_schema=prereg_schema)
        d3 = factories.DraftRegistrationFactory(
            initiator=self.user, registration_schema=prereg_schema)
        d1.registered_node = factories.RegistrationFactory()
        d1.save()
        drafts = drafts_for_user(self.user, 'prereg')
        for d in drafts:
            assert_in(d._id, (d2._id, d3._id))
            assert_not_equal(d._id, d1._id)
Exemple #7
0
    def test_drafts_for_user_omits_registered(self):
        prereg_schema = RegistrationSchema.objects.get(name='Prereg Challenge',
                                                       schema_version=2)

        d1 = factories.DraftRegistrationFactory(
            initiator=self.user, registration_schema=prereg_schema)
        d2 = factories.DraftRegistrationFactory(
            initiator=self.user, registration_schema=prereg_schema)
        d3 = factories.DraftRegistrationFactory(
            initiator=self.user, registration_schema=prereg_schema)
        d1.registered_node = factories.RegistrationFactory()
        d1.save()
        drafts = drafts_for_user(self.user, 'prereg')
        for d in drafts:
            assert_in(d._id, (d2._id, d3._id))
            assert_not_equal(d._id, d1._id)
Exemple #8
0
    def test_on_complete_immediate_creates_registration_for_draft_initiator(self, mock_enquque):
        ensure_schemas()
        user = factories.UserFactory()
        project = factories.ProjectFactory(creator=user)
        registration_schema = MetaSchema.find_one(
            Q('name', 'eq', 'Prereg Challenge') &
            Q('schema_version', 'eq', 2)
        )
        draft = factories.DraftRegistrationFactory(
            branched_from=project,
            registration_schema=registration_schema,
        )
        approval = DraftRegistrationApproval(
            meta={
                'registration_choice': 'immediate'
            }
        )
        approval.save()
        draft.approval = approval
        draft.save()
        approval._on_complete(user)
        draft.reload()
        registered_node = draft.registered_node

        assert registered_node is not None
        assert registered_node.is_pending_registration
        assert registered_node.registered_user == draft.initiator
Exemple #9
0
    def test_has_project_and_draft_registration(self):
        prereg_schema = RegistrationSchema.objects.get(name='Prereg Challenge')
        factories.DraftRegistrationFactory(initiator=self.user,
                                           registration_schema=prereg_schema)

        assert_equal(
            landing_page(user=self.user), {
                'has_projects':
                True,
                'has_draft_registrations':
                True,
                'campaign_long':
                'Prereg Challenge',
                'campaign_short':
                'prereg_challenge',
                'is_logged_in':
                True,
                'sign_up_url':
                '{}register/?campaign=prereg&next=http%3A%2F%2Flocalhost%2F'.
                format(DOMAIN),
            })

        with override_switch(name=OSF_PREREGISTRATION, active=True):
            prereg_schema = RegistrationSchema.objects.get(
                name='OSF Preregistration')
            factories.DraftRegistrationFactory(
                initiator=self.user, registration_schema=prereg_schema)
            assert_equal(
                landing_page(user=self.user), {
                    'has_projects':
                    True,
                    'has_draft_registrations':
                    True,
                    'campaign_long':
                    'OSF Preregistration',
                    'campaign_short':
                    'prereg',
                    'is_logged_in':
                    True,
                    'sign_up_url':
                    '{}register/?campaign=prereg&next=http%3A%2F%2Flocalhost%2F'
                    .format(DOMAIN),
                })
Exemple #10
0
    def test_has_project_and_draft_registration(self):
        prereg_schema = MetaSchema.objects.get(name='Prereg Challenge')
        factories.DraftRegistrationFactory(initiator=self.user,
                                           registration_schema=prereg_schema)

        assert_equal(
            landing_page(user=self.user), {
                'has_projects': True,
                'has_draft_registrations': True,
                'campaign_long': 'Prereg Challenge',
                'campaign_short': 'prereg',
                'is_logged_in': True,
            })
Exemple #11
0
    def test_has_project_and_draft_registration(self):
        prereg_schema = MetaSchema.find_one(Q('name', 'eq',
                                              'Prereg Challenge'))
        factories.DraftRegistrationFactory(initiator=self.user,
                                           registration_schema=prereg_schema)

        assert_equal(
            landing_page(user=self.user), {
                'has_projects': True,
                'has_draft_registrations': True,
                'campaign_long': 'Prereg Challenge',
                'campaign_short': 'prereg',
            })
Exemple #12
0
 def test_on_reject(self, mock_send_mail):
     user = factories.UserFactory()
     approval = DraftRegistrationApproval(
         meta={'registration_choice': 'immediate'})
     approval.save()
     project = factories.ProjectFactory(creator=user)
     registration_schema = MetaSchema.objects.get(name='Prereg Challenge',
                                                  schema_version=2)
     draft = factories.DraftRegistrationFactory(
         branched_from=project,
         registration_schema=registration_schema,
     )
     draft.approval = approval
     draft.save()
     approval._on_reject(user)
     assert approval.meta == {}
     assert mock_send_mail.call_count == 1
    def setUp(self):
        super(TestCheckPreregAuth, self).setUp()

        self.prereg_challenge_admin_user = AuthUserFactory()
        administer_permission = Permission.objects.get(codename='administer_prereg')
        self.prereg_challenge_admin_user.user_permissions.add(administer_permission)
        self.prereg_challenge_admin_user.save()
        prereg_schema = MetaSchema.objects.get(name='Prereg Challenge', schema_version=2)

        self.user = AuthUserFactory()
        self.node = factories.ProjectFactory(creator=self.user)

        self.parent = factories.ProjectFactory()
        self.child = factories.NodeFactory(parent=self.parent)

        self.draft_registration = factories.DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=prereg_schema,
            branched_from=self.parent
        )
Exemple #14
0
    def setUp(self):
        super(TestCheckPreregAuth, self).setUp()

        self.prereg_challenge_admin_user = AuthUserFactory()
        self.prereg_challenge_admin_user.add_system_tag(
            settings.PREREG_ADMIN_TAG)
        self.prereg_challenge_admin_user.save()
        prereg_schema = MetaSchema.objects.get(name='Prereg Challenge',
                                               schema_version=2)

        self.user = AuthUserFactory()
        self.node = factories.ProjectFactory(creator=self.user)

        self.parent = factories.ProjectFactory()
        self.child = factories.NodeFactory(parent=self.parent)

        self.draft_registration = factories.DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=prereg_schema,
            branched_from=self.parent)