-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_app.py
65 lines (52 loc) · 1.93 KB
/
test_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pytest
import xml.dom.minidom
import main
@pytest.fixture
def client():
main.app.config['TESTING'] = True
yield main.app.test_client()
def test_index(client):
'''Verify landing page.'''
rv = client.get('/')
assert 'CDLI Text Services' in rv.data.decode()
def test_nemo(client):
'''Verify nemo pages.'''
nemo = main.nemo.prefix
rv = client.get(nemo, follow_redirects=True)
text = rv.data.decode()
assert 'Nemo' in text
assert 'Text Collections' in text
urn = 'urn:cts:cdli:P497322'
page = 'default-collection-test-samples-converted-by-atf2cts'
text = client.get(f'{nemo}/collections/{urn}/{page}').data.decode()
assert 'CDLI Literary' in text
def cts_query(request, urn=None):
'''Generate a nautilus query url for the given parameters.'''
nautilus = main.nautilus.prefix
url = f'{nautilus}/cts?request={request}'
if urn:
url += f'&urn={urn}'
return url
def test_nautilus(client):
'''Verify nautilus api service.'''
rv = client.get(cts_query('GetCapabilities'))
dom = xml.dom.minidom.parseString(rv.data)
assert dom.documentElement.tagName == 'GetCapabilities'
textgroups = dom.getElementsByTagName('textgroup')
assert len(textgroups)
urns = [element.getAttribute('urn') for element in textgroups]
assert 'urn:cts:cdli:P464358' in urns
works = dom.getElementsByTagName('work')
urn = works[0].getAttribute('urn')
rv = client.get(cts_query('GetPassage', urn))
passage = xml.dom.minidom.parseString(rv.data)
assert passage.documentElement.tagName == 'GetPassage'
texts = passage.getElementsByTagName('text')
assert len(texts) == 1
bodies = texts[0].getElementsByTagName('body')
assert len(bodies) == 1
divs = bodies[0].getElementsByTagName('div')
assert len(divs) > 0
edition = divs[0]
assert edition.getAttribute('type') == 'edition'
assert edition.getAttribute('n').startswith(urn)