Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress upgrade #803

Merged
merged 6 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CKAN___API_TOKEN__JWT__DECODE__SECRET=string:CHANGE_ME

# Put envvars last per envvars doc, https://github.com/okfn/ckanext-envvars#requirements
# Not including saml2auth
CKAN__PLUGINS=datagov_inventory datastore xloader stats text_view recline_view googleanalyticsbasic s3filestore dcat_usmetadata usmetadata datajson envvars
CKAN__PLUGINS=datagov_inventory datastore xloader stats text_view recline_view s3filestore dcat_usmetadata usmetadata datajson envvars

CKAN__SITE_TITLE=Inventory
CKAN__SITE_LOGO=/base/images/inventory-logo.png
Expand All @@ -42,6 +42,7 @@ CKAN_SQLALCHEMY_URL=postgresql://ckan:pass@db/ckan
CKAN_HOME=/srv/app
CKAN_CONFIG=/app/config
PORT=5000
CKAN_SITE_URL=http://ckan:5000

CKAN_DATASTORE_WRITE_URL=postgresql://datastore:pass@datastore/datastore
CKAN_DATASTORE_READ_URL=postgresql://datastore_ro:pass@datastore/datastore
Expand Down Expand Up @@ -102,9 +103,6 @@ CKANEXT__XLOADER__JOB_TIMEOUT=3600
# not be loaded into the datastore.
CKANEXT__XLOADER__MAX_EXCERPT_LINES=100

## google analytics ids
CKANEXT___GOOGLEANALYTICS__IDS=google-analytics-fake-key-testing-87654321

## S3Filestore setttings
# The maximum content size, in bytes, for uploads
CKAN__STORAGE__MAX_CONTENT_LENGTH=650000000
Expand Down
5 changes: 1 addition & 4 deletions config/ckan.ini
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ ckan.cors.origin_whitelist = https://gsa.gov https://www.gsa.gov
# same origin policy

# Put envvars last per envvars doc, https://github.com/okfn/ckanext-envvars#requirements
ckan.plugins = datagov_inventory datastore xloader stats text_view recline_view googleanalyticsbasic s3filestore dcat_usmetadata usmetadata datajson saml2auth envvars
ckan.plugins = datagov_inventory datastore xloader stats text_view recline_view s3filestore dcat_usmetadata usmetadata datajson saml2auth envvars

ckan.views.default_views = recline_view text_view image_view webpage_view recline_grid_view

Expand Down Expand Up @@ -251,9 +251,6 @@ smtp.starttls = False
#smtp.mail_from =
error_message = Server Error - Refresh the Page: An internal server error occurred. Try refreshing the page by pressing F5 or Ctrl+F5.

## googleanalyticsbasic, to be configurable https://github.com/GSA/datagov-deploy/issues/2790
googleanalytics.ids = UA-42145528-2 UA-17367410-17

## Logging configuration
[loggers]
keys = root, ckan, ckanext, datajson
Expand Down
10 changes: 8 additions & 2 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ services:
environment:
- CKAN_SITE_URL=http://ckan:5000
test:
image: cypress/included:7.3.0
image: cypress/included:12.17.2
entrypoint: []
command: /bin/bash -c "npm install && npx wait-on http://ckan:5000/api/action/status_show && cypress run"
command: /bin/bash -c "
rm -rf /etc/apt/sources.list.d/google-chrome.list && \
btylerburton marked this conversation as resolved.
Show resolved Hide resolved
apt-get update && \
apt-get install -y unzip && \
npm install && \
npx wait-on http://ckan:5000/api/action/status_show && \
cypress run "
# To run specific test, use the following syntax:
# command: /bin/bash -c "npm install && npx wait-on http://ckan:5000/api/action/status_show && cypress run --spec cypress/integration/dcat_us_export.spec.js"
# command: /bin/bash -c "npm install && npx wait-on http://ckan:5000/api/action/status_show && cypress run --spec cypress/integration/login.spec.js"
Expand Down
22 changes: 22 additions & 0 deletions e2e/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
reporter: 'junit',
reporterOptions: {
mochaFile: 'cypress/results/output.xml',
},
videoCompression: false,
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
},
baseUrl: 'http://ckan:5000',
specPattern: 'cypress/integration/*.cy.js',
},
retries: {
runMode: 2,
openMode: 0,
},
})
8 changes: 0 additions & 8 deletions e2e/cypress.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('CKAN Extensions', () => {
expect(installed_extensions).to.include('xloader');
expect(installed_extensions).to.include('stats');
expect(installed_extensions).to.include('recline_view');
expect(installed_extensions).to.include('googleanalyticsbasic');
expect(installed_extensions).to.include('s3filestore');
expect(installed_extensions).to.include('envvars');
expect(installed_extensions).to.include('datastore');
Expand Down
42 changes: 42 additions & 0 deletions e2e/cypress/integration/ckan_token.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
describe('CKAN Token', () => {

before(() => {
cy.create_token();
});

after(() => {
cy.revoke_token();
});

it('Can get CKAN token', () => {
const token_data = Cypress.env('token_data');
expect(token_data.api_token).to.have.length(175);
expect(token_data.jti).to.have.length(43);
});

it('Can authorize with token', () => {
const token_data = Cypress.env('token_data');
cy.logout();

// 403 without token
cy.request({
method: 'GET',
url: '/api/action/package_search',
failOnStatusCode: false,
}).then((response) => {
expect(response.status).to.eq(403);
});

// 200 with token
cy.request({
method: 'GET',
url: '/api/action/package_search',
headers: {
'Authorization': token_data.api_token
}
}).then((response) => {
expect(response.status).to.eq(200);
});
});

})
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
describe('Dataset', () => {

before(() => {
cy.create_token();
cy.logout();
cy.login();
cy.delete_organization('test-organization');
cy.create_organization('test-organization', 'Test organization');
});

beforeEach(() => {
Cypress.Cookies.preserveOnce('auth_tkt', 'ckan');
});

after(() => {
cy.delete_dataset('test-dataset-1');
cy.delete_organization('test-organization');
cy.revoke_token();
});

it('Creates dataset via API', () => {
Expand All @@ -25,32 +22,41 @@ describe('Dataset', () => {
});

it('Has a details page with core metadata', () => {
cy.login();
cy.visit('/dataset/test-dataset-1');
cy.contains('Test Dataset 1');
cy.contains('DCAT-US Metadata');
});

it('Add resource to private dataset via API', () => {
const token_data = Cypress.env('token_data');
cy.logout();
cy.fixture('ckan_resource.csv', 'binary').then((ckan_resource) => {
// File in binary format gets converted to blob so it can be sent as Form data
const blob = Cypress.Blob.binaryStringToBlob(ckan_resource)
const formData = new FormData();
formData.set('upload', blob, 'ckan_resource.csv'); //adding a file to the form
formData.set('package_id', "test-dataset-1");
formData.set('name', "test-resource-1");
formData.set('resource_type', "CSV");
formData.set('format', "CSV");
cy.form_request('POST', '/api/action/resource_create', formData, function (response) {
formData.append('upload', blob, 'ckan_resource.csv'); //adding a file to the form
formData.append('package_id', "test-dataset-1");
formData.append('name', "test-resource-1");
formData.append('resource_type', "CSV");
formData.append('format', "CSV");
cy.request({
method: 'POST',
url: '/api/action/resource_create',
body: formData,
headers: {
'Content-Type': 'multipart/form-data',
'Authorization': token_data.api_token
}
}).then((response) => {
expect(response.status).to.eq(200);
});
});
cy.visit('/dataset');
});

it('Download resource file', () => {
cy.login();
cy.visit('/dataset/test-dataset-1')
// Hide flask debug toolbar
cy.get('#flDebugHideToolBarButton').click();
// Open resource dropdown
cy.get('.dropdown-toggle').click()
// Download resource file
Expand All @@ -62,9 +68,8 @@ describe('Dataset', () => {
it('Download resource file', () => {
// Test download as anonymous user

cy.login();
cy.visit('/dataset/test-dataset-1')
// Hide flask debug toolbar
cy.get('#flDebugHideToolBarButton').click();
// Open resource dropdown
cy.get('.dropdown-toggle').click();
// Download resource file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
describe('Datastore', () => {

before(() => {
cy.login();
cy.create_token();
cy.logout();
cy.delete_organization('test-organization');
cy.create_organization('test-organization', 'Test organization');
})

beforeEach(() => {
Cypress.Cookies.preserveOnce('auth_tkt', 'ckan')
})

after(() => {
cy.delete_dataset('test-dataset-1')
cy.delete_organization('test-organization')
cy.revoke_token();
})

it('Is installed and available via CKAN API', () => {
cy.request('/api/3/action/datastore_search?resource_id=_table_metadata')
.should((response) => {
const token_data = Cypress.env('token_data');
cy.request({
method: 'GET',
url: '/api/3/action/datastore_search?resource_id=_table_metadata',
headers: {
'Authorization': token_data.api_token
}
}).should((response) => {
expect(response.body).to.have.property('success', true)
});
});

it('Can create datastore resource via API', () => {
const token_data = Cypress.env('token_data');
// First create dataset
cy.fixture('ckan_dataset.json').then((ckan_dataset) => {
cy.create_dataset(ckan_dataset).should((response) => {
cy.create_dataset(ckan_dataset).then((response) => {
expect(response.body).to.have.property('success', true)

// Create resource with datastore_create api
Expand All @@ -34,7 +39,8 @@ describe('Datastore', () => {
'url': '/api/3/action/datastore_create',
'headers': {
'cache-control': 'no-cache',
'content-type': 'application/json'
'content-type': 'application/json',
'Authorization': token_data.api_token
},
body: JSON.stringify({
"resource": {"package_id": response.body.result.id},
Expand All @@ -50,18 +56,38 @@ describe('Datastore', () => {
})

it('Can access datastore API', () => {
cy.request('/api/action/package_show?id=test-dataset-1').then((response) => {
const token_data = Cypress.env('token_data');
cy.request({
method: 'GET',
url: '/api/action/package_show?id=test-dataset-1',
headers: {
'Authorization': token_data.api_token
}
}).then((response) => {
expect(response.body).to.have.property('success', true);
const resource_id = response.body.result.resources[0].id;
cy.request(`/api/action/datastore_search?resource_id=${resource_id}`).should((response) => {
cy.request({
method: 'GET',
url: `/api/action/datastore_search?resource_id=${resource_id}`,
headers: {
'Authorization': token_data.api_token
}
}).should((response) => {
expect(response.body).to.have.property('success', true);
expect(response.body.result).to.have.property('total', 2);
});
})
})

it('Can delete datastore resource via API', () => {
cy.request('/api/action/package_show?id=test-dataset-1').then((response) => {
const token_data = Cypress.env('token_data');
cy.request({
method: 'GET',
url: '/api/action/package_show?id=test-dataset-1',
headers: {
'Authorization': token_data.api_token
}
}).then((response) => {
expect(response.body).to.have.property('success', true);
const resource_id = response.body.result.resources[0].id;
// delete resource with datastore_delete api
Expand All @@ -70,7 +96,8 @@ describe('Datastore', () => {
'url': '/api/3/action/datastore_delete',
'headers': {
'cache-control': 'no-cache',
'content-type': 'application/json'
'content-type': 'application/json',
'Authorization': token_data.api_token
},
body: JSON.stringify({
"resource_id": resource_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import 'cypress-file-upload';
describe('DCAT-US Export', () => {
const dataset_title = 'test-dataset-2';

before(() => {
cy.create_token();
});

beforeEach(() => {
cy.logout();
cy.login();
cy.delete_dataset('test-dataset-1');
cy.delete_dataset('test-dataset-2');
cy.delete_dataset('test-sub-dataset-1');
Expand Down Expand Up @@ -44,9 +47,14 @@ describe('DCAT-US Export', () => {
});
});
cy.exec('rm cypress/downloads/draft*', { failOnNonZeroExit: false });
cy.exec('rm cypress/downloads/redacted.zip', { failOnNonZeroExit: false });
cy.exec('rm cypress/downloads/data.json', { failOnNonZeroExit: false });

cy.login();
});

afterEach(() => {
after(() => {
cy.logout();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want logout afterEach?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should, but since we have cy.login() in beforeEach, and it does a cy.logout() implicitly, so no need to add the extra code.
If we ever remove cy.login() from beforeEach, i would come back and add cy.logout() into afterEach.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does a cy.logout() implicitly

aha. yeah that makes sense.

cy.delete_dataset('test-dataset-1');
cy.delete_dataset('test-dataset-2');
cy.delete_dataset('test-sub-dataset-1');
Expand All @@ -55,6 +63,9 @@ describe('DCAT-US Export', () => {
cy.delete_organization('test-organization');
cy.delete_organization('test-sub-organization');
cy.exec('rm cypress/downloads/draft*', { failOnNonZeroExit: false });
cy.exec('rm cypress/downloads/redacted.zip', { failOnNonZeroExit: false });
cy.exec('rm cypress/downloads/data.json', { failOnNonZeroExit: false });
cy.revoke_token();
});

it('Can create a zip export of the organization drafts', () => {
Expand Down
12 changes: 12 additions & 0 deletions e2e/cypress/integration/main_page.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
describe('Main Page', () => {

beforeEach(() => {
cy.login();
});

it('Load main page with configuration', () => {
cy.visit('/dataset');
cy.contains('Inventory');
});

})
Loading