Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mini test framework for demonstrators #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
.vagrant
# See http://docs.vagrantup.com/v2/other/environmental-variables.html VAGRANT_DOTFILE_PATH
.vagrant-ultra
scape-demos.sublime*
scape-demos.sublime*
# python bytecode
*.pyc
4 changes: 4 additions & 0 deletions StyleJS/jquery-1.11.1.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions flint/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link rel="stylesheet" href="/StyleJS/css/style.css">
<link rel="stylesheet" href="/flint/css/style.css">

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="/StyleJS/jquery-1.11.1.min.js"></script>
<script src="/StyleJS/ajax.js"></script>

<script>
Expand Down Expand Up @@ -78,7 +78,7 @@ <h1 class="sign-up-title">Demonstration of FLint - a modular File/Format
</div>

<div class="buttonHolder">
<input type="button" class="sign-up-button" onclick="ajax_request()" value="Lint the File">
<input type="button" id="lint-it" class="sign-up-button" onclick="ajax_request()" value="Lint the File">
</div>

<hr>
Expand Down
Binary file added flint/test-fixtures/509284.pdf
Binary file not shown.
13 changes: 13 additions & 0 deletions maven_settings.xml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- this is an example maven settings file to be used together with cntlm, as defined in
proxy_settings.conf, it uses the port number defined in that conf file -->
<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>127.0.0.1</host>
<port>3310</port>
</proxy>
</proxies>
</settings>

7 changes: 7 additions & 0 deletions provision/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ echo "install scape demo tools ..."
echo "deb http://dl.bintray.com/openplanets/opf-debian /" >> /etc/apt/sources.list
apt-get update

# For general proxy issues using vagrant, have a look at the vagrant proxy-conf
# plugin: https://tmatilai.github.io/vagrant-proxyconf/
# after an update (apt should work with the vagrant proxy plugin alrady), check for NTLM proxies
source /vagrant/provision/proxy_detection.sh

# Install apache 2, Python module, PHP 5 and java runtime 7 for demo site
apt-get install -y apache2 php5 libapache2-mod-php5 libapache2-mod-python openjdk-7-jre-headless

Expand Down Expand Up @@ -53,3 +58,5 @@ source /vagrant/provision/bootstrap_flint.sh
source /vagrant/provision/bootstrap_matchbox.sh

source /vagrant/provision/bootstrap_xcorrsound.sh

source /vagrant/provision/run_tests.sh
34 changes: 4 additions & 30 deletions provision/bootstrap_flint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,8 @@
###
# flint
###
FLINT_VERSION=flint-0.6.0
DPTUTILS_VERSION=dptutils-0.0.1


# in case you're behind a (e.g. nmlt) proxy, this is a way to have maven working
if [ -f /vagrant/proxy_settings.conf ]
then
echo "found proxy_settings, installing cntlm"
apt-get install -y cntlm
cp /vagrant/proxy_settings.conf /etc/cntlm.conf
service cntlm restart
fi


# Install maven
echo "installing maven.."
apt-get install -y maven
# create a maven dir, necessary for the next steps
if [ ! -d /home/vagrant/.m2 ]
then
mkdir /home/vagrant/.m2 && chown vagrant:vagrant /home/vagrant/.m2
fi
# check whether there's a maven settings file in /vagrant and link to it if so (in case of proxy settings, etc)
if [ -f /vagrant/maven_settings.xml ]
then
echo "found maven_settings, linking to them"
ln -s /vagrant/maven_settings.xml /home/vagrant/.m2/settings.xml
fi
FLINT_VERSION=flint-0.7.0
DPTUTILS_VERSION=dptutils-0.0.2


# Install jdk7 (for flint)
Expand Down Expand Up @@ -57,7 +31,7 @@ sudo -u vagrant git clone https://github.com/openplanets/flint.git
cd flint
sudo -u vagrant git checkout $FLINT_VERSION
# build the minimal set of modules
sudo -u vagrant mvn -pl .,flint-toolwrappers,flint-core,flint-pdf,flint-epub,flint-register,flint-cli clean install -DskipTests=true
sudo -u vagrant mvn -pl .,flint-toolwrappers,flint-core,flint-hadoop-api,flint-pdf,flint-epub,flint-register,flint-cli clean install -DskipTests=true
# remove the version bit from the flint-cli jar name
echo "[for flint] creating /home/vagrant/flint/flint.jar.."
sudo -u vagrant cp flint-cli/target/flint-cli-*-jar-with-dependencies.jar flint.jar
echo "[for flint] created /home/vagrant/flint/flint.jar"
28 changes: 28 additions & 0 deletions provision/proxy_detection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# In case you're behind a (e.g. nmlt) proxy, this is a way to have maven working.
# An example/template is available at /vagrant/proxy_settings.conf.example
if [ -f /vagrant/proxy_settings.conf ]
then
echo "found proxy_settings, installing cntlm"
apt-get install -y cntlm
cp /vagrant/proxy_settings.conf /etc/cntlm.conf
service cntlm restart
fi

# Install maven
echo "installing maven.."
apt-get install -y maven
# create a maven dir, necessary for the next steps
if [ ! -d /home/vagrant/.m2 ]
then
mkdir /home/vagrant/.m2 && chown vagrant:vagrant /home/vagrant/.m2
fi
# check whether there's a maven settings file in /vagrant and link to it if so (in case of proxy settings, etc)
# An example/template is available at /vagrant/maven_settings.xml.example
if [ -f /vagrant/maven_settings.xml ]
then
echo "found maven_settings, linking to them"
ln -s /vagrant/maven_settings.xml /home/vagrant/.m2/settings.xml
fi

21 changes: 21 additions & 0 deletions provision/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# we need a browser, as pagelyzer uses firefox this should do
sudo apt-get install -y firefox

# install xvfb, which contains xvfb-run
sudo apt-get install -y xvfb

# using python's nose test framework
sudo apt-get install -y python-nose

# pip is a package manager for python
sudo apt-get install -y python-pip

# install python's selenium bindings
pip install selenium

echo "==========================================================================================="
echo ""
echo "Running high-level blackbox tests.."

# running the selenium tests in a virtual framebuffer connecting to the standalone selenium server
xvfb-run --server-num=1 nosetests -v /vagrant/tests/*.py
22 changes: 22 additions & 0 deletions proxy_settings.conf.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This is an example config file for cntlm (http://cntlm.sourceforge.net/), change and remove the '.example' bit
# for more information read also http://stackoverflow.com/questions/9181637/how-to-fill-proxy-information-in-cntlm-config-file

Username <YOUR_USERNAME>
Domain <YOUR_DOMAIN>

Auth NTLM
Password <YOUR_PASSWORD>

Proxy <YOUR_PROXY>

# List addresses you do not want to pass to parent proxies
# * and ? wildcards can be used
#
NoProxy localhost, 127.0.0.*, 10.*, 192.168.*

# Specify the port cntlm will listen on
# You can bind cntlm to specific interface by specifying
# the appropriate IP address also in format <local_ip>:<local_port>
# Cntlm listens on 127.0.0.1:3128 by default
#
Listen 3310
Empty file added tests/__init__.py
Empty file.
55 changes: 55 additions & 0 deletions tests/flint_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/python

"""
This is a very simple silenium-driven black-box test, that on a given website
enters something in a form, clicks a button to submit this, waits long enough
to get results back, and checks that there are indeed results.
"""

import unittest

from selenium import webdriver

# the port is from the *inside* of the VM
SITE_URL = "http://localhost:80/flint/index.html"
TEST_FILE = "https://github.com/openplanets/format-corpus/raw/master/govdocs1-error-pdfs/error_set_2/050734.pdf"
# relevant html DOM IDs
TEXT_INPUT_ID = "flintValidateFromUrl"
SUBMIT_BUTTON_ID = "lint-it"
OUTPUT_ELEMENT_ID = "ul.output"


class TestFlint(unittest.TestCase):

def setUp(self):

# use the existing headless firefox
self.driver = webdriver.Firefox()


def test_flint_is_there(self):
# navigate to the site of the demonstrator
self.driver.get(SITE_URL)


# find the input element where we want to write the filepath to
input = self.driver.find_element_by_id(TEXT_INPUT_ID)

# write the path to the test file to the input element
input.send_keys(TEST_FILE)

# as this is an asynchronous call we want to give enough time (in seconds) to
# the background program to rund and to find what's being returned
self.driver.implicitly_wait(120)

# click the 'run' button
self.driver.find_element_by_id(SUBMIT_BUTTON_ID).click()

# find the ouptut element
output = self.driver.find_element_by_css_selector(OUTPUT_ELEMENT_ID)

self.assertTrue('CheckResult' in output.text,
msg="Can't find 'CheckResult' in html")
self.assertTrue('well-formed' in output.text,
msg="Can't find 'well-formed' category in check-result")