diff --git a/.ahoy.yml b/.ahoy.yml index 21de7eec..8974edd7 100644 --- a/.ahoy.yml +++ b/.ahoy.yml @@ -66,7 +66,9 @@ commands: logs: usage: Show Docker logs. - cmd: sh bin/docker-compose.sh logs "$@" + cmd: | + ahoy title "Output logs" + sh bin/docker-compose.sh logs "$@" pull: usage: Pull latest docker images. @@ -181,28 +183,28 @@ commands: usage: Starts default CKAN background job worker cmd: | ahoy title 'Starting default CKAN background job worker' - ahoy cli "ckan_cli jobs clear && \ - ckan_cli jobs worker" + ahoy cli "ckan_cli jobs worker" start-ckan-job-worker-priority: usage: Starts CKAN background job worker for priority tasks cmd: | ahoy title 'Starting CKAN background job worker priority' - ahoy cli "ckan_cli jobs clear priority && \ - ckan_cli jobs worker priority" + ahoy cli "ckan_cli jobs worker priority" start-ckan-job-worker-bulk: usage: Starts CKAN background job worker for low-priority tasks cmd: | ahoy title 'Starting CKAN background job worker bulk' - ahoy cli "ckan_cli jobs clear bulk && \ - ckan_cli jobs worker bulk" + ahoy cli "ckan_cli jobs worker bulk" stop-ckan-job-workers: usage: Stops CKAN background job worker cmd: | ahoy title 'Stopping CKAN background job worker' - ahoy cli "pkill -f 'jobs worker'" + ahoy cli "ckan_cli jobs clear; \ + ckan_cli jobs clear priority; \ + ckan_cli jobs clear bulk; + (pgrep 'jobs worker' && pkill -f 'jobs worker') || true" # Utilities. title: diff --git a/.flake8 b/.flake8 index 8f66602c..6892859f 100644 --- a/.flake8 +++ b/.flake8 @@ -18,4 +18,6 @@ max-line-length = 127 # List ignore rules one per line. ignore = + C901 + E501 W503 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1ae6e5d6..bee0ee74 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,7 +46,7 @@ jobs: - name: Retrieve logs if: always() run: bin/get-logs.sh - timeout-minutes: 5 + timeout-minutes: 1 - name: Retrieve screenshots if: always() diff --git a/bin/serve.sh b/bin/serve.sh index df22c1ad..531b22b7 100755 --- a/bin/serve.sh +++ b/bin/serve.sh @@ -17,7 +17,7 @@ done . ${APP_DIR}/bin/activate if (which ckan > /dev/null); then - ckan -c ${CKAN_INI} run --disable-reloader --threaded + ckan -c ${CKAN_INI} run --disable-reloader --threaded else paster serve ${CKAN_INI} fi diff --git a/test/features/comments.feature b/test/features/comments.feature index f1e28fa7..d29d1468 100644 --- a/test/features/comments.feature +++ b/test/features/comments.feature @@ -32,7 +32,8 @@ Feature: Comments Scenario: When a logged-in user submits a comment on a Data Request the comment should then be visible on the Comments tab of the Data Request Given "CKANUser" as the persona When I log in - And I go to data request "Test Request" comments + And I create a datarequest + And I go to data request "$last_generated_title" comments Then I should see an element with xpath "//h3[contains(string(), 'Add a comment')]" When I submit a comment with subject "Test subject" and comment "This is a test comment" Then I should see "This is a test comment" within 10 seconds @@ -41,11 +42,12 @@ Feature: Comments Scenario: When a logged-in user submits a comment on a Data Request the email should contain title and comment Given "CKANUser" as the persona When I log in - And I go to data request "Test Request" comments + And I create a datarequest + And I go to data request "$last_generated_title" comments Then I should see an element with xpath "//h3[contains(string(), 'Add a comment')]" - When I submit a comment with subject "Test Request" and comment "This is a test data request comment" + When I submit a comment with subject "Testing Data Request comment" and comment "This is a test data request comment" And I wait for 5 seconds - Then I should receive a base64 email at "test_org_admin@localhost" containing both "Data request subject: Test Request" and "Comment: This is a test data request comment" + Then I should receive a base64 email at "dr_admin@localhost" containing both "Data request subject: Test Title" and "Comment: This is a test data request comment" @comment-add @comment-profane Scenario: When a logged-in user submits a comment containing profanity on a Dataset they should receive an error message and the comment will not appear @@ -71,7 +73,8 @@ Feature: Comments Scenario: When a logged-in user submits a comment containing profanity on a Data Request they should receive an error message and the comment will not appear Given "CKANUser" as the persona When I log in - And I go to data request "Test Request" comments + And I create a datarequest + And I go to data request "$last_generated_title" comments Then I should see an element with xpath "//h3[contains(string(), 'Add a comment')]" When I submit a comment with subject "Test subject" and comment "He had sheep, and oxen, and he asses, and menservants, and maidservants, and she asses, and camels." Then I should see "Comment blocked due to profanity" within 5 seconds @@ -86,21 +89,26 @@ Feature: Comments When I submit a comment with subject "Testing flags" and comment "Test" And I press the element with xpath "//a[contains(@class, 'flag-comment')][1]" And I confirm the dialog containing "comment has been flagged as inappropriate" if present - Then I should see "Reported" within 5 seconds + And I wait for 5 seconds + And I go to dataset "$last_generated_name" comments + Then I should see "Reported" And I should receive a base64 email at "test_org_admin@localhost" containing "This comment has been flagged as inappropriate by a user" @comment-report @datarequest @email Scenario: When a logged-in user reports a comment on a Data Request the comment should be marked as reported and an email notification sent to the organisation admins Given "CKANUser" as the persona When I log in - And I go to data request "Test Request" comments + And I create a datarequest + And I go to data request "$last_generated_title" comments And I submit a comment with subject "Test reporting" and comment "Testing comment reporting" Then I should see "Testing comment reporting" within 10 seconds When I press the element with xpath "//a[contains(@class, 'flag-comment')][1]" And I confirm the dialog containing "comment has been flagged as inappropriate" if present - Then I should see "Reported" within 5 seconds - And I should receive a base64 email at "test_org_admin@localhost" containing "This comment has been flagged as inappropriate by a user" + And I wait for 5 seconds + And I go to data request "$last_generated_title" comments + Then I should see "Reported" + And I should receive a base64 email at "dr_admin@localhost" containing "This comment has been flagged as inappropriate by a user" @comment-reply Scenario: When a logged-in user submits a reply comment on a Dataset, the comment should display within 10 seconds @@ -128,13 +136,15 @@ Feature: Comments @comment-delete @datarequest Scenario: When an admin visits a data request belonging to their organisation, they can delete a comment and should see deletion text for the user responsible. - Given "TestOrgAdmin" as the persona + Given "DataRequestOrgAdmin" as the persona When I log in - And I go to data request "Test Request" comments + And I create a datarequest + And I go to data request "$last_generated_title" comments + When I submit a comment with subject "Testing deletion" and comment "Test" And I press the element with xpath "//a[@title='Delete comment']" And I confirm the dialog containing "Are you sure you want to delete this comment?" if present Then I should not see "This comment was deleted." within 2 seconds - And I should see "Comment deleted by Test Admin." within 2 seconds + And I should see "Comment deleted by Data Request Admin." within 2 seconds @comment-tab @unauthenticated diff --git a/test/features/datarequest_circumstances.feature b/test/features/datarequest_circumstances.feature index fdb5603b..c2b5d59a 100644 --- a/test/features/datarequest_circumstances.feature +++ b/test/features/datarequest_circumstances.feature @@ -123,7 +123,8 @@ Feature: Datarequest-circumstances And I select "Open dataset already exists" from "close_circumstance" And I wait for 1 seconds # Have to use JS to change the selected value as the behaving framework does not work with autocomplete dropdown - And I execute the script "$('#field-accepted_dataset_id').val($('#field-accepted_dataset_id option:eq(1)').attr('value'))" + And I execute the script "$('#field-accepted_dataset_id option:contains("Dataset for data requests")').attr('selected', 'selected')" + And I take a debugging screenshot And I press the element with xpath "//button[contains(@class, 'btn-danger') and @name='close']" Then I should see "Accepted dataset" within 1 seconds And I should see "Dataset for data requests" within 1 seconds diff --git a/test/features/engagement_reporting.feature b/test/features/engagement_reporting.feature index 8941f7ce..683e3d0a 100644 --- a/test/features/engagement_reporting.feature +++ b/test/features/engagement_reporting.feature @@ -30,14 +30,14 @@ Feature: Engagement Reporting And I press "Engagement Report" And I press the element with xpath "//button[contains(string(), 'Show')]" Then I should see an element with xpath "//tr[@id='datarequests-total']/td[contains(@class, 'metric-title') and string()='Data requests' and position()=1]" - And I should see an element with xpath "//tr[@id='datarequests-total']/td[contains(@class, 'metric-data') and string()='25' and position()=2]" + And I should see an element with xpath "//tr[@id='datarequests-total']/td[contains(@class, 'metric-data') and string()='30' and position()=2]" When I create a datarequest And I go to my reports page And I press "Engagement Report" And I press the element with xpath "//button[contains(string(), 'Show')]" Then I should see an element with xpath "//tr[@id='datarequests-total']/td[contains(@class, 'metric-title') and string()='Data requests' and position()=1]" - And I should see an element with xpath "//tr[@id='datarequests-total']/td[contains(@class, 'metric-data') and string()='26' and position()=2]" + And I should see an element with xpath "//tr[@id='datarequests-total']/td[contains(@class, 'metric-data') and string()='31' and position()=2]" Scenario: As an admin user of my organisation, when I view my engagement report, I can verify the numbers are correct and increment Given "ReportingOrgAdmin" as the persona @@ -55,7 +55,9 @@ Feature: Engagement Reporting And I should see an element with xpath "//tr[contains(@class, 'closing-circumstance')]/td[position()=2]/a[contains(@href, '/closed?') and string()='0']" When I create a dataset and resource with key-value parameters "notes=Dataset for engagement reporting" and "url=default" - And I press the element with xpath "//a[@class='btn btn-success' and contains(string(), 'Follow')]" + And I take a debugging screenshot + And I press "Follow" + And I take a debugging screenshot And I go to dataset "$last_generated_name" comments And I submit a comment with subject "Test subject" and comment "This is a test comment" And I go to data request "Reporting Request" comments diff --git a/test/features/resource_align_default_schema.feature b/test/features/resource_align_default_schema.feature index 8f406218..938ea942 100644 --- a/test/features/resource_align_default_schema.feature +++ b/test/features/resource_align_default_schema.feature @@ -10,17 +10,20 @@ Feature: Resource align_default_schema field Then I should see an element with xpath "//th[@class="dataset-label" and string()="Default data schema"]/following-sibling::td[contains(string(), "[blank]")]" When I go to the first resource in the dataset - And I press the element with xpath "//a[contains(string(),'Manage')]" + And I press "Manage" Then I should not see "Align this data schema with the dataset default" - And I should see "Upload" - And I should see "Link" - And I should see "JSON" + And I should see an element with xpath "//div[@id='resource-schema-buttons']/label[contains(string(), 'Data Schema')]" + When I show the non-JavaScript schema fields + Then I should see "Upload Data Schema" + And I should see "Data Schema URL" + And I should see "Data Schema JSON definition" When I open the new resource form for dataset "$last_generated_name" Then I should not see "Align this data schema with the dataset default" - And I should see "Upload" - And I should see "Link" - And I should see "JSON" + When I show the non-JavaScript schema fields + Then I should see "Upload Data Schema" + And I should see "Data Schema URL" + And I should see "Data Schema JSON definition" Scenario: Create resource with schema not aligned to default schema Given "TestOrgEditor" as the persona @@ -39,65 +42,47 @@ Feature: Resource align_default_schema field And I go to the first resource in the dataset Then I should see an element with xpath "//th[string()='Aligned with default data schema']/following-sibling::td[string()='FALSE']" - Scenario: Edit a resource in the GUI where default schema exists and the existing schema value does not match the default + Scenario: Edit a resource in the GUI where default schema exists Given "TestOrgEditor" as the persona When I log in And I create a dataset and resource with key-value parameters "schema_json=default" and "name=another-resource::schema=default::align_default_schema=False" Then I should see an element with xpath "//th[@class="dataset-label" and string()="Default data schema"]/following::a[contains(string(), "View Schema File")]" + # Default and resource schema are different + When I go to the first resource in the dataset Then I should see an element with xpath "//th[string()='Aligned with default data schema']/following-sibling::td[string()='FALSE']" When I click the link with text "View Schema File" Then I should see an element with xpath "//body[contains(string(), '"Resource schema"')]" When I go back - And I press the element with xpath "//a[contains(string(), 'Manage')]" - Then I should see an element with xpath "//input[@type='checkbox' and @name='align_default_schema' and not(@checked)]/following-sibling::label[@for='field-align_default_schema' and contains(string(),'Align this data schema with the dataset default')]" + And I press "Manage" + Then I should see "Align this data schema with the dataset default" + And I should see an element with xpath "//input[@name='align_default_schema' and not(@checked)]" - When I check "align_default_schema" - And I press the element with xpath "//button[string()='Update Resource']" - Then I should see an element with xpath "//th[string()='Aligned with default data schema']/following-sibling::td[string()='TRUE']" + When I set the resource schema to the dataset default + And I press "Update Resource" + Then I should see an element with xpath "//th[string()='Aligned with default data schema']/following-sibling::td[translate(string(), 'true', 'TRUE')='TRUE']" When I click the link with text "View Schema File" Then I should see an element with xpath "//body[contains(string(), '"Default schema"')]" - Scenario: Edit resource in the GUI where default schema exists and the existing schema value matches the default - Given "TestOrgEditor" as the persona - When I log in - And I create a dataset and resource with key-value parameters "schema_json=default" and "name=another-resource::schema=::align_default_schema=False" - Then I should see an element with xpath "//th[@class="dataset-label" and string()="Default data schema"]/following::a[contains(string(), "View Schema File")]" - - When I go to the first resource in the dataset - Then I should see an element with xpath "//th[string()='Aligned with default data schema']/following-sibling::td[string()='FALSE']" - When I press the element with xpath "//a[contains(string(), 'Manage')]" - Then I should see "Align this data schema with the dataset default" - - When I execute the script "document.getElementById('field-schema').value='{"fields":[{"format": "default","name": "Game Number","type": "integer"},{"format": "default","name": "Game Length","type": "integer"}],"missingValues": ["Default schema"]}'" - And I press the element with xpath "//button[string()='Update Resource']" - Then I should see an element with xpath "//th[string()='Aligned with default data schema']/following-sibling::td[string()='TRUE']" - # now default and resource schema are the same - When I press the element with xpath "//a[contains(string(), 'Manage')]" - Then I should not see "Align this data schema with the dataset default" - - # now default and resource schema are different - When I press the element with xpath "//textarea[@id='field-schema-json']/preceding-sibling::a[string()='Clear']" - And I execute the script "document.getElementById('field-schema').value='{"fields":[{"format": "default","name": "Game Number","type": "integer"},{"format": "default","name": "Game Length","type": "integer"}], "missingValues": ["Resource schema"]}'" - When I press the element with xpath "//button[string()='Update Resource']" - And I press the element with xpath "//a[contains(string(), 'Manage')]" + When I go back + And I press "Manage" Then I should see "Align this data schema with the dataset default" + And I should see an element with xpath "//input[@name='align_default_schema' and @checked]" - When I press the element with xpath "//button[string()='Update Resource']" + When I uncheck "align_default_schema" + And I execute the script "$('#field-schema-json ~ a.btn-remove-url').click()" + And I execute the script "$('#field-schema-json').val('{"fields": [{"format": "default", "name": "Foo", "type": "string"}], "missingValues": ["Baz"]}')" + And I take a debugging screenshot + And I press "Update Resource" And I click the link with text "View Schema File" - Then I should see an element with xpath "//body[contains(string(), '"Resource schema"')]" - + Then I should see an element with xpath "//body[contains(string(), '"Baz"')]" When I go back - And I press the element with xpath "//a[contains(string(), 'Manage')]" - Then I should see an element with xpath "//input[@type='checkbox' and @name='align_default_schema' and not(@checked)]/following-sibling::label[@for='field-align_default_schema' and contains(string(), 'Align this data schema with the dataset default')]" - - When I check "align_default_schema" - And I press the element with xpath "//button[string()='Update Resource']" - Then I should see an element with xpath "//th[string()='Aligned with default data schema']/following-sibling::td[string()='TRUE']" - - When I click the link with text "View Schema File" - Then I should see an element with xpath "//body[contains(string(), '"Default schema"')]" + Then I should see an element with xpath "//th[string()='Aligned with default data schema']/following-sibling::td[translate(string(), 'false', 'FALSE')='FALSE']" + When I press "Manage" + And I check "align_default_schema" + And I press "Update Resource" + Then I should see an element with xpath "//th[string()='Aligned with default data schema']/following-sibling::td[translate(string(), 'true', 'TRUE')='TRUE']" diff --git a/test/features/resource_availability.feature b/test/features/resource_availability.feature index 36f7fc1b..b4aa5b30 100644 --- a/test/features/resource_availability.feature +++ b/test/features/resource_availability.feature @@ -5,7 +5,7 @@ Feature: Re-identification risk governance acknowledgement or Resource visibilit Scenario: As a publisher, I can view hidden resources Given "TestOrgEditor" as the persona When I log in - And I create a dataset and resource with key-value parameters "name=package-with-invisible-resource::notes=Package with invisible resource::de_identified_data=NO::private=False" and "name=invisible-resource::resource_visible=FALSE" + And I create a dataset and resource with key-value parameters "name=package-with-invisible-resource::notes=Package with invisible resource::de_identified_data=NO" and "name=invisible-resource::resource_visible=FALSE" Then I should see "invisible-resource" And I should see "HIDDEN" When I press "invisible-resource" @@ -23,7 +23,7 @@ Feature: Re-identification risk governance acknowledgement or Resource visibilit Scenario: As an unprivileged user, I cannot see resources with privacy assessment requested and risk governance completed Given "TestOrgEditor" as the persona When I log in - And I create a dataset and resource with key-value parameters "name=package-with-assessed-resource::notes=Package with assessed resource::de_identified_data=NO::private=False" and "name=resource-for-assessment::request_privacy_assessment=YES::governance_acknowledgement=YES::resource_visible=TRUE" + And I create a dataset and resource with key-value parameters "name=package-with-assessed-resource::notes=Package with assessed resource::de_identified_data=NO" and "name=resource-for-assessment::request_privacy_assessment=YES::governance_acknowledgement=YES::resource_visible=TRUE" Then I should see "resource-for-assessment" Given "CKANUser" as the persona @@ -35,7 +35,7 @@ Feature: Re-identification risk governance acknowledgement or Resource visibilit Scenario: As an unprivileged user, I can see de-identified resources marked as visible without a privacy assessment Given "TestOrgEditor" as the persona When I log in - And I create a dataset and resource with key-value parameters "name=de-identified-package-with-unassessed-resource::de_identified_data=YES::private=False" and "name=visible-resource::request_privacy_assessment=NO::governance_acknowledgement=YES::resource_visible=TRUE" + And I create a dataset and resource with key-value parameters "name=de-identified-package-with-unassessed-resource::de_identified_data=YES" and "name=visible-resource::request_privacy_assessment=NO::governance_acknowledgement=YES::resource_visible=TRUE" Given "CKANUser" as the persona When I log out @@ -79,10 +79,10 @@ Feature: Re-identification risk governance acknowledgement or Resource visibilit Given "TestOrgEditor" as the persona When I log in And I create a dataset and resource with key-value parameters "de_identified_data=NO" and "name=invisible-resource::resource_visible=FALSE" - And I should see "HIDDEN" - And I press "invisible-resource" - And I should see "HIDDEN" - And I press "Manage" + Then I should see "HIDDEN" + When I press "invisible-resource" + Then I should see "HIDDEN" + When I press "Manage" Then I should not see an element with xpath "//label[@for="field-request_privacy_assessment"]//*[@class="control-required"]" And I should see an element with xpath "//select[@id="field-request_privacy_assessment"]//option[@value="" or @value="YES" or @value="NO"]" And I should see "Privacy risk assessment prior to public release might assist the publishing decision-making process" @@ -94,11 +94,11 @@ Feature: Re-identification risk governance acknowledgement or Resource visibilit Scenario: As an anonymous user, I can see resources without de-identified data Given "TestOrgEditor" as the persona When I log in - And I create a dataset and resource with key-value parameters "name=package-without-de-identified-data::de_identified_data=NO::private=False" and "name=visible-resource::governance_acknowledgement=NO::resource_visible=TRUE" + And I create a dataset and resource with key-value parameters "name=package-without-de-identified-data::de_identified_data=NO" and "name=visible-resource::governance_acknowledgement=NO::resource_visible=TRUE" When I log out And I go to dataset "package-without-de-identified-data" Then I should not see "HIDDEN" And I should see "visible-resource" - And I click the link with text that contains "visible-resource" - And I should not see "HIDDEN" + When I click the link with text that contains "visible-resource" + Then I should not see "HIDDEN" diff --git a/test/features/resource_privacy_assessment_result.feature b/test/features/resource_privacy_assessment_result.feature index d84a0668..0f6a57ef 100644 --- a/test/features/resource_privacy_assessment_result.feature +++ b/test/features/resource_privacy_assessment_result.feature @@ -34,7 +34,7 @@ Feature: Resource Privacy Assessment Result Scenario: Email to dataset contact when result of requested privacy assessment is posted Given "SysAdmin" as the persona When I log in - And I create a dataset and resource with key-value parameters "name=package-with-new-privacy-assessment::author_email=test@gmail.com" and "name=pending-assessment-resource::request_privacy_assessment=YES" + And I create a dataset and resource with key-value parameters "notes=Package with new privacy assessment::author_email=test@gmail.com" and "name=pending-assessment-resource::request_privacy_assessment=YES" And I go to the first resource in the dataset And I press the element with xpath "//a[contains(string(), 'Manage')]" And I fill in "privacy_assessment_result" with "New privacy_assessment_result" diff --git a/test/features/schema_generation.feature b/test/features/schema_generation.feature index 148eed2b..1c5a8a8e 100644 --- a/test/features/schema_generation.feature +++ b/test/features/schema_generation.feature @@ -5,16 +5,20 @@ Feature: Schema Generation Scenario: As a publisher, when I visit my resource, I can generate a validation schema for it Given "TestOrgEditor" as the persona When I log in - And I create a dataset and resource with key-value parameters "name=package-with-csv-res::schema_json=default" and "upload=default::format=CSV" + And I create a dataset and resource with key-value parameters "notes=package-with-csv-res::schema_json=default" and "upload=default::format=CSV" + And I take a debugging screenshot And I go to the first resource in the dataset + And I take a debugging screenshot + # Ensure that the datastore is active + And I reload page every 3 seconds until I see an element with xpath "//*[string() = 'Data Dictionary']" but not more than 6 times And I visit resource schema generation page - And I reload page every 3 seconds until I see an element with xpath "//ul[@class="nav nav-tabs"]/li[position()=2]/a[contains(string(), 'Data Schema')]" but not more than 6 times - Then I should see an element with xpath "//button[contains(string(), 'Generate JSON data schema')]" - And I should see an element with xpath "//button[contains(@class, 'btn-generate')]/following::table[contains(@class, 'table-schema')]" + And I take a debugging screenshot + Then I should see an element with xpath "//button[contains(string(), 'Generate JSON data schema') and contains(@class, 'btn-generate')]/following::table[contains(@class, 'table-schema')]" And I should see an element with xpath "//th[string()='Status']/following::td[string()='Not generated']" And I should see an element with xpath "//th[string()='Last updated']/following::td[string()='Never']" - When I press the element with xpath "//button[contains(string(), 'Generate JSON data schema')]" + When I press "Generate JSON data schema" + And I take a debugging screenshot And I reload page every 3 seconds until I see an element with xpath "//th[string()='Status']/following::td[string()='Pending']" but not more than 6 times Then I should see an element with xpath "//th[string()='Last updated']/following::td/span[contains(@class, 'date')]" When I reload page every 3 seconds until I see an element with xpath "//button[string()='Apply']" but not more than 6 times @@ -40,28 +44,31 @@ Feature: Schema Generation Scenario: System actions following the selection of the set as dataset default dropdown option on the manage data schema GUI page Given "TestOrgEditor" as the persona When I log in - And I create a dataset and resource with key-value parameters "name=apply-for-dataset-schema::schema_json=default" and "upload=default::format=CSV" + And I create a dataset and resource with key-value parameters "notes=apply-for-dataset-schema::schema_json=default" and "upload=default::format=CSV" And I go to the first resource in the dataset + And I reload page every 3 seconds until I see an element with xpath "//*[string() = 'Data Dictionary']" but not more than 6 times And I visit resource schema generation page - And I reload page every 3 seconds until I see an element with xpath "//ul[@class="nav nav-tabs"]/li[position()=2]/a[contains(string(), 'Data Schema')]" but not more than 6 times - And I press the element with xpath "//button[contains(string(), 'Generate JSON data schema')]" + Then I should see an element with xpath "//button[contains(string(), 'Generate JSON data schema') and contains(@class, 'btn-generate')]/following::table[contains(@class, 'table-schema')]" + When I press "Generate JSON data schema" And I reload page every 3 seconds until I see an element with xpath "//button[string()='Apply']" but not more than 6 times And I select "dataset" from "apply_for" And I press the element with xpath "//button[string()='Apply']" - And I go to dataset "apply-for-dataset-schema" + And I go to dataset "$last_generated_name" + And I show all the fields Then I should see an element with xpath "//th[@class="dataset-label" and string()="Default data schema"]/following::a[string()="View Schema File"]" - Scenario: System actions following the selection of the validate only this resource dropdown option on the manage data schema GUI page Given "TestOrgEditor" as the persona When I log in - And I create a dataset and resource with key-value parameters "name=apply-for-resource-schema::schema_json=default" and "upload=default::format=CSV" + And I create a dataset and resource with key-value parameters "notes=apply-for-resource-schema::schema_json=default" and "upload=default::format=CSV" And I go to the first resource in the dataset + And I reload page every 3 seconds until I see an element with xpath "//*[string() = 'Data Dictionary']" but not more than 6 times And I visit resource schema generation page - And I reload page every 3 seconds until I see an element with xpath "//ul[@class="nav nav-tabs"]/li[position()=2]/a[contains(string(), 'Data Schema')]" but not more than 6 times - And I press the element with xpath "//button[contains(string(), 'Generate JSON data schema')]" + Then I should see an element with xpath "//button[contains(string(), 'Generate JSON data schema') and contains(@class, 'btn-generate')]/following::table[contains(@class, 'table-schema')]" + When I press "Generate JSON data schema" And I reload page every 3 seconds until I see an element with xpath "//button[string()='Apply']" but not more than 6 times And I select "resource" from "apply_for" And I press the element with xpath "//button[string()='Apply']" And I press the element with xpath "//a[contains(string(), 'View resource')]" + And I show all the fields Then I should see an element with xpath "//th[string()="Data Schema"]/following::a[string()="View Schema File"]" diff --git a/test/features/steps/steps.py b/test/features/steps/steps.py index 73d687e9..170b0c79 100644 --- a/test/features/steps/steps.py +++ b/test/features/steps/steps.py @@ -25,6 +25,24 @@ URL_RE = re.compile(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|\ (?:%[0-9a-fA-F][0-9a-fA-F]))+', re.I | re.S | re.U) +dataset_default_schema = """ + {"fields": [ + {"format": "default", "name": "Game Number", "type": "integer"}, + {"format": "default", "name": "Game Length", "type": "integer"} + ], + "missingValues": ["Default schema"] + } +""" + +resource_default_schema = """ + {"fields": [ + {"format": "default", "name": "Game Number", "type": "integer"}, + {"format": "default", "name": "Game Length", "type": "integer"} + ], + "missingValues": ["Resource schema"] + } +""" + @when(u'I take a debugging screenshot') def debug_screenshot(context): @@ -32,7 +50,7 @@ def debug_screenshot(context): """ if context.persona and context.persona.get('debug') == 'True': context.execute_steps(u""" - Then I take a screenshot + When I take a screenshot """) @@ -64,7 +82,7 @@ def log_in(context): @when(u'I expand the browser height') def expand_height(context): # Work around x=null bug in Selenium set_window_size - context.browser.driver.set_window_rect(x=0, y=0, width=1024, height=4096) + context.browser.driver.set_window_rect(x=0, y=0, width=1024, height=3072) @when(u'I log in directly') @@ -125,10 +143,17 @@ def clear_url(context): @when(u'I confirm the dialog containing "{text}" if present') def confirm_dialog_if_present(context, text): - if context.browser.is_text_present(text): - context.execute_steps(u""" - When I press the element with xpath "//*[contains(@class, 'modal-dialog')]//button[contains(@class, 'btn-primary')]" - """) + dialog_xpath = "//*[contains(@class, 'modal-dialog') and contains(string(), '{0}')]".format(text) + if context.browser.is_element_present_by_xpath(dialog_xpath): + parent_xpath = dialog_xpath + elif context.browser.is_text_present(text): + parent_xpath = "//div[contains(string(), '{0}')]/..".format(text) + else: + return + button_xpath = parent_xpath + "//button[contains(@class, 'btn-primary')]" + context.execute_steps(u""" + When I press the element with xpath "{0}" + """.format(button_xpath)) @when(u'I confirm dataset deletion') @@ -162,6 +187,7 @@ def go_to_new_resource_form(context, name): context.execute_steps(u""" When I press "Resources" And I press "Add new resource" + And I take a debugging screenshot """) @@ -171,6 +197,7 @@ def title_random_text(context): context.execute_steps(u""" When I fill in "title" with "Test Title {0}" And I fill in "name" with "test-title-{0}" if present + And I set "last_generated_title" to "Test Title {0}" And I set "last_generated_name" to "test-title-{0}" """.format(uuid.uuid4())) @@ -186,6 +213,7 @@ def go_to_dataset_page(context): def go_to_dataset(context, name): context.execute_steps(u""" When I visit "/dataset/{0}" + And I take a debugging screenshot """.format(name)) @@ -193,6 +221,17 @@ def go_to_dataset(context, name): def go_to_first_resource(context): context.execute_steps(u""" When I press the element with xpath "//li[@class="resource-item"]/a" + And I take a debugging screenshot + """) + + +@when(u'I show all the fields') +def show_more_fields(context): + """ + Click the 'Show more' link, if present, to reveal all the metadata. + """ + context.execute_steps(u""" + When I execute the script "$('a.show-more').click()" """) @@ -350,6 +389,18 @@ def _parse_params(param_string): return six.iteritems(params) +@when(u'I show the non-JavaScript schema fields') +def reveal_non_js_schema_fields(context): + context.execute_steps(u""" + When I execute the script "$('#resource-schema-buttons ~ div.form-group').attr('style', '')" + """) + + +@when(u'I set the resource schema to the dataset default') +def set_resource_schema_to_dataset_default(context): + _enter_manual_schema(context, dataset_default_schema) + + # Enter a JSON schema value # This can require JavaScript interaction, and doesn't fit well into # a step invocation due to all the double quotes. @@ -367,6 +418,8 @@ def _create_dataset_from_params(context, params): When I visit "/dataset/new" And I fill in default dataset fields """) + if 'private' not in params: + params = params + "::private=False" for key, value in _parse_params(params): if key == "name": # 'name' doesn't need special input, but we want to remember it @@ -390,14 +443,7 @@ def _create_dataset_from_params(context, params): """.format(value)) elif key == "schema_json": if value == "default": - value = """ - {"fields": [ - {"format": "default", "name": "Game Number", "type": "integer"}, - {"format": "default", "name": "Game Length", "type": "integer"} - ], - "missingValues": ["Default schema"] - } - """ + value = dataset_default_schema _enter_manual_schema(context, value) else: context.execute_steps(u""" @@ -477,18 +523,7 @@ def create_resource_from_params(context, resource_params): """.format(key, option)) elif key == "schema": if value == "default": - value = """{ - "fields": [{ - "format": "default", - "name": "Game Number", - "type": "integer" - }, { - "format": "default", - "name": "Game Length", - "type": "integer" - }], - "missingValues": ["Resource schema"] - }""" + value = resource_default_schema _enter_manual_schema(context, value) else: context.execute_steps(u""" @@ -522,7 +557,7 @@ def filter_contents(mail): else: import base64 decoded_payload = six.ensure_text(base64.b64decode(six.ensure_binary(payload_bytes))) - print('decoded_payload: ', decoded_payload) + print('Searching for', text, ' and ', text2, ' in decoded_payload: ', decoded_payload) return text in decoded_payload and (not text2 or text2 in decoded_payload) assert context.mail.user_messages(address, filter_contents) @@ -559,7 +594,7 @@ def reload_page_every_n_until_find(context, xpath, seconds=5, reload_times=5): assert False, 'Element with xpath "{}" was not found'.format(xpath) -# ckanext-data-qld +# ckanext-validation-schema-generator @when(u'I visit resource schema generation page') @@ -570,6 +605,9 @@ def resource_schema_generation(context): """.format(path)) +# ckanext-data-qld + + @when(u'I trigger notification about updated privacy assessment results') def i_trigger_notification_assessment_results(context): context.execute_steps(u""" @@ -707,6 +745,7 @@ def create_datarequest(context): And I press "Add data request" And I fill in title with random text And I fill in "description" with "Test description" + And I execute the script "$('#field-organizations option:contains("Open Data Administration")').attr('selected', true)" And I press the element with xpath "//button[contains(@class, 'btn-primary')]" """) diff --git a/vars/shared-CKANTest.var.yml b/vars/shared-CKANTest.var.yml index bbba24cc..50083964 100644 --- a/vars/shared-CKANTest.var.yml +++ b/vars/shared-CKANTest.var.yml @@ -71,7 +71,7 @@ extensions: description: "CKAN Extension for Queensland Government Open Data" type: "git" url: "https://github.com/qld-gov-au/ckanext-data-qld.git" - version: "7.2.2" + version: "7.2.3" CKANExtDataRequests: &CKANExtDataRequests name: "ckanext-datarequests-{{ Environment }}" diff --git a/vars/shared-OpenData.var.yml b/vars/shared-OpenData.var.yml index a830051b..eb97fb27 100644 --- a/vars/shared-OpenData.var.yml +++ b/vars/shared-OpenData.var.yml @@ -71,7 +71,7 @@ extensions: description: "CKAN Extension for Queensland Government Open Data" type: "git" url: "https://github.com/qld-gov-au/ckanext-data-qld.git" - version: "7.2.2" + version: "7.2.3" CKANExtDataRequests: &CKANExtDataRequests name: "ckanext-datarequests-{{ Environment }}"