def test_delete_multiple_resources(self): changes = [] original = Dataset(resources=[ { "url": "http://example.com/image.png", "format": "png", "name": "Image 1", }, { "url": "http://example.com/image.png", "format": "png", "name": "Image 2", }, { "url": "http://example.com/image.png", "format": "png", "name": "Image 3", }, ]) new = copy.deepcopy(original) del new["resources"][1] del new["resources"][0] new = helpers.call_action("package_update", **new) check_resource_changes(changes, original, new, "fake") assert len(changes) == 2, changes assert changes[0]["type"] == "delete_resource" if changes[0]["resource_name"] == "Image 1": assert changes[1]["resource_name"] == "Image 2" else: assert changes[0]["resource_name"] == "Image 2" assert changes[1]["resource_name"] == "Image 1"
def test_change_resource_description(self): changes = [] original = Dataset(resources=[ { "url": "http://example.com/image.png", "format": "png", "name": "Image 1", "description": "First image", }, { "url": "http://example.com/image.png", "format": "png", "name": "Image 2", "description": "Second image", }, ]) new = copy.deepcopy(original) new["resources"][1]["description"] = "changed" new = helpers.call_action("package_update", **new) check_resource_changes(changes, original, new, "fake") assert len(changes) == 1, changes assert changes[0]["type"] == "resource_desc" assert changes[0]["method"] == "change" assert changes[0]["resource_name"] == "Image 2"
def test_add_multiple_resources(self): changes = [] original = Dataset() new = helpers.call_action( "package_patch", id=original["id"], resources=[ { "url": "http://example.com/image.png", "format": "png", "name": "Image 1", }, { "url": "http://example.com/image2.png", "format": "png", "name": "Image 2", }, ], ) check_resource_changes(changes, original, new, "fake") assert len(changes) == 2, changes assert changes[0]["type"] == "new_resource" assert changes[1]["type"] == "new_resource" if changes[0]["resource_name"] == "Image 1": assert changes[1]["resource_name"] == "Image 2" else: assert changes[1]["resource_name"] == "Image 1" assert changes[0]["resource_name"] == "Image 2"
def test_remove_resource_extra(self): changes = [] original = Dataset(resources=[{ "url": "http://example.com/image.png", "format": "png", "name": "Image 1", "key1": "value1", }]) new = copy.deepcopy(original) del new["resources"][0]["key1"] new = helpers.call_action("package_update", **new) check_resource_changes(changes, original, new, "fake") assert len(changes) == 1, changes assert changes[0]["type"] == "resource_extras" assert changes[0]["method"] == "remove_one" assert changes[0]["key"] == "key1"