Commit 00409f51 authored by Magnus Westergaard's avatar Magnus Westergaard
Browse files

DEICH-5545: Remove old koha tests.

parent 4d2d7c1e
......@@ -34,7 +34,7 @@ Stop any running containers and run the following command:
Our autocompleting input component for authorized values in Fuge seems to trigger a SEGFAULT in Cypress' built-in Electron browser when run in headless mode. If there is more than one option in the dropdown and typed input causes some options to be eliminated (e.g. "mus" is typed in the work type field, causing the option "Litteratur" to be eliminated from the dropdown list), the test runner crashes due to a SIGSEGV signal.
This issue did not exist with Cypress 4.x, but is currently an issue with Cypress 6.3.0, which uses an Electron browser based on Chromium 87. As a result, the tests require Chromium or Google Chrome installed to run headlessly for now.
This issue did not exist with Cypress 4.x, but is currently an issue with Cypress 6.4.0, which uses an Electron browser based on Chromium 87. As a result, the tests require Chromium or Google Chrome installed to run headlessly for now.
Note: the tests run fine in the Electron browser when not in headless mode (`npx cypress open`).
......
......@@ -19,7 +19,7 @@ describe("Koha API - patron validate pin and password", () => {
})
})
// FIXME doesn't work as expected
// FIXME doesn't work as expected, borrower has no pin code set
it.skip("can detect a valid pin code", () => {
cy.request("POST",
`${Cypress.env("KOHA_API_URL")}/validatepin`,
......
......@@ -44,7 +44,7 @@ Cypress.Commands.add("loginKohaAdmin", () => {
})
})
// FIXME: can this be a regular V borrower? REGVOKSEN is a temporary state
// TODO: rewrite to use the proper endpoints for self registration in koha (REGVOKSEN is a temp state and the borrower has no pin code)
Cypress.Commands.add("addSelfRegisterPatron", (withSsn = false) => {
cy.fixture("koha/selfregister_v.json").then((json) => {
cy.request("POST", `${Cypress.env("KOHA_API_URL")}/patrons`, json)
......
......@@ -13,27 +13,6 @@
name: test
url: https://deichman.test.obib.no
#Automated tests
koha-api-tests:
stage: sanity
extends:
- .devtest
variables:
DEVTEST_KOHA_DB: "koha-db"
DEVTEST_KOHA_API: "${DEVTEST_KOHA_API}"
#CMD: "'mysql -u $MYSQL_USER -p$MYSQL_PASSWORD koha_deichman' < /opt/deichman/deployment-config/koha/fixtures/cleanup.sql"
APPLICATION_NAME: koha
only:
changes: [ "Makefile", ".gitlab-ci.yml", "gitlab-ci/deploy/test.yml", "gitlab-ci/deploy-jobs.yml", "*.sh", "koha/**/*"]
tags:
- koha
#before_script: # ensure clean slate
# - make remote-docker-command ssh_user=${SSH_USER} ssh_server="${SSH_SERVERS}" CONTAINER=${DEVTEST_KOHA_DB} cmd="${cmd}"
script:
- cd koha/tests
#- ./run_tests.sh
when: on_success
deploy-scheduled-test:
extends:
- .testdeploy
......
......@@ -741,6 +741,7 @@ resource patrons => sub {
};
};
# TODO: is this endpoint used anymore (except for tests)? no traces in graylog, no authentication required
summary "Add a patron";
params(
requires("branchcode", type => Str, desc => "Patron homebranch"),
......
......@@ -16,6 +16,7 @@ use Deichman::Exception;
desc "Norwegian patron DB operations";
resource norwegianpatrondb => sub {
# TODO: is this endpoint used anymore? check if all clients use api/patrons/checkexisting
resource checkforexistinguser => sub {
params(
requires("ssn", type => Int, desc => "Patron social security number"),
......
*.dump
*results*
.pytest_cache
__pycache__
---
# Common setup stages accessible in all tests
name: API patron operations
description: Create session, biblio, items
stages:
- id: addSuperuser
name: Add Superuser
request:
method: POST
url: "{api}/patrons"
headers:
Content-Type: application/json
json:
surname: "Test Surname"
firstname: "Test Firstname"
userid: "{superUserCardNumber}"
cardnumber: "{superUserCardNumber}"
branchcode: "hutl"
categorycode: "V"
address: "TESTADDRESS"
zipcode: 1234
city: "TESTCITY"
email: "verylonganduselessemail@testemail.urk"
mobile: "98712345"
dateofbirth: "1980-01-01"
password: "{superUserPassword}"
pin: "{superUserPIN}"
sex: "F"
borrowernotes: "TESTPATRON001"
flags: 1
response:
status_code: 201
json:
surname: "Test Surname"
userid: "{superUserCardNumber}"
save:
json:
superUser: borrowernumber
- id: loginAdmin
name: Add admin Session
request:
method: POST
url: "{api}/auth/session"
headers:
Content-Type: application/json
json:
userid: "{superUserCardNumber}"
password: "{superUserPassword}"
response:
status_code: 201
cookies:
- koha.session
save:
header:
adminCookie: "Set-Cookie"
- id: addApiKey
name: Add api key
request:
method: POST
url: "{api}/apikey"
headers:
Content-Type: application/json
json:
description: "TEST APIKEY"
response:
status_code: 200
json:
description: "TEST APIKEY"
save:
json:
apiKey: token
- id: addBiblio
name: Add biblio
request:
method: POST
url: "{api}/biblio"
file_body: /tests/fixtures/biblio.xml
headers:
Content-Type: application/xml
response:
status_code: 201
headers:
location: !anystr
save:
json:
biblioNumber: biblionumber
- id: addItem
name: Add Item
request:
method: POST
url: "{api}/items"
json:
barcode: "{barcode}"
biblionumber: "{biblioNumber}"
homebranch: "bjor"
holdingbranch: "bjor"
itemnotes: "TESTITEM001"
headers:
Content-Type: application/json
response:
status_code: 201
strict: False
json:
item:
barcode: "{barcode}"
biblionumber: !int "{biblioNumber:d}"
homebranch: "bjor"
holdingbranch: "bjor"
itemnotes: "TESTITEM001"
location:
lives: "bjor"
save:
json:
itemNumber: item.itemnumber
- id: createSelfRegisterPatron
name: Create Self-register patron
request:
method: POST
url: "{api}/patrons"
headers:
Content-Type: application/json
json:
categorycode: "REGVOKSEN"
surname: "Test Self-register surname"
firstname: "Test Self-register firstname"
userid: "{selfRegCardNumber}"
branchcode: "hutl"
address: "TESTADDRESS"
zipcode: 1234
city: "TESTCITY"
email: "testmail_selfreg@testmail.no"
mobile: "99887766"
dateofbirth: "1990-12-24"
password: "{selfRegPassword}"
pin: "{selfRegPIN}"
borrowernotes: "TESTPATRON002"
sex: "M"
response:
status_code: 201
save:
json:
selfRegBorrowerNumber: borrowernumber
selfRegCardNumber: cardnumber
json:
borrowernumber: !anyint # was !anystr
surname: "Test Self-register surname"
- id: loginSelfRegisterPatron
name: Login and create session for Self-register patron
name: Add Session
request:
method: POST
url: "{api}/auth/session"
headers:
Content-Type: application/json
json:
userid: "{selfRegCardNumber}"
password: "{selfRegPassword}"
response:
status_code: 201
cookies:
- koha.session
save:
$ext:
function: helpers.utils:saveCookie
extra_kwargs:
selfRegCookie: "set-cookie"
- id: selfRegMessagePrefs
name: PUT selfreg patron messagepreferences
request:
method: PUT
url: "{api}/messagepreferences/{selfRegBorrowerNumber}"
headers:
Content-Type: application/json
json:
advance_notice:
days_in_advance: 2
transports:
- email
- sms
wants_digest: True
hold_filled:
transports:
- email
- sms
item_checkout:
transports: []
item_check_in:
transports: []
response:
status_code: 200
json:
Advance_Notice:
- !anydict
Hold_Filled:
- !anydict
- id: selfRegSyncDefaults
name: PUT selfreg patron syncdefaults
request:
method: PUT
url: "{api}/norwegianpatrondb/{selfRegBorrowerNumber}"
headers:
Content-Type: application/json
json:
borrowernumber: "{selfRegBorrowerNumber}"
ssn: "{selfRegSSN}"
password: "{selfRegPassword}"
response:
status_code: 200
# TODO: approving self registered user is now a totally new set of actions
- id: approveSelfRegUser
name: Approve a self registered user
request:
method: PUT
url: "{api}/patrons/{selfRegBorrowerNumber}"
headers:
Content-Type: application/json
json:
categorycode: "V"
response:
status_code: 200
\ No newline at end of file
---
name: teardown stages
description: stages to clean up
stages:
- id: deleteApiKey
name: Delete api keys
request:
method: DELETE
url: "{api}/apikey/{apiKey:s}"
headers:
Authorization: "Bearer {apiKey:s}"
response:
status_code: 200
- id: deleteSuperuser
name: Delete superuser
request:
method: DELETE
url: "{api}/patrons/{superUser}"
response:
status_code: 200
- id: deleteSelfRegisterPatron
name: DELETE Self-register patron
request:
method: DELETE
url: "{api}/patrons/{selfRegBorrowerNumber}"
response:
status_code: 200
# Delete item, need to remove barcode first
- id: undefBarcode
name: Undef Barcode
request:
method: PUT
url: "{api}/items/{itemNumber}"
headers:
Content-Type: application/json
json:
barcode: null
response:
status_code: 200
json: []
- id: deleteItem
name: Delete Item
request:
method: DELETE
url: "{api}/items/{itemNumber}"
response:
status_code: 200
- id: deleteBiblio
name: Delete Biblio
request:
method: DELETE
url: "{api}/biblio/{biblioNumber}"
response:
status_code: 200
- id: deleteSession
name: Delete Session
request:
method: DELETE
url: "{api}/patrons/{superUser}"
response:
status_code: 200
FROM alpine
ENV PATH=${PATH}:/usr/local/bin:/ \
TAG=v0.26.0 \
LANG=C.UTF-8 \
KOHA_API=http://koha:8081/api
RUN apk add --no-cache curl
RUN curl -L https://github.com/ovh/venom/releases/download/${TAG}/venom.linux-amd64 -o /venom && chmod +x /venom
COPY . /tests
CMD cat /tests/*.yml > all.yaml && venom run all.yaml
# tavern Dockerfile
FROM python:3.8-alpine
ENV PYTHONPATH /tests
RUN pip3 install tavern
CMD ["python", \
"-m", "pytest", \
"/tests"]
# README.md
Koha quick-n-dirty integration tests.
Uses `tavern` integration test tools with http executors (https://tavern.readthedocs.io/en/latest/)
Simple descriptions of api calls to test and verify for regression.
Koha API Swagger specs:
```curl intra.localhost/api/swagger```
## Prerequisites
Running
* koha
* koha-mysql
* elasticsearch (since biblios and items require indexing)
* nlsink (to respond ok on NL patron lookup)
Run tavern in same docker network as Koha
## Setup
Build docker image
```
docker build -f Dockerfile.tavern -t tavern .
```
Test config in `conftest.py`
## Run
```
./run_tests.sh
```
## Writing Tests
* One test = One Yaml file `test_xxx.tavern.yaml`
* setup and teardown stages (repeated steps) are placed in `000-setup-stages.yaml` and `999-teardown-stages.yaml`. Referenced by id and `type: ref`
* global vars in `common.yaml`
* DB cleanups in `fixtures/cleanup.sql`
* response objects can be tested for `json` or `header`
* on validating response objects (dicts) order must be sorted, arrays (lists) must include **all** items or **any** (but in correct expected order)
* ignore tests with either `marks: - skip` in header or `skip: True` in test
* more advanced tests can be added in python defs inside `helpers` dir. Accessed with `$ext: functions: helpers.utils:method` args in `extra_kwords`
TODO.md
/picklist GET
/picklist/notfound/{id} PUT
/auth/overdrive POST
/loanhistory/{borrowernumber}/id/{id} DELETE
/loanhistory/{borrowernumber} DELETE GET
/payments PUT POST
/payments/callback POST
/messaging/{borrowernumber}/payment-receipt PUT
/ill/availability/{biblionumber} GET
/ill/request/list GET
/ill/request POST
/loans/{issue_id} GET PUT
/item/alarmtriggered/{id} POST
/item/setstatus/{id} POST
/item/status/{id} GET
/items/{itemnumber} GET
/items/{itemnumber}/IPP PUT
/item/labelgenerator/{barcode} GET
/loansandreservations/{borrowernumber} GET
/biblio/{biblionumber}/expanded GET
/biblio/{biblionumber}/items GET
/biblio/{biblionumber} PUT DELETE GET
/patron/dataaccessrequest/{borrowernumber} GET
/reports/expiredholds/{branchcode} GET
/reports/canceledholds/{branchcode} GET
/patrons/{borrowernumber}/extended GET
---
name: test common includes
description: used for testing against local server
variables:
barcode: "09123123451234"
ssn: "12345612345"
api: "http://koha:8081/api"
superUserCardNumber: "TESTSUPERUSER001"
superUserPassword: "password0000"
superUserPIN: "0000"
selfRegCardNumber: "TESTSELFREG001"
selfRegPassword: "password1234"
selfRegPIN: "1234"
selfRegSSN: "12345612346"
pickupNumber: "123"
import os
import tempfile
import logging
import yaml
#import colorlog
import pytest
# with open("/tests/log_spec.yaml", "r") as log_spec_file:
# config.dictConfig(yaml.load(log_spec_file))
@pytest.fixture(scope="function", autouse=True)
def run_all():
current_dir = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(current_dir, "log_spec.yaml"), "r") as spec_file:
settings = yaml.safe_load(spec_file)
logging.config.dictConfig(settings)
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<record
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"
xmlns="http://www.loc.gov/MARC21/slim">
<leader>00631cam a22002291 4500</leader>
<controlfield tag="001">626460</controlfield>
<controlfield tag="008">040823 a 10nob 2</controlfield>
<datafield tag="015" ind1=" " ind2=" ">
<subfield code="a">0147191</subfield>
<subfield code="b">BIBBI</subfield>
</datafield>
<datafield tag="015" ind1=" " ind2=" ">
<subfield code="a">832303</subfield>
<subfield code="b">BibliofilID</subfield>
</datafield>
<datafield tag="019" ind1=" " ind2=" ">
<subfield code="b">l</subfield>
<subfield code="d">R</subfield>
</datafield>
<datafield tag="020" ind1=" " ind2=" ">
<subfield code="a">8249502728</subfield>
<subfield code="b">ib.</subfield>
<subfield code="c">Nkr 348.00</subfield>
</datafield>
<datafield tag="090" ind1=" " ind2=" ">
<subfield code="d">Rag</subfield>
</datafield>
<datafield tag="100" ind1=" " ind2="0">
<subfield code="a">Ragde, Anne B.</subfield>
<subfield code="c">forfatter</subfield>
<subfield code="d">1957-</subfield>
<subfield code="j">n.</subfield>
<subfield code="3">10834700</subfield>
</datafield>
<datafield tag="245" ind1="1" ind2="0">
<subfield code="a">Berlinerpoplene</subfield>
<subfield code="b">roman</subfield>
<subfield code="c">Anne Birkefeldt Ragde</subfield>
</datafield>
<datafield tag="260" ind1=" " ind2=" ">
<subfield code="a">Oslo</subfield>
<subfield code="b">Oktober</subfield>
<subfield code="c">2004</subfield>
</datafield>
<datafield tag="300" ind1=" " ind2=" ">
<subfield code="a">313 s.</subfield>
</datafield>
<datafield tag="503" ind1=" " ind2=" ">
<subfield code="a">Forts. i: Eremittkrepsene</subfield>
</datafield>
<datafield tag="599" ind1=" " ind2=" ">
<subfield code="a">04x0823kh a04-14</subfield>
</datafield>
<datafield tag="699" ind1=" " ind2="2">
<subfield code="a">Familieforhold</subfield>
<subfield code="x">Fortellinger</subfield>
<subfield code="1">306.87</subfield>
<subfield code="2">BS</subfield>
</datafield>
<datafield tag="850" ind1=" " ind2=" ">
<subfield code="a">DEICHM</subfield>
<subfield code="s">n</subfield>
</datafield>
<datafield tag="942" ind1=" " ind2=" ">
<subfield code="c">L</subfield>
</datafield>
</record>
DELETE iss FROM issues iss JOIN borrowers USING(borrowernumber) WHERE note LIKE 'TEST%' OR borrowernotes LIKE 'TEST%' OR cardnumber LIKE 'TEST%';
DELETE oi FROM old_issues oi WHERE note LIKE 'TEST%';
DELETE res FROM reserves res JOIN borrowers USING(borrowernumber) WHERE reservenotes LIKE 'TEST%' OR borrowernotes LIKE 'TEST%' OR cardnumber LIKE 'TEST%';
DELETE oldr FROM old_reserves oldr WHERE reservenotes LIKE 'TEST%';
DELETE i FROM items i WHERE itemnotes LIKE 'TEST%';
DELETE b FROM biblio b WHERE notes LIKE 'TEST%';
DELETE b FROM borrowers b WHERE cardnumber like 'TEST%' OR borrowernotes LIKE 'TEST%';
{
"advance_notice": {
"days_in_advance": 2,
"transports": ["email", "sms"],
"wants_digest": true