Beispiel #1
0
    def test_get_activity_id_from_resource_version_name(self):
        user = factories.User()
        owner_org = factories.Organization(users=[{
            'name': user['name'],
            'capacity': 'editor'
        }])
        dataset = factories.Dataset(owner_org=owner_org['id'])
        resource = factories.Resource(package_id=dataset['id'],
                                      name='First name')

        context = get_context(user)

        version = resource_version_create(context, {
            'resource_id': resource['id'],
            'name': '1',
            'notes': 'Version notes'
        })
        expected_activity_id = version['activity_id']

        activity_id = get_activity_id_from_resource_version_name(
            context, {
                'resource_id': resource['id'],
                'version_name': version['name']
            })

        assert expected_activity_id == activity_id
 def test_dataset_has_versions_after_one_created(self, test_dataset, org_editor):
     context = get_context(org_editor)
     create_version(test_dataset['id'], org_editor)
     assert True is dataset_has_versions(
         context,
         {'dataset_id': test_dataset['id']}
     )
    def test_resource_version_list(self):
        dataset = factories.Dataset()
        resource = factories.Resource(package_id=dataset['id'],
                                      name='First name')
        user = factories.Sysadmin()
        context = get_context(user)

        resource_version_create(context, {
            'resource_id': resource['id'],
            'name': '1'
        })

        toolkit.get_action('resource_patch')(context, {
            'id': resource['id'],
            'name': 'Second name'
        })

        resource_version_create(
            context, {
                'resource_id': resource['id'],
                'name': '2',
                'notes': 'Notes for version 2'
            })

        version_list = resource_version_list(context,
                                             {'resource_id': resource['id']})

        assert len(version_list) == 2
        assert version_list[0]['name'] == '2'
        assert version_list[0]['notes'] == 'Notes for version 2'
        assert version_list[1]['name'] == '1'
        assert version_list[0]['activity_id'] != version_list[1]['activity_id']
    def test_resource_version_current(self):
        dataset = factories.Dataset()
        resource = factories.Resource(package_id=dataset['id'],
                                      name='First name')
        user = factories.Sysadmin()
        context = get_context(user)

        resource_version_create(context, {
            'resource_id': resource['id'],
            'name': '1'
        })

        toolkit.get_action('resource_patch')(context, {
            'id': resource['id'],
            'name': 'Second name'
        })

        resource_version_create(
            context, {
                'resource_id': resource['id'],
                'name': '2',
                'notes': 'Notes for version 2'
            })

        current_version = resource_version_current(
            context, {'resource_id': resource['id']})

        assert current_version['name'] == '2'
        assert current_version['notes'] == 'Notes for version 2'
Beispiel #5
0
    def test_resource_in_activity(self):
        user = factories.User()
        owner_org = factories.Organization(users=[{
            'name': user['name'],
            'capacity': 'editor'
        }])
        dataset = factories.Dataset(owner_org=owner_org['id'])
        resource = factories.Resource(package_id=dataset['id'],
                                      name='Resource 1')

        context = get_context(user)

        version = resource_version_create(context, {
            'resource_id': resource['id'],
            'name': '1',
            'notes': 'Version notes'
        })
        expected_activity_id = version['activity_id']

        assert True == resource_in_activity(context, {
            'activity_id': expected_activity_id,
            'resource_id': resource['id']
        })

        resource_2 = factories.Resource(package_id=dataset['id'],
                                        name='Resource 2')

        assert False == resource_in_activity(context, {
            'activity_id': expected_activity_id,
            'resource_id': resource_2['id']
        })
Beispiel #6
0
    def test_activity_resource_shows_works_on_non_editors(self):
        user = factories.User()
        owner_org = factories.Organization(users=[{
            'name': user['name'],
            'capacity': 'editor'
        }])
        dataset = factories.Dataset(owner_org=owner_org['id'])
        resource = factories.Resource(package_id=dataset['id'],
                                      name='First name')

        context = get_context(user)

        version = resource_version_create(context, {
            'resource_id': resource['id'],
            'name': '1',
            'notes': 'Version notes'
        })

        user2 = factories.User()

        activity_resource = activity_resource_show(
            {'user': user2['name']}, {
                'activity_id': version['activity_id'],
                'resource_id': resource['id']
            })

        assert activity_resource
        assert activity_resource['name'] == 'First name'
 def test_dataset_version_latest_raises_when_dataset_not_found(self, org_editor):
     context = get_context(org_editor)
     with pytest.raises(toolkit.ObjectNotFound, match="Dataset not found"):
         dataset_version_latest(
             context,
             {
                 'dataset_id': 'fake-dataset-id'
             }
         )
 def test_dataset_version_latest_raises_when_dataset_has_no_versions(self, test_dataset, org_editor):
     context = get_context(org_editor)
     with pytest.raises(toolkit.ObjectNotFound, match="Versions not found for this dataset"):
         dataset_version_latest(
             context,
             {
                 'dataset_id': test_dataset['id']
             }
         )
 def test_dataset_version_should_fail_if_dataset_not_exists(self, org_editor):
     context = get_context(org_editor)
     with pytest.raises(toolkit.ObjectNotFound, match="Dataset not found"):
         dataset_version_list(
             context,
             {
                 'dataset_id': 'fake-dataset-id'
             }
         )
 def test_dataset_version_should_return_empty_list_if_dataset_no_versions(self, test_dataset, org_editor):
     context = get_context(org_editor)
     versions_list = dataset_version_list(
         context,
         {
             'dataset_id': test_dataset['id']
         }
     )
     assert [] == versions_list
    def test_cannot_create_versions_with_same_name(self):
        dataset = factories.Dataset()
        resource = factories.Resource(package_id=dataset['id'])
        user = factories.Sysadmin()

        version = resource_version_create(get_context(user), {
            'resource_id': resource['id'],
            'name': '1',
            'notes': 'Version notes'
        })

        with pytest.raises(toolkit.ValidationError):
            resource_version_create(
                get_context(user), {
                    'resource_id': resource['id'],
                    'name': '1',
                    'notes': 'Version notes'
                })
 def test_get_activity_id_from_dataset_version_raises_not_found(self, test_dataset, org_editor):
     context = get_context(org_editor)
     with pytest.raises(toolkit.ObjectNotFound, match="Version not found in the dataset"):
         get_activity_id_from_dataset_version_name(
             context,
             {
                 'dataset_id': test_dataset['id'],
                 'version': 'Fake version name'
             }
         )
    def test_fails_if_not_name_provided(self):
        dataset = factories.Dataset()
        resource = factories.Resource(package_id=dataset['id'])
        user = factories.Sysadmin()

        with pytest.raises(toolkit.ValidationError):
            resource_version_create(get_context(user), {
                'resource_id': resource['id'],
                'notes': 'Version notes'
            })
 def test_dataset_create_should_fail_when_incorrect_activity_id(self, test_dataset, org_editor):
     context = get_context(org_editor)
     with pytest.raises(toolkit.ObjectNotFound, match="Activity not found"):
         dataset_version_create(
             context,
             {
                 "dataset_id": test_dataset['id'],
                 "name": "V1.0",
                 "activity_id": "fake-activity-id"
             }
         )
    def test_fails_if_objects_do_not_exist(self):
        user = factories.Sysadmin()
        with pytest.raises(toolkit.ObjectNotFound) as e:
            resource_version_create(
                get_context(user), {
                    'resource_id': 'fake-resource-id',
                    'name': '1',
                    'notes': 'Version notes'
                })
            assert e.msg == 'Dataset not found'

        dataset = factories.Dataset()
        with pytest.raises(toolkit.ObjectNotFound) as e:
            resource_version_create(
                get_context(user), {
                    'resource_id': 'fake-resource-id',
                    'name': '1',
                    'notes': 'Version notes'
                })
            assert e.msg == 'Resource not found'
 def test_activity_dataset_show_fails_if_no_dataset_in_activity(self, test_dataset, org_editor):
     version = create_version(test_dataset['id'], org_editor)
     context = get_context(org_editor)
     with pytest.raises(toolkit.ObjectNotFound, match='Dataset not found in the activity object.'):
         activity_dataset_show(
             context,
             {
                 'dataset_id': 'fake-dataset-id',
                 'activity_id': version['activity_id']
             }
         )
Beispiel #17
0
    def test_version_update(self, test_version, org_editor):
        context = get_context(org_editor)
        updated_version = toolkit.get_action('version_update')(
            context, {
                'version_id': test_version['id'],
                'package_id': test_version['package_id'],
                'name': "updated-name",
                'notes': "updated-notes"
            })

        assert test_version['id'] == updated_version['id']
        assert "updated-name" == updated_version['name']
        assert "updated-notes" == updated_version['notes']
    def test_get_activity_id_from_dataset_version_returns_correct(self, test_dataset, org_editor):
        version1 = create_version(test_dataset['id'], org_editor, version_name="Version1")
        expected_activity_id = version1['activity_id']

        context = get_context(org_editor)
        actual_activity_id = get_activity_id_from_dataset_version_name(
            context,
            {
                'dataset_id': test_dataset['id'],
                'version': version1['name']
            }
        )

        assert expected_activity_id == actual_activity_id
Beispiel #19
0
    def test_activity_resource_shows_correct_resource(self):
        user = factories.User()
        owner_org = factories.Organization(users=[{
            'name': user['name'],
            'capacity': 'editor'
        }])
        dataset = factories.Dataset(owner_org=owner_org['id'])
        resource = factories.Resource(package_id=dataset['id'],
                                      name='First name')

        context = get_context(user)

        version = resource_version_create(context, {
            'resource_id': resource['id'],
            'name': '1',
            'notes': 'Version notes'
        })

        toolkit.get_action('resource_patch')(context, {
            'id': resource['id'],
            'name': 'Second name'
        })

        version_2 = resource_version_create(
            context, {
                'resource_id': resource['id'],
                'name': '2',
                'notes': 'Notes for version 2'
            })

        activity_resource = activity_resource_show(
            context, {
                'activity_id': version['activity_id'],
                'resource_id': resource['id']
            })

        assert activity_resource
        assert activity_resource['name'] == 'First name'

        activity_resource_2 = activity_resource_show(
            context, {
                'activity_id': version_2['activity_id'],
                'resource_id': resource['id']
            })

        assert activity_resource_2
        assert activity_resource_2['name'] == 'Second name'
    def test_dataset_version_restore_retrives_dataset(self, test_version, test_dataset, org_editor, object_ref):
        context = get_context(org_editor)
        dataset_title = test_dataset['title']
        dataset_id = test_dataset['id']
        dataset_ref = test_dataset[object_ref]
        version_ref = test_version[object_ref]
        toolkit.get_action('package_patch')(
            context,
            {
                "id": dataset_id,
                "title": "updated-title"
            }
        )
        restored_dataset = restore_version(dataset_ref, version_ref, org_editor)

        assert dataset_title == restored_dataset['title'], "restored dataset title does not match"
        assert dataset_id == restored_dataset['id'], "restored dataset has different id"
    def test_resource_version_create(self):
        dataset = factories.Dataset()
        resource = factories.Resource(package_id=dataset['id'])
        user = factories.Sysadmin()

        version = resource_version_create(get_context(user), {
            'resource_id': resource['id'],
            'name': '1',
            'notes': 'Version notes'
        })

        assert version
        assert version['package_id'] == dataset['id']
        assert version['resource_id'] == resource['id']
        assert version['notes'] == 'Version notes'
        assert version['name'] == '1'
        assert version['creator_user_id'] == user['id']
    def test_dataset_version_create_should_create_version(self, org_admin, test_dataset):
        version_name = "Test Version 1.0"
        version_notes = "Some details about the version"
        version = dataset_version_create(
            get_context(org_admin),
            {
                "dataset_id": test_dataset['id'],
                "name": version_name,
                "notes": version_notes
            }
        )
        checks = {'package_id': test_dataset['id'],
                  'resource_id': None,
                  'notes': version_notes,
                  'name': version_name,
                  'creator_user_id': org_admin['id']}

        assert_version(version, checks)
Beispiel #23
0
    def test_resource_has_version(self):
        dataset = factories.Dataset()
        resource = factories.Resource(package_id=dataset['id'],
                                      name='First name')
        user = factories.Sysadmin()
        context = get_context(user)

        assert False == resource_has_versions(context,
                                              {'resource_id': resource['id']})

        resource_version_create(context, {
            'resource_id': resource['id'],
            'name': '1',
            'notes': 'Version notes'
        })

        assert True == resource_has_versions(context,
                                             {'resource_id': resource['id']})
Beispiel #24
0
def test_dataset_version_for_activity_returns_none_if_no_version(app, test_dataset, org_editor):
    context = get_context(org_editor)
    toolkit.get_action('package_patch')(
        context,
        {
            "id": test_dataset['id'],
            "name": "updated-name"
        }
    )
    activities = toolkit.get_action('package_activity_list')(
        context,
        {
            'id': test_dataset['id']
        }
    )
    activity_id = activities[0]['id']
    with mock.patch('ckanext.versions.helpers.toolkit.g', user=org_editor['name']):
        version = dataset_version_for_activity_id(test_dataset['id'], activity_id)
    assert None is version
    def test_version_delete(self):
        dataset = factories.Dataset()
        resource = factories.Resource(package_id=dataset['id'],
                                      name='First name')
        user = factories.Sysadmin()
        context = get_context(user)

        version = resource_version_create(context, {
            'resource_id': resource['id'],
            'name': '1',
            'notes': 'Version notes'
        })

        assert version

        version_delete(context, {'version_id': version['id']})

        with pytest.raises(toolkit.ObjectNotFound):
            version_show(context, {'version_id': version['id']})
    def test_version_show(self):
        dataset = factories.Dataset()
        resource = factories.Resource(package_id=dataset['id'],
                                      name='First name')
        user = factories.Sysadmin()
        context = get_context(user)

        version = resource_version_create(context, {
            'resource_id': resource['id'],
            'name': '1',
            'notes': 'Version notes'
        })

        result = version_show(context, {'version_id': version['id']})

        assert result['id'] == version['id']
        assert result['name'] == '1'
        assert result['notes'] == 'Version notes'
        assert result['creator_user_id'] == user['id']
    def test_dataset_version_list_return_version_in_create_time_desc_order(self, test_dataset, org_editor):
        context = get_context(org_editor)
        version1 = create_version(test_dataset['id'], org_editor, version_name="Version1")
        toolkit.get_action('package_patch')(
            context,
            {
                "id": test_dataset['id'],
                "title": "New Title"
            }
        )
        version2 = create_version(test_dataset['id'], org_editor, version_name="Version2")

        version_list = dataset_version_list(
            context,
            {
                'dataset_id': test_dataset['id']
            }
        )
        assert version2['id'] == version_list[0]['id'], "version2 should be first as newest"
        assert version1['id'] == version_list[-1]['id'], "version1 should be last as oldest"
    def test_dataset_version_create_returns_valid_activity_id(self, test_organization, org_editor):
        old_name = "initial-name"
        dataset = factories.Dataset(name=old_name, owner_org=test_organization['id'])
        version = create_version(dataset['id'], org_editor)
        context = get_context(org_editor)
        toolkit.get_action('package_patch')(
            context,
            {
                "id": dataset['id'],
                "name": "updated-name"
            }
        )

        old_dataset = toolkit.get_action('activity_data_show')(
            context,
            {'id': version['activity_id']}
        )['package']

        assert old_dataset['name'] == old_name
        assert old_dataset['id'] == dataset['id']
Beispiel #29
0
    def test_resource_version_create_editor_user(self):
        user = factories.User()
        owner_org = factories.Organization(users=[{
            'name': user['name'],
            'capacity': 'editor'
        }])
        dataset = factories.Dataset(owner_org=owner_org['id'])
        resource = factories.Resource(package_id=dataset['id'])

        version = resource_version_create(get_context(user), {
            'resource_id': resource['id'],
            'name': '1',
            'notes': 'Version notes'
        })

        assert version
        assert version['package_id'] == dataset['id']
        assert version['resource_id'] == resource['id']
        assert version['notes'] == 'Version notes'
        assert version['name'] == '1'
        assert version['creator_user_id'] == user['id']
    def test_dataset_version_latest_show_latest_version(self, test_dataset, org_editor):
        context = get_context(org_editor)
        version1 = create_version(test_dataset['id'], org_editor, version_name="Version1")
        toolkit.get_action('package_patch')(
            context,
            {
                "id": test_dataset['id'],
                "name": "updated-name"
            }
        )
        version2 = create_version(test_dataset['id'], org_editor, version_name="Version2")

        latest_version = dataset_version_latest(
            context,
            {
                'dataset_id': test_dataset['id']
            }
        )

        assert version1['id'] != latest_version['id']
        assert_version(latest_version, {'id': version2['id'], 'name': version2['name']})