Skip to content

geosolutions-it/geonode-cypress

Repository files navigation

UI Tests

This test suite contains UI-tests for the "GeoNode 4.4.x". The "advanced workflow" of GeoNode is covered by these tests, too. It's possible to run the tests with no advanced workflow then several tests will fail. It uses Cypress.io as testing framework and Mocha Awesome for report generation.

Setup

$ sudo apt update && sudo apt upgrade --yes
$ sudo apt install npm --yes
$ npm install
Create the .env file (important)

Test execution

Web GUI (for debugging):

$ npm run web

Headless Test only:

$ npm run test

Create Report only:

$ npm run report

Headless Test and Report:

$ npm run test-and-report

Test Report

Path of the Report HTML: ./reports
Path of the Report JSON: ./results
Path of the Test Screenshots: ./cypress/screenshots

Fill GeoNode with Testdata

Setup

$ sudo apt update && sudo apt upgrade --yes
$ sudo apt install python3 --yes
Create the .env file (important)

Upload Datasets

$ python3 ./functions/python/upload.py --iterations <int> --datasetsize medium
--iterations How many Datasets should be uploaded, int >= 0
--datasetsize Size of the Dataset that should be uploaded small|medium|large

Delete all Datasets

$ python3 ./functions/python/upload.py
This will delete all Datasets with prefixes python_|cypress_|Suuushi
This process might take a while... \

Python Script API Flow

upload.py

1. Get Auth-Token:      GET     {baseURL}/account/login/
2. Upload Dataset:      POST    {baseURL}/api/v2/uploads/upload
3. Wait for execID:     GET     {baseURL}/api/v2/executionrequest/{execID}

delete.py

1. Get Auth-Token:      GET     {baseURL}/account/login/
2. Get Dataset-List:    GET     {baseURL}/api/v2/resources?page_size={pagesize}
3. Delete Dataset:      DELETE  {baseURL}/api/v2/resources/{pk}/delete
4. Get execID:          GET     {baseURL}/api/v2/executionrequest
5. Wait for execID:     GET     {baseURL}/api/v2/executionrequest/{execID}

requester.py

<no api calls>

filemanager.py

<no api calls>

GeoNode API Doc

Tipps and Tricks

  1. Use the Edge Dev Tools Network Log to get an idea of the API Calls
  2. Use Postman to reproduce the API Calls
  3. Postman can generate Code for all Programming Languages

1. Get Session ID, needed for login request

Request

GET {baseURL}/account/login/

Response

HTTP Code: 200
Cookies: sessionid, csrftoken

Example

import requests

url = "http://localhost/account/login/"

payload = {}
headers = {}

response = requests.request("GET", url, headers=headers, data=payload)

csrftoken = response.cookies.get('csrftoken', None)
sessionid = response.cookies.get('sessionid', None)

2. Login using GeoNode Credentials

Request

You need the sessionid, csrftoken from step 1

POST {baseURL}/account/login/

Headers: 
Cookie: sessionid={sessionid}, csrftoken={csrftoken}

Body (form-data):
login = {username}
password = {password}
csrfmiddlewaretoken = {csrftoken}

Response

HTTP Code 302, 200 (Redirect)

302:
Cookie: csrftoken

200:
Cookie: sessionid

Example

import requests

url = "http://localhost/account/login/"

payload = {
    'csrfmiddlewaretoken': {csrftoken},
    'login': {username},
    'password': {password},
}
headers = {
    'Cookie': f'csrftoken={csrftoken};',
    'Content-Type': 'application/x-www-form-urlencoded'
}

response = requests.request("POST", url, headers=headers, data=payload)

csrftoken = response.cookies.get('csrftoken', None)
sessionid = response.cookies.get('sessionid', None)

if sessionid is None:
    sessionid = response.history[0].cookies.get('sessionid', None)

3. Get all Datasets

Request

GET {baseURL}/api/v2/resources?page_size={pagesize}

Headers:
Cookies: csrftoken={csrfToken}; sessionid={sessionid}
x-csrftoken: {csrfToken}

Payload:
charset: 'UTF-8',
store_spatial_files: 'true'

Response

HTTP Code: 200
JSON

Example

see delete.py

About

No description, website, or topics provided.

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors