This repository has been archived by the owner on Dec 7, 2020. It is now read-only.
/
test_example_app.py
78 lines (63 loc) · 2.44 KB
/
test_example_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
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2016-2018 CERN.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
"""Test example app."""
import os
import signal
import subprocess
import sys
import time
import pkg_resources
EXAMPLE_APP_DIR = os.path.join(os.path.split(sys.path[0])[0], 'examples')
def setup_module():
"""Set up before all tests."""
# switch to examples/app.py
os.chdir(EXAMPLE_APP_DIR)
def teardown_module():
"""Tear down after all tests."""
for cmd in ['FLASK_APP=app.py flask db destroy --yes-i-know',
'rm -rf instance']:
exit_status = subprocess.call(cmd, shell=True)
assert exit_status == 0
def test_example_app():
"""Test example app."""
source = pkg_resources.resource_filename('invenio_records',
'data/marc21/bibliographic.xml')
# Testing database creation
for cmd in ['mkdir -p instance',
'pip install -r requirements.txt',
'FLASK_APP=app.py flask db init',
'FLASK_APP=app.py flask db create']:
exit_status = subprocess.call(cmd, shell=True)
assert exit_status == 0
# Testing record creation
cmd = """dojson -i {0} -l marcxml do marc21 | FLASK_APP=app.py \
flask records create --pid-minter recid""".format(
source
)
exit_status = subprocess.call(cmd, shell=True)
assert exit_status == 0
# Download javascript and css libraries
for cmd in ['FLASK_APP=app.py flask npm',
'cd static && npm install && cd ..',
'npm install -g node-sass@3.8.0 clean-css@3.4.12'
' requirejs uglify-js',
'FLASK_APP=app.py flask collect -v',
'FLASK_APP=app.py flask assets build']:
exit_status = subprocess.call(cmd, shell=True)
assert exit_status == 0
# Starting example web app
cmd = 'FLASK_APP=app.py flask run'
webapp = subprocess.Popen(cmd, stdout=subprocess.PIPE,
preexec_fn=os.setsid, shell=True)
time.sleep(10)
# Testing record retrieval via web
cmd = 'curl http://127.0.0.1:5000/example/1'
output = subprocess.check_output(cmd, shell=True)
assert 'Candidate of Higgs boson production' in str(output)
# Stopping example web app
os.killpg(webapp.pid, signal.SIGTERM)