Example #1
0
    def setUp(self):
        super(TestCollectionsSearch, self).setUp()
        search.delete_index(elastic_search.INDEX)
        search.create_index(elastic_search.INDEX)

        self.user = factories.UserFactory(fullname='Salif Keita')
        self.node_private = factories.NodeFactory(creator=self.user,
                                                  title='Salif Keita: Madan',
                                                  is_public=False)
        self.node_public = factories.NodeFactory(creator=self.user,
                                                 title='Salif Keita: Yamore',
                                                 is_public=True)
        self.node_one = factories.NodeFactory(creator=self.user,
                                              title='Salif Keita: Mandjou',
                                              is_public=True)
        self.node_two = factories.NodeFactory(creator=self.user,
                                              title='Salif Keita: Tekere',
                                              is_public=True)
        self.provider = factories.CollectionProviderFactory()
        self.collection_one = factories.CollectionFactory(
            title='Life of Salif Keita',
            creator=self.user,
            is_public=True,
            provider=self.provider)
        self.collection_public = factories.CollectionFactory(
            title='Best of Salif Keita',
            creator=self.user,
            is_public=True,
            provider=self.provider)
        self.collection_private = factories.CollectionFactory(
            title='Commentary: Best of Salif Keita',
            creator=self.user,
            is_public=False,
            provider=self.provider)
def populate_collection_providers(add_data):
    for data in COLLECTION_PROVIDERS:
        _id = data.pop('_id')
        default_license = data.pop('default_license', False)
        licenses = [
            get_license(name) for name in data.pop('licenses_acceptable', [])
        ]
        custom_taxonomy = data.pop('custom_taxonomy', False)

        primary_collection = data.pop('primary_collection', False)

        provider, created = CollectionProvider.objects.update_or_create(
            _id=_id, defaults=data)

        if licenses:
            provider.licenses_acceptable.set(licenses)

        if default_license:
            provider.default_license = get_license(default_license)

        if custom_taxonomy and not provider.subjects.exists():
            logger.info('Adding custom taxonomy for: {}'.format(_id))
            call_command('populate_custom_taxonomies', '--provider', _id,
                         '--type', 'osf.collectionprovider', '--data',
                         json.dumps(custom_taxonomy))

        provider_subjects = provider.subjects.all()
        subjects = provider_subjects if len(
            provider_subjects) else PreprintProvider.load(
                'osf').subjects.all()

        if primary_collection and not provider.primary_collection:
            primary_collection['provider'] = provider
            provider.primary_collection = factories.CollectionFactory(
                **primary_collection)
            provider.primary_collection.save()
            provider.save()

        if add_data and provider.primary_collection:
            user = factories.AuthUserFactory()
            user.save()

            for _ in range(5):
                node = factories.NodeFactory()
                node.is_public = True
                node.save()

                status = random.choice(
                    provider.primary_collection.status_choices)
                collected_type = random.choice(
                    provider.primary_collection.collected_type_choices)
                cgm = provider.primary_collection.collect_object(
                    node, user, collected_type=collected_type, status=status)
                rando_subjects = random.sample(subjects, min(len(subjects), 5))
                cgm.subjects.add(*rando_subjects)
                cgm.save()

        logger.info('{} collection provider: {}'.format(
            'Added' if created else 'Updated', _id))
Example #3
0
    def test_migration_collections(self):
        provider = factories.CollectionProviderFactory()
        collection_one = factories.CollectionFactory(is_public=True,
                                                     provider=provider)
        collection_two = factories.CollectionFactory(is_public=True,
                                                     provider=provider)
        node = factories.NodeFactory(creator=self.user,
                                     title='Ali Bomaye',
                                     is_public=True)
        collection_one.collect_object(node, self.user)
        collection_two.collect_object(node, self.user)
        assert node.is_collected

        docs = query_collections('*')['results']
        assert len(docs) == 2

        docs = query_collections('Bomaye')['results']
        assert len(docs) == 2

        count_query = {}
        count_query['aggregations'] = {
            'counts': {
                'terms': {
                    'field': '_type',
                }
            }
        }

        migrate(delete=True, index=settings.ELASTIC_INDEX, app=self.app.app)

        docs = query_collections('*')['results']
        assert len(docs) == 2

        docs = query_collections('Bomaye')['results']
        assert len(docs) == 2

        res = self.es.search(index=settings.ELASTIC_INDEX,
                             doc_type='collectionSubmission',
                             search_type='count',
                             body=count_query)
        assert res['hits']['total'] == 2
Example #4
0
    def setUp(self):
        super(TestODMTitleSearch, self).setUp()

        self.user = factories.AuthUserFactory()
        self.user_two = factories.AuthUserFactory()
        self.project = factories.ProjectFactory(creator=self.user, title='foo')
        self.project_two = factories.ProjectFactory(creator=self.user_two, title='bar')
        self.public_project = factories.ProjectFactory(creator=self.user_two, is_public=True, title='baz')
        self.registration_project = factories.RegistrationFactory(creator=self.user, title='qux')
        self.folder = factories.CollectionFactory(creator=self.user, title='quux')
        self.dashboard = find_bookmark_collection(self.user)
        self.url = api_url_for('search_projects_by_title')