Skip to content

Commit

Permalink
Merge pull request #333 from GSA/datajson-export-test
Browse files Browse the repository at this point in the history
Datajson draft.json export test
  • Loading branch information
FuhuXia authored Jul 21, 2021
2 parents 4de26ca + a664a39 commit 8236c74
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ clean:

debug:
# Stop the canonical app container to avoid a port collision. Use `run`
# so that we have interactive console access for the debugger.
# so that we have interactive console access for the debugger.
docker-compose stop app ; docker-compose run --service-ports app

requirements:
Expand Down
44 changes: 44 additions & 0 deletions tests/draft_data_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"license_title": "License not specified",
"maintainer": null,
"relationships_as_object": [],
"private": true,
"maintainer_email": null,
"num_tags": 1,
"metadata_created": "2020-12-18T19:01:33.429530",
"metadata_modified": "2020-12-18T19:02:54.841495",
"author": null,
"author_email": null,
"state": "active",
"version": null,
"type": "dataset",
"tags": [
{
"vocabulary_id": null,
"state": "active",
"display_name": "test",
"id": "65c76784-e271-4eb1-9778-a738622a1a3d1",
"name": "test"
}
],
"tag_string": "test",
"groups": [],
"license_id": "notspecified",
"relationships_as_subject": [],
"organization": "test-organization",
"isopen": false,
"url": null,
"notes": "The description of the second test dataset",
"owner_org": "test-organization",
"bureau_code": "010:00",
"contact_email": "[email protected]",
"contact_name": "Tester",
"modified": "2020-12-18",
"public_access_level": "public",
"publisher": "Department of the Interior",
"unique_id": "doi-123456789-111",
"title": "Draft Test Dataset 1",
"name": "draft-test-dataset-1",
"program_code": "010:002",
"extras": [{"key": "publishing_status", "value": "Draft"}]
}
44 changes: 44 additions & 0 deletions tests/draft_data_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"license_title": "License not specified",
"maintainer": null,
"relationships_as_object": [],
"private": true,
"maintainer_email": null,
"num_tags": 1,
"metadata_created": "2020-12-18T19:01:33.429530",
"metadata_modified": "2020-12-18T19:02:54.841495",
"author": null,
"author_email": null,
"state": "active",
"version": null,
"type": "dataset",
"tags": [
{
"vocabulary_id": null,
"state": "active",
"display_name": "test",
"id": "65c76784-e271-4eb1-9778-a738622a1a3d1",
"name": "test"
}
],
"tag_string": "test",
"groups": [],
"license_id": "notspecified",
"relationships_as_subject": [],
"organization": "test-organization",
"isopen": false,
"url": null,
"notes": "The description of the second test dataset",
"owner_org": "test-organization",
"bureau_code": "010:00",
"contact_email": "[email protected]",
"contact_name": "Tester",
"modified": "2020-12-18",
"public_access_level": "public",
"publisher": "Department of the Interior",
"unique_id": "doi-123456789-222",
"title": "Draft Test Dataset 2",
"name": "draft-test-dataset-2",
"program_code": "010:003",
"extras": [{"key": "publishing_status", "value": "Draft"}]
}
43 changes: 43 additions & 0 deletions tests/draft_data_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"license_title": "License not specified",
"maintainer": null,
"relationships_as_object": [],
"private": true,
"maintainer_email": null,
"num_tags": 1,
"metadata_created": "2020-12-18T19:01:33.429530",
"metadata_modified": "2020-12-18T19:02:54.841495",
"author": null,
"author_email": null,
"state": "active",
"version": null,
"type": "dataset",
"tags": [
{
"vocabulary_id": null,
"state": "active",
"display_name": "test",
"id": "65c76784-e271-4eb1-9778-a738622a1a3d1",
"name": "test"
}
],
"tag_string": "test",
"groups": [],
"license_id": "notspecified",
"relationships_as_subject": [],
"organization": "test-organization",
"isopen": false,
"url": null,
"notes": "The description of the second test dataset",
"owner_org": "test-organization",
"bureau_code": "010:00",
"contact_email": "[email protected]",
"contact_name": "Tester",
"modified": "2020-12-18",
"public_access_level": "public",
"publisher": "Department of the Interior",
"unique_id": "doi-123456789-333",
"title": "Test Dataset 3",
"name": "test-dataset-3",
"program_code": "010:004"
}
63 changes: 63 additions & 0 deletions tests/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,66 @@ curl -f -X POST http://app:5000/api/action/resource_create \
return 1;
fi
}

function clean_dataset {
curl -X POST 'http://app:5000/api/3/action/package_delete' --cookie ./cookie-jar \
-H 'content-type: application/json' \
-d "{\"id\": \"$1\"}"
}

function add_datasets_for_draft_json {

clean_dataset "draft-test-dataset-1"
clean_dataset "draft-test-dataset-2"
clean_dataset "test-dataset-3"

# Add dataset 1 - draft
data1="$(cat tests/draft_data_1.json)"
curl -f -X POST 'http://app:5000/api/3/action/package_create' --cookie ./cookie-jar \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d "$data1"

# Add dataset 2 - draft
data1="$(cat tests/draft_data_2.json)"
curl -f -X POST 'http://app:5000/api/3/action/package_create' --cookie ./cookie-jar \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d "$data1"

# Add dataset 3 - not draft
data1="$(cat tests/draft_data_3.json)"
curl -f -X POST 'http://app:5000/api/3/action/package_create' --cookie ./cookie-jar \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d "$data1"
}

@test "Test Export draft.json working" {
login
add_datasets_for_draft_json

# Get draft.json
curl --fail --location --request GET --output draft.zip --cookie ./cookie-jar \
'http://app:5000/organization/test-organization/draft.json'

# Remove datasets to prevetn future conflicts
clean_dataset "draft-test-dataset-1"
clean_dataset "draft-test-dataset-2"
clean_dataset "test-dataset-3"

unzip -o draft.zip
result=`cat draft_data.json | jq .dataset[].title`
# We expect only dataset 1 and 2 to be draft-status
expected='"Draft Test Dataset 1"
"Draft Test Dataset 2"'
if [ "$result" = "$expected" ]; then
echo "Success! Dataset 1 and 2 registered as draft"
echo "Dataset 3 not registered as draft "
return 0;
else
echo "$result does NOT equal $expected"
return 1;
fi

}

0 comments on commit 8236c74

Please sign in to comment.