From 7bb59f2f2aba434552f69adf7245c1801769dfec Mon Sep 17 00:00:00 2001 From: ThrawnCA Date: Wed, 19 Feb 2025 14:19:47 +1000 Subject: [PATCH] [QOLDEV-1070] add more scenario tests --- .ahoy.yml | 2 +- MANIFEST.in | 2 +- ckanext/data_qld/tests/test_validation.py | 4 +- .../features/resource_type_validation.feature | 16 ++++++++ test/features/steps/steps.py | 2 +- test/features/xloader.feature | 36 ++++++++++++++++++ test/fixtures/eicar.com.pdf | Bin 0 -> 68 bytes 7 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 test/features/resource_type_validation.feature create mode 100644 test/features/xloader.feature create mode 100644 test/fixtures/eicar.com.pdf diff --git a/.ahoy.yml b/.ahoy.yml index 0c0807f1..c3ebff1a 100644 --- a/.ahoy.yml +++ b/.ahoy.yml @@ -148,7 +148,7 @@ commands: usage: Run unit tests. cmd: | ahoy title 'Run unit tests' - ahoy cli 'pytest -vvv --ckan-ini=.docker/test.ini "${APP_DIR}"/ckanext/data_qld/tests/test_api.py --junit-xml=test/junit/results.xml' || \ + ahoy cli 'pytest --ckan-ini=.docker/test.ini "${APP_DIR}"/ckanext --junit-xml=test/junit/results.xml' || \ [ "${ALLOW_UNIT_FAIL:-0}" -eq 1 ] test-unit-failed-rerun: diff --git a/MANIFEST.in b/MANIFEST.in index 12cf2b63..c6359c50 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ include README.md include LICENSE include requirements.txt -recursive-include ckanext/data-qld *.html *.json *.js *.less *.css *.mo +recursive-include ckanext *.html *.json *.js *.less *.css *.mo diff --git a/ckanext/data_qld/tests/test_validation.py b/ckanext/data_qld/tests/test_validation.py index ec4c513a..4db0cef1 100644 --- a/ckanext/data_qld/tests/test_validation.py +++ b/ckanext/data_qld/tests/test_validation.py @@ -25,7 +25,7 @@ def test_get_create_mode_if_no_schema_and_de_identified( """Validation must be in async mode if we don't have a schema and dataset is de_identified""" dataset = dataset_factory(de_identified_data="YES") - resource = resource_factory(package_id=dataset["id"]) + resource = resource_factory(package_id=dataset["id"], schema=None) mode = validation_settings.get_create_mode({}, resource) assert mode == validation_settings.ASYNC_MODE @@ -74,7 +74,7 @@ def test_get_update_mode_if_no_schema_and_de_identified( """Validation must be in async mode if we don't have a schema and dataset is de_identified""" dataset = dataset_factory(de_identified_data="YES") - resource = resource_factory(package_id=dataset["id"]) + resource = resource_factory(package_id=dataset["id"], schema=None) mode = validation_settings.get_update_mode({}, resource) assert mode == validation_settings.ASYNC_MODE diff --git a/test/features/resource_type_validation.feature b/test/features/resource_type_validation.feature new file mode 100644 index 00000000..30286cf0 --- /dev/null +++ b/test/features/resource_type_validation.feature @@ -0,0 +1,16 @@ +@resource_type_validation +Feature: Resource type validation + + Scenario: As an evil user, when I try to upload a resource with a MIME type not matching its extension, I should get an error + Given "TestOrgEditor" as the persona + When I log in + And I create a dataset with key-value parameters "notes=Testing resource type mismatch" + And I open the new resource form for dataset "$last_generated_name" + And I create a resource with key-value parameters "name=Testing EICAR PDF::description=Testing EICAR sample virus file with PDF extension::format=PDF::upload=eicar.com.pdf" + Then I should see "Mismatched file type" + + Scenario: As a publisher, when I create a resource linking to an internal URL, I should not see any type mismatch errors + Given "TestOrgEditor" as the persona + When I log in + And I create a dataset and resource with key-value parameters "notes=Testing internal URL" and "name=Internal link::url=http://ckan:5000/api/action/status_show" + Then I should see "Testing internal URL" diff --git a/test/features/steps/steps.py b/test/features/steps/steps.py index 52ba25e7..449d1d5d 100644 --- a/test/features/steps/steps.py +++ b/test/features/steps/steps.py @@ -461,7 +461,7 @@ def _parse_params(param_string): for param in param_string.split("::"): entry = param.split("=", 1) params[entry[0]] = entry[1] if len(entry) > 1 else "" - return params.items() + return six.iteritems(params) @when(u'I show the non-JavaScript schema fields') diff --git a/test/features/xloader.feature b/test/features/xloader.feature new file mode 100644 index 00000000..a39096c9 --- /dev/null +++ b/test/features/xloader.feature @@ -0,0 +1,36 @@ +@OpenData +@XLoader +Feature: XLoader + + Scenario: As a publisher, when I visit a resource I control with a datastore entry, I can access the XLoader interface + Given "TestOrgEditor" as the persona + When I log in + And I create a dataset and resource with key-value parameters "notes=Testing XLoader" and "name=test-csv-resource::url=https://people.sc.fsu.edu/~jburkardt/data/csv/addresses.csv::format=CSV" + # Wait for XLoader to run + And I press "test-csv-resource" + And I reload page every 3 seconds until I see an element with xpath "//*[contains(string(), 'DataStore')]" but not more than 6 times + Then I should see "DataStore" + + When I press "DataStore" + And I reload page every 3 seconds until I see an element with xpath "//*[contains(string(), 'Express Load completed')]" but not more than 6 times + Then I should see "Express Load completed" + And I should see "Data Schema" + And I should see "Data Dictionary" + And I should see "Upload to DataStore" + And I should see "Delete from DataStore" + And I should see "Status" + And I should see "Last updated" + And I should see "Upload Log" + And I should see "View resource" + + When I press "Upload to DataStore" + Then I should see "Status" + And I should see "Pending" + And I should see "Delete from DataStore" + + When I press "Delete from DataStore" + And I confirm the dialog containing "delete the DataStore" if present + Then I should see "DataStore and Data Dictionary deleted for resource" + And I should see "Upload to DataStore" + And I should not see "Delete from DataStore" + And I should not see an element with xpath "//a[contains(@href, '/dictionary/')]" diff --git a/test/fixtures/eicar.com.pdf b/test/fixtures/eicar.com.pdf new file mode 100644 index 0000000000000000000000000000000000000000..a2463df6d6421be9fe983071e5a69d379f09c84e GIT binary patch literal 68 zcmazr^;Zl~b#M%bHi-#{iZC_N2#C`(cXrk^uT^pNbao8V4GwYib8!rE(RK6-@eK0} X3Jul`aSaa9b@TLbRaEiN_Rs