Ejemplo n.º 1
0
 def test_save(self, mock_pub):
     from designsafe.apps.api.agave.filemanager.fixtures.publication_fixture import pub_fixture
     fm = PublicationsManager(None)
     mock_saved_pub = MagicMock()
     mock_pub.return_value = mock_saved_pub
     pub = fm.save_publication(pub_fixture)
     self.assertEqual(pub, mock_saved_pub)
Ejemplo 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)
Ejemplo n.º 3
0
    def post(self, request, **kwargs):
        if request.is_ajax():
            data = json.loads(request.body)

        else:
            data = request.POST

        #logger.debug('publication: %s', json.dumps(data, indent=2))
        status = data.get('status', 'saved')
        pub = PublicationsManager(None).save_publication(
            data['publication'], status)
        if data.get('status', 'save').startswith('publish'):
            (tasks.freeze_publication_meta.s(
                pub.projectId, data.get('mainEntityUuids')).set(queue='api')
             | group(
                 tasks.save_publication.si(pub.projectId,
                                           data.get('mainEntityUuids')).set(
                                               queue='files', countdown=60),
                 tasks.copy_publication_files_to_corral.si(pub.projectId).set(
                     queue='files', countdown=60))
             | tasks.swap_file_tag_uuids.si(pub.project_id)
             | tasks.set_publish_status.si(pub.projectId,
                                           data.get('mainEntityUuids'))
             | tasks.zip_publication_files.si(pub.projectId)).apply_async()

        return JsonResponse(
            {
                'status': 200,
                'response': {
                    'message': 'Your publication has been '
                    'schedule for publication',
                    'status': status
                }
            },
            status=200)
Ejemplo n.º 4
0
    def items(self):
        client = get_service_account_client()
        projPath = []

        # pefm - PublicElasticFileManager to grab public projects
        count = 0
        while True:
            projects = PublicationsManager(None).listing(system=None,
                                                         offset=count,
                                                         limit=200)
            for proj in projects['children']:
                if 'project' in proj:
                    # designsafe projects
                    subpath = {
                        'root': reverse('designsafe_data:data_depot'),
                        'project': proj['project'],
                        'system': proj['system']
                    }
                    projPath.append(
                        '{root}public/{system}/{project}'.format(**subpath))
                elif 'system' in proj and 'path' in proj:
                    # nees projects
                    subpath = {
                        'root': reverse('designsafe_data:data_depot'),
                        'project': proj['path'],
                        'system': proj['system']
                    }
                    projPath.append(
                        '{root}public/{system}{project}'.format(**subpath))
                else:
                    continue

            if len(projects['children']) < 200:
                break
            count += 200

        return projPath
Ejemplo n.º 5
0
 def test_requires_auth(self):
     mock_ac = MagicMock()
     fm = PublicationsManager(mock_ac)
     self.assertEqual(fm.requires_auth, False)