Skip to content

Commit

Permalink
Add tests: spectra type API
Browse files Browse the repository at this point in the history
  • Loading branch information
f-idiris committed Sep 22, 2023
1 parent 6f4e8d6 commit 8634fc6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/controller/test_spectra_type_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os
import json

test_json = './tests/fixtures/test_data_types.json'

def test_create_or_update_data_type(client):
new_data_type = {
"new_data_type": {
"MASS SPECTRUM": "MS"
}
}

response = client.post('/spectra_type_api/data_type', json=new_data_type)
assert response.status_code == 200

response_data = response.json()
assert response_data.get("datatypes") is not None
assert response_data["datatypes"].get("MASS SPECTRUM") == "MS"

def test_create_or_update_data_type_unchanged(client):
# data type already exists in JSON
new_data_type = {
"new_data_type": {
"INFRARED SPECTRUM": "INFRARED"
}
}

response = client.post('/spectra_type_api/data_type', json=new_data_type)
assert response.status_code == 400

response_data = response.json()

assert "message" in response_data
assert response_data["message"] == "Data type 'INFRARED SPECTRUM' already exists"

def test_create_or_update_data_type_file_not_found(client):
original_test_json = test_json
test_json = './tests/fixtures/non_existent_test_data.json'

new_data_type = {
"new_data_type": {
"RAMAN SPECTRUM": "RAMAN"
}
}

response = client.post('/spectra_type_api/data_type', json=new_data_type)
assert response.status_code == 200
response_data = response.json()
assert len(response_data.get("datatypes")) == 1
assert response_data["datatypes"].get("RAMAN SPECTRUM") == "RAMAN"

test_json = original_test_json
6 changes: 6 additions & 0 deletions tests/fixtures/test_data_types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"datatypes": {
"NMRSPECTRUM": "NMR",
"INFRARED SPECTRUM": "INFRARED"
}
}

0 comments on commit 8634fc6

Please sign in to comment.