Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: addition of test_examples_app.py
* Adds test_examples_app.py. (closes #37) Signed-off-by: Leonardo Rossi <leonardo.r@cern.ch>
- Loading branch information
Leonardo Rossi
committed
Oct 12, 2016
1 parent
54b7252
commit 53e71ab
Showing
8 changed files
with
195 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
|
||
# quit on errors: | ||
set -o errexit | ||
|
||
# quit on unbound symbols: | ||
set -o nounset | ||
|
||
DIR=`dirname "$0"` | ||
|
||
cd $DIR | ||
export FLASK_APP=app.py | ||
|
||
# Load fixtures | ||
flask fixtures pages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
|
||
# quit on errors: | ||
set -o errexit | ||
|
||
# quit on unbound symbols: | ||
set -o nounset | ||
|
||
DIR=`dirname "$0"` | ||
|
||
cd $DIR | ||
export FLASK_APP=app.py | ||
|
||
# Create the database | ||
flask db init | ||
flask db create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
|
||
DIR=`dirname "$0"` | ||
|
||
cd $DIR | ||
export FLASK_APP=app.py | ||
|
||
# Clean the database | ||
flask db drop --yes-i-know |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{# | ||
# This file is part of Invenio. | ||
# Copyright (C) 2014, 2015, 2016 CERN. | ||
# | ||
# Invenio is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License as | ||
# published by the Free Software Foundation; either version 2 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Invenio is distributed in the hope that it will be useful, but | ||
# WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Invenio; if not, write to the Free Software Foundation, Inc., | ||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | ||
#} | ||
{% extends config.PAGES_BASE_TEMPLATE %} | ||
|
||
{% set title = page.title %} | ||
|
||
{% block page_body %} | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-xs-12"> | ||
{% block content %}{{ page.content|safe }}{% endblock %} | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of Invenio. | ||
# Copyright (C) 2016 CERN. | ||
# | ||
# Invenio is free software; you can redistribute it | ||
# and/or modify it under the terms of the GNU General Public License as | ||
# published by the Free Software Foundation; either version 2 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Invenio is distributed in the hope that it will be | ||
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Invenio; if not, write to the | ||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
# MA 02111-1307, USA. | ||
# | ||
# In applying this license, CERN does not | ||
# waive the privileges and immunities granted to it by virtue of its status | ||
# as an Intergovernmental Organization or submit itself to any jurisdiction. | ||
|
||
"""Test example app.""" | ||
|
||
import os | ||
import signal | ||
import subprocess | ||
import time | ||
|
||
import pytest | ||
|
||
|
||
@pytest.yield_fixture | ||
def example_app(): | ||
"""Example app fixture.""" | ||
current_dir = os.getcwd() | ||
# go to example directory | ||
project_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
exampleappdir = os.path.join(project_dir, 'examples') | ||
os.chdir(exampleappdir) | ||
# setup example | ||
cmd = './app-setup.sh' | ||
exit_status = subprocess.call(cmd, shell=True) | ||
assert exit_status == 0 | ||
# Starting example web app | ||
cmd = 'FLASK_APP=app.py flask run --debugger -p 5000 -h 0.0.0.0' | ||
webapp = subprocess.Popen(cmd, stdout=subprocess.PIPE, | ||
preexec_fn=os.setsid, shell=True) | ||
time.sleep(10) | ||
# return webapp | ||
yield webapp | ||
# stop server | ||
os.killpg(webapp.pid, signal.SIGTERM) | ||
# tear down example app | ||
cmd = './app-teardown.sh' | ||
subprocess.call(cmd, shell=True) | ||
# return to the original directory | ||
os.chdir(current_dir) | ||
|
||
|
||
def test_example_app(example_app): | ||
"""Test example app.""" | ||
# load fixtures | ||
cmd = './app-fixtures.sh' | ||
exit_status = subprocess.call(cmd, shell=True) | ||
assert exit_status == 0 | ||
time.sleep(10) | ||
# open page | ||
cmd = 'curl http://0.0.0.0:5000/example1' | ||
output = subprocess.check_output(cmd, shell=True).decode('utf-8') | ||
assert 'hello default page' in output | ||
cmd = 'curl http://0.0.0.0:5000/example2' | ||
output = subprocess.check_output(cmd, shell=True).decode('utf-8') | ||
assert 'hello my page' in output |