Esempio n. 1
0
    def test_listing(self, mock_search, mock_pub, mock_leg_pub):

        request = MagicMock()
        request.query_string = 'test_query'
        request.username = '******'

        fm = PublicationsSearchManager(request)
        mock_search().query().sort().extra().execute.return_value = [
            IndexedPublication(projectId='PRJ-XXX'),
            IndexedPublicationLegacy()
        ]

        mock_pub().to_file.return_value = {'type': 'pub'}
        mock_leg_pub().to_file.return_value = {'type': 'leg_pub'}

        res = fm.listing()
        expected_result = {
            'trail': [{
                'name': '$SEARCH',
                'path': '/$SEARCH'
            }],
            'name': '$SEARCH',
            'path': '/',
            'system': None,
            'type': 'dir',
            'children': [{
                'type': 'pub'
            }, {
                'type': 'leg_pub'
            }],
            'permissions': 'READ'
        }
        self.assertEqual(res, expected_result)
Esempio n. 2
0
    def test_listing(self, mock_search, mock_pub, mock_leg_pub):
        fm = PublicationsManager(None)
        mock_search().filter().sort().extra().execute.return_value = [
            IndexedPublication(projectId='PRJ-XXX'),
            IndexedPublicationLegacy()
        ]

        mock_pub().to_file.return_value = {'type': 'pub'}
        mock_leg_pub().to_file.return_value = {'type': 'leg_pub'}

        res = fm.listing(**{'type_filters': []})
        expected_result = {
            'trail': [{
                'name': '$SEARCH',
                'path': '/$SEARCH'
            }],
            'name': '$SEARCH',
            'path': '/',
            'system': None,
            'type': 'dir',
            'children': [{
                'type': 'pub'
            }, {
                'type': 'leg_pub'
            }],
            'permissions': 'READ'
        }
        self.assertEqual(res, expected_result)
Esempio n. 3
0
def save_publication(publication, status='publishing'):
    """Save publication."""
    publication['projectId'] = publication['project']['value']['projectId']
    publication['created'] = datetime.datetime.now().isoformat()
    publication['status'] = status
    publication['version'] = 2
    publication['licenses'] = publication.pop('license', [])
    publication['license'] = ''
    try:
        pub = IndexedPublication.from_id(publication['projectId'])
        pub.update(**publication)
    except DocumentNotFound:
        pub = IndexedPublication(project_id=publication['projectId'],
                                 **publication)
        pub.save()
    pub.save()
    return pub
Esempio n. 4
0
def initilize_publication(publication,
                          status='publishing',
                          revision=None,
                          revision_text=None,
                          revision_titles=None):
    """initilize publication."""
    publication['projectId'] = publication['project']['value']['projectId']
    publication['status'] = status
    publication['version'] = 2
    publication['licenses'] = publication.pop('license', [])
    publication['license'] = ''
    es_client = new_es_client()
    if revision:
        base_pub = IndexedPublication.from_id(publication['projectId'],
                                              revision=None,
                                              using=es_client)
        publication['created'] = base_pub['created']
        publication['revision'] = revision
        publication['revisionDate'] = datetime.datetime.now().isoformat()
        publication['revisionText'] = revision_text
        if revision_titles:
            publication['revisionTitles'] = revision_titles
    elif 'created' not in publication:
        publication['created'] = datetime.datetime.now().isoformat()
    try:
        pub = IndexedPublication.from_id(publication['projectId'],
                                         revision=revision,
                                         using=es_client)
        pub.update(using=es_client, **publication)
    except DocumentNotFound:
        pub = IndexedPublication(project_id=publication['projectId'],
                                 **publication)
        pub.save(using=es_client)
    pub.save(using=es_client)

    # Refresh index so that search works in subsequent pipeline operations.
    IndexedPublication._index.refresh(using=es_client)
    return pub