Commit fc3b1b46 authored by Pablo Panero's avatar Pablo Panero
Browse files

tests: refactor to compy with _data field

parent 4682f262
......@@ -22,11 +22,13 @@ def test_binary_es_ocr(endpoint, api_key):
"update": ["CernSearch-Administrators@cern.ch"],
"delete": ["CernSearch-Administrators@cern.ch"]
},
"title": "Test binary",
"description": "Test binary with ingest pipeline",
"link": "localhost/test",
"b64": "{binary_content}".format(binary_content=BINARY_CONTENT),
"$schema": "{endpoint}/schemas/test/binary_v0.0.1.json".format(
"_data": {
"title": "Test binary",
"description": "Test binary with ingest pipeline",
"link": "localhost/test",
"b64": "{binary_content}".format(binary_content=BINARY_CONTENT)
},
"$schema": "{endpoint}/schemas/test/binary_v0.0.2.json".format(
endpoint=endpoint
)
}
......@@ -39,12 +41,13 @@ def test_binary_es_ocr(endpoint, api_key):
# Check non presence of OCR content in DB record
resp_body = resp.json()['metadata']
assert resp_body.get('content') is None # Content is the target field in ES pipeline
assert resp_body.get('control_number') is not None
assert resp_body.get('title') == 'Test binary'
assert resp_body.get('description') == 'Test binary with ingest pipeline'
assert resp_body.get('link') == 'localhost/test'
assert resp_body.get('b64') == "{binary_content}".format(binary_content=BINARY_CONTENT)
resp_data = resp_body.get("_data")
assert resp_data.get('content') is None # Content is the target field in ES pipeline
assert resp_data.get('title') == 'Test binary'
assert resp_data.get('description') == 'Test binary with ingest pipeline'
assert resp_data.get('link') == 'localhost/test'
assert resp_data.get('b64') == "{binary_content}".format(binary_content=BINARY_CONTENT)
control_number = resp_body.get("control_number")
# Search record
......@@ -60,7 +63,7 @@ def test_binary_es_ocr(endpoint, api_key):
resp_hits = resp.json()['hits']
assert resp_hits.get('total') == 1
content = resp_hits['hits'][0]['metadata'].get('content')
content = resp_hits['hits'][0]['metadata'].get("_data").get('content')
assert content is not None
assert content.get('content') == "Lorem ipsum dolor sit amet"
assert content.get('content_type') == 'application/rtf'
......@@ -75,7 +78,7 @@ def test_binary_es_ocr(endpoint, api_key):
resp_hits = resp.json()['hits']
assert resp_hits.get('total') == 1
content = resp_hits['hits'][0]['metadata'].get('content')
content = resp_hits['hits'][0]['metadata'].get("_data").get('content')
assert content is not None
assert content.get('content') == "Lorem ipsum dolor sit amet"
assert content.get('content_type') == 'application/rtf'
......
......@@ -21,8 +21,10 @@ def test_control_number_update(endpoint, api_key):
"update": ["CernSearch-Administrators@cern.ch"],
"delete": ["CernSearch-Administrators@cern.ch"]
},
"title": "test_control_number_update",
"description": "Not updated document"
"_data": {
"title": "test_control_number_update",
"description": "Not updated document"
}
}
# Create test record
......@@ -34,7 +36,7 @@ def test_control_number_update(endpoint, api_key):
orig_record = resp.json()['metadata']
# Update without control_number
body['description'] = 'Update with no control number'
body["_data"]['description'] = 'Update with no control number'
resp = requests.put('{endpoint}/api/record/{control_number}'.format(
endpoint=endpoint,
control_number=orig_record['control_number']),
......@@ -44,10 +46,10 @@ def test_control_number_update(endpoint, api_key):
assert resp.status_code == 200
assert put_record.get('control_number') is not None
assert put_record.get('control_number') == orig_record['control_number']
assert put_record['description'] == body['description']
assert put_record["_data"]['description'] == body["_data"]['description']
# Update with a wrong control_number
body['description'] = 'Update with wrong control number'
body["_data"]['description'] = 'Update with wrong control number'
resp = requests.put('{endpoint}/api/record/{control_number}'.format(
endpoint=endpoint,
control_number=orig_record['control_number']),
......@@ -57,7 +59,7 @@ def test_control_number_update(endpoint, api_key):
assert resp.status_code == 200
assert put_record.get('control_number') is not None
assert put_record.get('control_number') == orig_record['control_number']
assert put_record['description'] == body['description']
assert put_record["_data"]['description'] == body["_data"]['description']
# Delete test record
resp = requests.delete('{endpoint}/api/record/{control_number}'.format(
......@@ -75,14 +77,16 @@ def test_access_fields_existence(endpoint, api_key):
# POST and PUT should follow the same workflow. Only checking POST.
# Without _access field
body = {
"title": "test_access_fields_existence",
"description": "No _access field"
"_data": {
"title": "test_access_fields_existence",
"description": "No _access field"
}
}
resp = requests.post('{endpoint}/api/records/'.format(endpoint=endpoint),
headers=HEADERS, data=json.dumps(body))
assert resp.status_code == 400
assert {"field": "_schema", "message": "Missing field _access."} in resp.json()['errors']
assert {"field": "_schema", "message": "Missing field _access"} in resp.json()['errors']
# Without _access.delete field
body = {
......@@ -90,8 +94,10 @@ def test_access_fields_existence(endpoint, api_key):
"owner": ["CernSearch-Administrators@cern.ch"],
"update": ["CernSearch-Administrators@cern.ch"]
},
"title": "test_access_fields_existence",
"description": "No _access.delete field"
"_data": {
"title": "test_access_fields_existence",
"description": "No _access.delete field"
}
}
resp = requests.post('{endpoint}/api/records/'.format(endpoint=endpoint),
headers=HEADERS, data=json.dumps(body))
......@@ -105,8 +111,10 @@ def test_access_fields_existence(endpoint, api_key):
"owner": ["CernSearch-Administrators@cern.ch"],
"delete": ["CernSearch-Administrators@cern.ch"]
},
"title": "test_access_fields_existence",
"description": "No _access.update field"
"_data": {
"title": "test_access_fields_existence",
"description": "No _access.update field"
}
}
resp = requests.post('{endpoint}/api/records/'.format(endpoint=endpoint),
headers=HEADERS, data=json.dumps(body))
......
......@@ -11,7 +11,11 @@ HEADERS = {
@pytest.mark.unit
def test_default_search_field(endpoint, api_key):
def test_search(endpoint, api_key):
"""
Test search over public documents. Test that the ``_access.*`` field is
not searched over.
"""
HEADERS['Authorization'] = 'Bearer {credentials}'.format(credentials=api_key)
body = {
......@@ -20,9 +24,11 @@ def test_default_search_field(endpoint, api_key):
"update": ["CernSearch-Administrators@cern.ch"],
"delete": ["CernSearch-Administrators@cern.ch"]
},
"title": "Test default search field",
"description": "This contains CernSearch and should appear",
"$schema": "{endpoint}/schemas/test/doc_v0.0.1.json".format(
"_data": {
"title": "Test default search field",
"description": "This contains CernSearch and should appear"
},
"$schema": "{endpoint}/schemas/test/doc_v0.0.2.json".format(
endpoint=endpoint
)
}
......@@ -36,13 +42,14 @@ def test_default_search_field(endpoint, api_key):
# Check non presence of OCR content in DB record
resp_body = resp.json()['metadata']
assert resp_body.get('control_number') is not None
assert resp_body.get('title') == 'Test default search field'
assert resp_body.get('description') == 'This contains CernSearch and should appear'
resp_data = resp_body.get("_data")
assert resp_data.get('title') == 'Test default search field'
assert resp_data.get('description') == 'This contains CernSearch and should appear'
control_number_one = resp_body.get("control_number")
# Create second test record
body['description'] = 'This does not contains the magic word and should not appear'
body["_data"]['description'] = 'This does not contains the magic word and should not appear'
# Create test record
resp = requests.post('{endpoint}/api/records/'.format(endpoint=endpoint),
......@@ -53,8 +60,9 @@ def test_default_search_field(endpoint, api_key):
# Check non presence of OCR content in DB record
resp_body = resp.json()['metadata']
assert resp_body.get('control_number') is not None
assert resp_body.get('title') == 'Test default search field'
assert resp_body.get('description') == 'This does not contains the magic word and should not appear'
resp_data = resp_body.get("_data")
assert resp_data.get('title') == 'Test default search field'
assert resp_data.get('description') == 'This does not contains the magic word and should not appear'
control_number_two = resp_body.get("control_number")
......@@ -80,7 +88,7 @@ def test_default_search_field(endpoint, api_key):
resp_hits = resp.json()['hits']
assert resp_hits.get('total') == 1
description = resp_hits['hits'][0]['metadata'].get('description')
description = resp_hits['hits'][0]['metadata'].get("_data").get('description')
assert description is not None
assert description == 'This contains CernSearch and should appear'
......
......@@ -3,7 +3,7 @@ import requests
@pytest.mark.unit
def test_default_search_field(endpoint, api_key):
def test_ui(endpoint, api_key):
# Check the UI does not generate 50X Errors
resp = requests.post('{endpoint}/account/settings/applications/'.format(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment