def test_delete_multiple_extras(self): changes = [] original = Dataset(extras=[ { "key": "subject", "value": "science" }, { "key": "topic", "value": "wind" }, { "key": "geography", "value": "global" }, ]) new = helpers.call_action( "package_patch", id=original["id"], extras=[{ "key": "topic", "value": "wind" }], ) check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "extra_fields" assert changes[0]["method"] == "remove_multiple" assert set(changes[0]["key_list"]) == set(("subject", "geography"))
def test_remove_multiple_tags(self): changes = [] original = Dataset(tags=[ { "name": "rivers" }, { "name": "oceans" }, { "name": "streams" }, ]) new = helpers.call_action("package_patch", id=original["id"], tags=[{ "name": "rivers" }]) check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "tags" assert changes[0]["method"] == "remove_multiple" assert set(changes[0]["tags"]) == set(("oceans", "streams"))
def test_change_extra(self): changes = [] original = Dataset(extras=[ { "key": "subject", "value": "science" }, { "key": "topic", "value": "wind" }, ]) new = helpers.call_action( "package_patch", id=original["id"], extras=[ { "key": "subject", "value": "scientific" }, { "key": "topic", "value": "wind" }, ], ) check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "extra_fields" assert changes[0]["method"] == "change_with_old_value" assert changes[0]["key"] == "subject" assert changes[0]["old_value"] == "science" assert changes[0]["new_value"] == "scientific"
def test_notes_removed_with_non_existing(self): changes = [] original = {"notes": "old notes"} new = {} check_metadata_changes(changes, original, new) assert changes[0]["type"] == "notes" assert changes[0]["method"] == "remove"
def test_maintainer_email_removed_with_non_existing(self): changes = [] original = {"maintainer_email": "*****@*****.**"} new = {} check_metadata_changes(changes, original, new) assert changes[0]["type"] == "maintainer_email" assert changes[0]["method"] == "remove"
def test_remove_url(self): changes = [] original = Dataset(url="first url") new = helpers.call_action("package_patch", id=original["id"], url="") check_metadata_changes(changes, original, new) assert changes[0]["type"] == "url" assert changes[0]["method"] == "remove"
def test_license_title_added_when_it_does_not_exist(self): changes = [] original = {} new = {"license_title": "new license"} check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "license" assert changes[0]["new_title"] == "new license"
def test_author_added_when_it_does_not_exist(self): changes = [] original = {} new = {"author": "new author"} check_metadata_changes(changes, original, new) assert changes[0]["type"] == "author" assert changes[0]["method"] == "add" assert changes[0]["new_author"] == "new author"
def test_maintainer_email_added_when_it_does_not_exist(self): changes = [] original = {} new = {"maintainer_email": "*****@*****.**"} check_metadata_changes(changes, original, new) assert changes[0]["type"] == "maintainer_email" assert changes[0]["method"] == "add" assert changes[0]["new_maintainer_email"] == "*****@*****.**"
def test_url_removed_with_non_existing(self): changes = [] original = {"url": "http://example.com"} new = {} check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "url" assert changes[0]["method"] == "remove" assert changes[0]["old_url"] == "http://example.com"
def test_notes_changed(self): changes = [] original = {"notes": "old notes"} new = {"notes": "new notes"} check_metadata_changes(changes, original, new) assert changes[0]["type"] == "notes" assert changes[0]["method"] == "change" assert changes[0]["new_notes"] == "new notes" assert changes[0]["old_notes"] == "old notes"
def test_remove_maintainer(self): changes = [] original = Dataset(maintainer="first maintainer") new = helpers.call_action("package_patch", id=original["id"], maintainer="") check_metadata_changes(changes, original, new) assert changes[0]["type"] == "maintainer" assert changes[0]["method"] == "remove"
def test_tag_added_when_it_does_not_exist(self): changes = [] original = {} new = {"tags": [{"name": "rivers"}]} check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "tags" assert changes[0]["method"] == "add_one" assert changes[0]["tag"] == "rivers"
def test_tag_removed_with_non_existing(self): changes = [] original = {"tags": [{"name": "oceans"}]} new = {} check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "tags" assert changes[0]["method"] == "remove_one" assert changes[0]["tag"] == "oceans"
def test_version_removed_with_non_existing(self): changes = [] original = {"version": "1"} new = {} check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "version" assert changes[0]["method"] == "remove" assert changes[0]["old_version"] == "1"
def test_version_added_when_it_does_not_exist(self): changes = [] original = {} new = {"version": "1"} check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "version" assert changes[0]["method"] == "add" assert changes[0]["new_version"] == "1"
def test_url_added_when_it_does_not_exist(self): changes = [] original = {} new = {"url": "http://example.com"} check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "url" assert changes[0]["method"] == "add" assert changes[0]["new_url"] == "http://example.com"
def test_author_changed(self): changes = [] original = {"author": "old author"} new = {"author": "new author"} check_metadata_changes(changes, original, new) assert changes[0]["type"] == "author" assert changes[0]["method"] == "change" assert changes[0]["new_author"] == "new author" assert changes[0]["old_author"] == "old author"
def test_maintainer_email_changed(self): changes = [] original = {"maintainer_email": "*****@*****.**"} new = {"maintainer_email": "*****@*****.**"} check_metadata_changes(changes, original, new) assert changes[0]["type"] == "maintainer_email" assert changes[0]["method"] == "change" assert changes[0]["new_maintainer_email"] == "*****@*****.**" assert changes[0]["old_maintainer_email"] == "*****@*****.**"
def test_maintainer_changed(self): changes = [] original = {"maintainer": "old maintainer"} new = {"maintainer": "new maintainer"} check_metadata_changes(changes, original, new) assert changes[0]["type"] == "maintainer" assert changes[0]["method"] == "change" assert changes[0]["new_maintainer"] == "new maintainer" assert changes[0]["old_maintainer"] == "old maintainer"
def test_title_removed_with_non_existing(self): changes = [] original = {"title": "old title"} new = {} check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "title" assert changes[0]["old_title"] == "old title" assert changes[0]["new_title"] is None
def test_title_changed(self): changes = [] original = {"title": "old title"} new = {"title": "new title"} check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "title" assert changes[0]["old_title"] == "old title" assert changes[0]["new_title"] == "new title"
def test_add_notes(self): changes = [] original = Dataset(notes="") new = helpers.call_action("package_patch", id=original["id"], notes="new notes") check_metadata_changes(changes, original, new) assert changes[0]["type"] == "notes" assert changes[0]["method"] == "add" assert changes[0]["new_notes"] == "new notes"
def test_url_changed(self): changes = [] original = {"url": "http://example.com"} new = {"url": "http://example.com/new"} check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "url" assert changes[0]["method"] == "change" assert changes[0]["old_url"] == "http://example.com" assert changes[0]["new_url"] == "http://example.com/new"
def test_version_changed(self): changes = [] original = {"version": "1"} new = {"version": "2"} check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "version" assert changes[0]["method"] == "change" assert changes[0]["old_version"] == "1" assert changes[0]["new_version"] == "2"
def test_owner_org_removed_with_non_existing(self): changes = [] old_org = {"id": "org_id"} original = {"owner_org": old_org["id"], "organization": old_org} new = {} check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "org" assert changes[0]["method"] == "remove" assert changes[0]["old_org_id"] == old_org["id"]
def test_add_maintainer(self): changes = [] original = Dataset() new = helpers.call_action("package_patch", id=original["id"], maintainer="new maintainer") check_metadata_changes(changes, original, new) assert changes[0]["type"] == "maintainer" assert changes[0]["method"] == "add" assert changes[0]["new_maintainer"] == "new maintainer"
def test_owner_org_added_when_it_does_not_exist(self): changes = [] original = {} new_org = {"id": "new_org_id"} new = {"owner_org": new_org["id"], "organization": new_org} check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "org" assert changes[0]["method"] == "add" assert changes[0]["new_org_id"] == new_org["id"]
def test_add_version(self): changes = [] original = Dataset() new = helpers.call_action("package_patch", id=original["id"], version="new version") check_metadata_changes(changes, original, new) assert changes[0]["type"] == "version" assert changes[0]["method"] == "add" assert changes[0]["new_version"] == "new version"
def test_make_public(self): changes = [] old_org = Organization() original = Dataset(owner_org=old_org["id"], private=True) new = helpers.call_action("package_patch", id=original["id"], private=False) check_metadata_changes(changes, original, new) assert len(changes) == 1, changes assert changes[0]["type"] == "private" assert changes[0]["new"] == "Public"