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_dataset_version_create_auth(self, test_organization, test_dataset, user_role, can_create_version): for user in test_organization['users']: if user['capacity'] == user_role: if can_create_version: create_version(test_dataset['id'], user) return else: with pytest.raises(toolkit.NotAuthorized): create_version(test_dataset['id'], user) return pytest.fail("Couldn't find user with required role %s", user_role)
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'] } )
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_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']})
def test_dataset_version_list_return_all_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") version_list = dataset_version_list( context, { 'dataset_id': test_dataset['id'] } ) version_ids = [v['id'] for v in version_list] assert 2 == len(version_ids), "only 2 versions created for dataset" assert version1['id'] in version_ids assert version2['id'] in version_ids
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
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']
def test_activity_dataset_show_returns_correct_dataset(self, test_dataset, org_editor, object_ref): version = create_version(test_dataset['id'], org_editor) context = get_context(org_editor) updated_name = "updated-name" new_dataset = toolkit.get_action('package_patch')( context, { "id": test_dataset['id'], "name": updated_name } ) old_dataset = activity_dataset_show( context, { 'dataset_id': new_dataset[object_ref], 'activity_id': version['activity_id'] } ) assert test_dataset['name'] == old_dataset['name'] assert new_dataset['id'] == old_dataset['id']
def test_dataset_version_create_fails_if_version_for_activity_exists(self, test_dataset, org_editor): create_version(test_dataset['id'], org_editor, version_name="Version1") with pytest.raises(toolkit.ValidationError, match="Version already exists for this activity"): create_version(test_dataset['id'], org_editor, version_name="Version2")
def test_dataset_create_version_not_accepts_empty_name(self, test_dataset, org_editor): with pytest.raises(toolkit.ValidationError, match="Version name can't be an empty string"): create_version(test_dataset['id'], org_editor, version_name='')
def test_dataset_create_version_accepts_dataset_name(self, test_dataset, org_editor): version = create_version(test_dataset['name'], org_editor) assert test_dataset['id'] == version['package_id']
def test_dataset_version_create_should_fail_if_dataset_not_exists(self, org_editor): with pytest.raises(toolkit.ObjectNotFound, match="Dataset not found"): create_version('fake_dataset_id', org_editor)
def test_dataset_version_create_should_not_create_version_with_same_name(self, test_dataset, org_editor): version_name = "Not unique name" create_version(test_dataset['id'], org_editor, version_name=version_name) with pytest.raises(toolkit.ValidationError): create_version(test_dataset['id'], org_editor, version_name=version_name)
def test_version(test_dataset, org_editor): return create_version(test_dataset['id'], org_editor, version_name="Version1")