Esempio n. 1
0
    def setup(self):
        self.external_user = factories.ExternalUser()
        user = core_factories.User()

        target = factories.DataContainer(
            id='data-target',
            name='data-target',
        )
        deposit = factories.DataContainer(id='data-deposit',
                                          name='data-deposit')

        self.external_user_dataset = factories.DepositedDataset(
            description='deposited dataset created by external user',
            owner_org='data-deposit',
            owner_org_dest='data-target',
            user=self.external_user)
        self.internal_user_dataset = factories.DepositedDataset(
            description='deposited dataset created by internal user',
            owner_org='data-deposit',
            owner_org_dest='data-target',
            user=user)
        self.dataset = factories.Dataset(owner_org=target['id'], )

        self.external_dataset_resources = [
            factories.Resource(
                description=
                'resource created by external_user attached to deposited dataset created by external_user',
                package_id=self.external_user_dataset['id'],
                url_type='upload',
                user=self.external_user,
                visibility='restricted'),
            factories.Resource(
                description=
                'resource created by someone else attached to deposited dataset created by external_user',
                package_id=self.external_user_dataset['id'],
                url_type='upload',
                user=user,
                visibility='restricted'),
        ]
        self.internal_dataset_resources = [
            factories.Resource(package_id=self.internal_user_dataset['id'],
                               url_type='upload',
                               user=user),
        ]
        self.arbitrary_resource = factories.Resource(
            package_id=self.dataset['id'],
            url_type='upload',
        )
Esempio n. 2
0
    def setup(self):
        self.app = core_helpers._get_test_app()

        self.dataset = factories.DepositedDataset(name='dataset',
                                                  owner_org='data-deposit',
                                                  owner_org_dest='data-target',
                                                  user=self.creator)
Esempio n. 3
0
    def setup(self):
        super(TestDepositedDatasetController, self).setup()

        # Users
        self.sysadmin = core_factories.Sysadmin(name='sysadmin', id='sysadmin')
        self.depadmin = core_factories.User(name='depadmin', id='depadmin')
        self.curator = core_factories.User(name='curator', id='curator')
        self.creator = core_factories.User(name='creator', id='creator')
        self.depositor = core_factories.User(name='depositor', id='depositor')
        self.editor = core_factories.User(name='editor', id='editor')

        # Containers
        self.deposit = factories.DataContainer(
            users=[
                {'name': 'curator', 'capacity': 'editor'},
                {'name': 'depadmin', 'capacity': 'admin'},
            ],
            name='data-deposit',
            id='data-deposit'
        )
        self.target = factories.DataContainer(
            name='data-target',
            id='data-target',
            users=[
                {'name': 'editor', 'capacity': 'editor'},
            ],

        )

        # Dataset
        self.dataset = factories.DepositedDataset(
            name='dataset',
            owner_org='data-deposit',
            owner_org_dest='data-target',
            user=self.creator)
Esempio n. 4
0
    def test_package_update(self):

        # Create users
        depadmin = core_factories.User(name='depadmin')
        curator = core_factories.User(name='curator')
        depositor = core_factories.User(name='depositor')
        creator = core_factories.User(name='creator')

        # Create containers
        deposit = factories.DataContainer(
            id='data-deposit',
            name='data-deposit',
            users=[
                {
                    'name': 'depadmin',
                    'capacity': 'admin'
                },
                {
                    'name': 'curator',
                    'capacity': 'editor'
                },
            ],
        )
        target = factories.DataContainer(
            id='data-target',
            name='data-target',
        )

        # Create dataset
        dataset = factories.DepositedDataset(name='dataset',
                                             owner_org='data-deposit',
                                             owner_org_dest='data-target',
                                             user=creator)

        # Forbidden depadmin/curator/depositor
        with pytest.raises(toolkit.NotAuthorized):
            toolkit.check_access(
                'package_update',
                context={'user': '******'},
                data_dict={'id': dataset['id']},
            )
        with pytest.raises(toolkit.NotAuthorized):
            toolkit.check_access(
                'package_update',
                context={'user': '******'},
                data_dict={'id': dataset['id']},
            )
        with pytest.raises(toolkit.NotAuthorized):
            toolkit.check_access(
                'package_update',
                context={'user': '******'},
                data_dict={'id': dataset['id']},
            )

        # Granted creator
        assert (True == toolkit.check_access('package_update',
                                             {'user': '******'},
                                             {'id': dataset['id']}))
Esempio n. 5
0
    def test_external_user_approved_deposit(self):
        sysadmin = core_factories.Sysadmin()
        external_user = factories.ExternalUser()

        target = factories.DataContainer(
            id='data-target',
            name='data-target',
        )
        deposit = factories.DataContainer(id='data-deposit',
                                          name='data-deposit')

        deposited_dataset = factories.DepositedDataset(
            name='dataset1',
            owner_org='data-deposit',
            owner_org_dest='data-target',
            user=external_user)
        tmp = deposited_dataset.copy()
        tmp.update({
            'unit_of_measurement': 'individual',
            'keywords': ['3', '4'],
            'archived': 'False',
            'data_collector': ['acf'],
            'data_collection_technique': 'f2f',
            'external_access_level': 'open_access',
            'geographies': [DEFAULT_GEOGRAPHY_CODE]
        })
        deposited_dataset = helpers.call_action('package_update',
                                                {'user': sysadmin['name']},
                                                **tmp)

        # While the dataset is in deposited state, external_user can view it
        assert (True == toolkit.check_access(
            'package_show',
            {'user': external_user['name']},
            {'id': deposited_dataset['id']},
        ))

        # Approve the dataset
        approved_dataset = convert_deposited_dataset_to_regular_dataset(
            deposited_dataset)
        approved_dataset = helpers.call_action('package_update',
                                               context={
                                                   'user': sysadmin['name'],
                                                   'type':
                                                   approved_dataset['type']
                                               },
                                               **approved_dataset)

        # Now that the dataset has moved out of the data-deposit,
        # external_user can not view it anymore
        with pytest.raises(toolkit.NotAuthorized):
            toolkit.check_access(
                'package_show',
                context={'user': external_user['name']},
                data_dict={'id': approved_dataset['id']},
            )
Esempio n. 6
0
    def test_resource_download_deposited_dataset(self):
        depadmin = core_factories.User()
        curator = core_factories.User()
        target_container_admin = core_factories.User()
        target_container_member = core_factories.User()
        other_container_admin = core_factories.User()

        deposit = factories.DataContainer(id='data-deposit',
                                          users=[
                                              {
                                                  'name': depadmin['name'],
                                                  'capacity': 'admin'
                                              },
                                              {
                                                  'name': curator['name'],
                                                  'capacity': 'editor'
                                              },
                                          ])
        target = factories.DataContainer(users=[
            {
                'name': target_container_admin['name'],
                'capacity': 'admin'
            },
            {
                'name': target_container_member['name'],
                'capacity': 'member'
            },
        ])
        container = factories.DataContainer(users=[
            {
                'name': other_container_admin['name'],
                'capacity': 'admin'
            },
        ])

        dataset = factories.DepositedDataset(owner_org=deposit['id'],
                                             owner_org_dest=target['id'])
        resource = factories.Resource(
            package_id=dataset['id'],
            url_type='upload',
        )

        for user in [depadmin, curator, target_container_admin]:
            assert ({
                'success': True
            } == auth.resource_download({'user': user['name']}, resource))

        for user in [target_container_member, other_container_admin]:
            assert ({
                'success': False
            } == auth.resource_download({'user': user['name']}, resource))
Esempio n. 7
0
    def test_integration_edit_deposit(self, app):
        # everyone can edit their own draft deposited datasets
        external_user = factories.ExternalUser()
        external_deposit = factories.DepositedDataset(
            name='dataset1',
            owner_org='data-deposit',
            owner_org_dest='data-target',
            user=external_user,
            state='draft',
        )
        with app.flask_app.test_request_context():
            resp = app.get(
                url='/deposited-dataset/edit/{}'.format(
                    external_deposit['id']),
                extra_environ={
                    'REMOTE_USER': external_user['name'].encode('ascii')
                },
                status=200,
            )

        internal_user = core_factories.User()
        internal_deposit = factories.DepositedDataset(
            name='dataset2',
            owner_org='data-deposit',
            owner_org_dest='data-target',
            user=internal_user,
            state='draft',
        )
        with app.flask_app.test_request_context():
            resp = app.get(
                url='/deposited-dataset/edit/{}'.format(
                    internal_deposit['id']),
                extra_environ={
                    'REMOTE_USER': internal_user['name'].encode('ascii')
                },
                status=200,
            )
Esempio n. 8
0
    def setup(self):
        self.depadmin = core_factories.User()
        self.curator = core_factories.User()
        self.target_container_admin = core_factories.User()
        self.target_container_member = core_factories.User()
        self.other_container_admin = core_factories.User()

        deposit = factories.DataContainer(id='data-deposit',
                                          users=[
                                              {
                                                  'name':
                                                  self.depadmin['name'],
                                                  'capacity': 'admin'
                                              },
                                              {
                                                  'name': self.curator['name'],
                                                  'capacity': 'editor'
                                              },
                                          ])
        target = factories.DataContainer(users=[
            {
                'name': self.target_container_admin['name'],
                'capacity': 'admin'
            },
            {
                'name': self.target_container_member['name'],
                'capacity': 'member'
            },
        ])
        container = factories.DataContainer(users=[
            {
                'name': self.other_container_admin['name'],
                'capacity': 'admin'
            },
        ])

        dataset = factories.DepositedDataset(owner_org=deposit['id'],
                                             owner_org_dest=target['id'])
        self.package = model.Package.get(dataset['id'])
Esempio n. 9
0
 def test_get_dataset_validation_error_or_none(self):
     deposit = factories.DataContainer(id='data-deposit')
     target = factories.DataContainer(id='data-target')
     dataset = factories.DepositedDataset(name='name',
                                          title='title',
                                          owner_org=deposit['id'],
                                          owner_org_dest=target['id'])
     context = {
         'model': model,
         'session': model.Session,
         'ignore_auth': True,
         'user': None
     }
     error = helpers.get_dataset_validation_error_or_none(dataset,
                                                          context=context)
     assert_equals(
         error.error_summary, {
             'Keywords': 'Select at least one',
             'Archived': 'Missing value',
             'Data collector': 'Select at least one',
             'Unit of measurement': 'Missing value',
             'Data collection technique': 'Missing value',
         })
Esempio n. 10
0
    def setup(self):
        self.target = factories.DataContainer(id='data-target', title='Target')
        self.deposit_container = factories.DataContainer(
            id='data-deposit',
            name='data-deposit',
        )
        self.deposit_dataset = factories.DepositedDataset(
            owner_org='data-deposit',
            owner_org_dest=self.target['id'],
            title='deposit',
            tags=[{
                'name': 'foobar'
            }],
            keywords=[KEYWORDS['Water Sanitation Hygiene']],
        )
        self.deposit_resource = factories.Resource(
            package_id=self.deposit_dataset['id'],
            url_type='upload',
        )

        self.sysadmin = core_factories.Sysadmin()
        self.containers = [
            factories.DataContainer(title='Container1'),
            factories.DataContainer(title='Container1')
        ]
        self.users = [
            core_factories.User(fullname='User1'),
            core_factories.User(fullname='User2'),
        ]
        self.datasets = [
            factories.Dataset(
                user=self.sysadmin,
                tags=[{
                    'name': 'economy'
                }, {
                    'name': 'health'
                }, {
                    'name': 'environment'
                }],
                keywords=[
                    KEYWORDS['Protection'], KEYWORDS['Food Security'],
                    KEYWORDS['Emergency Shelter and NFI']
                ],
                owner_org=self.containers[0]['id'],
            ),
            factories.Dataset(
                user=self.users[0],
                tags=[{
                    'name': 'health'
                }, {
                    'name': 'environment'
                }],
                keywords=[
                    KEYWORDS['Food Security'],
                    KEYWORDS['Emergency Shelter and NFI']
                ],
                owner_org=self.containers[0]['id'],
            ),
            factories.Dataset(
                user=self.users[0],
                tags=[{
                    'name': 'health'
                }],
                keywords=[KEYWORDS['Food Security']],
                owner_org=self.containers[0]['id'],
            ),
            factories.Dataset(
                user=self.users[0],
                keywords=[KEYWORDS['Food Security']],
                owner_org=self.containers[1]['id'],
            ),
        ]
        self.resources = [
            factories.Resource(package_id=self.datasets[0]['id'],
                               url_type='upload'),
            factories.Resource(package_id=self.datasets[0]['id'],
                               url_type='upload'),
            factories.Resource(package_id=self.datasets[1]['id'],
                               url_type='upload'),
            factories.Resource(package_id=self.datasets[2]['id'],
                               url_type='upload'),
        ]

        create_download_activity({'user': self.sysadmin['name']},
                                 self.resources[0]['id'])
        create_download_activity({'user': self.users[0]['name']},
                                 self.resources[1]['id'])

        create_download_activity({'user': self.sysadmin['name']},
                                 self.resources[2]['id'])
        create_download_activity({'user': self.users[0]['name']},
                                 self.resources[2]['id'])
        create_download_activity({'user': self.users[0]['name']},
                                 self.resources[2]['id'])

        create_download_activity({'user': self.sysadmin['name']},
                                 self.deposit_resource['id'])