Commit 4054e5af by Bruno Bzeznik

More tests... and attempt to fake auth

Simple tests are working, but tables from async queries are not testable
because of the 2 steps auth. We need to find a way to authenticate more
permanently so every url is testable.

So, tried to implement REMOTE_USER auth into Django, but does not
seem to work...
parent 9f15cc43
......@@ -60,7 +60,7 @@
extraConfig = ''
ProxyPassReverse / http://localhost:8888/
RewriteEngine on
RewriteRule ^/\.well-known/?(.*)$ http://data.phylodev.org/static/%{REQUEST_URI} [L,P]
RewriteRule ^/static/?(.*)$ - [L,P]
......
......@@ -11,6 +11,10 @@ echo 'GDAL_LIBRARY_PATH = "/run/current-system/sw/lib/libgdal.so"' >> $PHYLODB_D
# Disable CSRF cookie as we will use non-secure http
perl -pi -e "s/CSRF_COOKIE_SECURE.*=.*/CSRF_COOKIE_SECURE = False/" $PHYLODB_DIR/phylodb/settings.py
# For the fake authentication to work
perl -pi -e "s/django.contrib.auth.middleware.AuthenticationMiddleware',$/django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.auth.middleware.RemoteUserMiddleware',/" $PHYLODB_DIR/phylodb/settings.py
echo "AUTHENTICATION_BACKENDS = [ 'django.contrib.auth.backends.RemoteUserBackend' ]" >> $PHYLODB_DIR/phylodb/settings.py
# Django install
cd $LIB_DIR/django
if [ \! -d phylodbenv ]
......@@ -92,4 +96,4 @@ fi
# Start Gunicon WSGI server on port 8888
ps awux |grep gunicorn|grep -v grep|awk '{print "kill " $2}'|bash
nohup gunicorn -b :8888 phylodb.wsgi&
nohup gunicorn -e REMOTE_USER=admin -b :8888 phylodb.wsgi&
......@@ -3,17 +3,52 @@
from webtest import TestApp
app = TestApp('http://data.phylodev.org')
# TODO: find another way to authenticate or to pass auth cookie, as
# it breaks tests with params into the URL
def phyloget(url):
resp = app.get(url)
print ("Testing "+url)
resp = app.get('/home/login/?next='+url)
form = resp.form
form['username'] = 'admin'
form['password'] = 'phylodev'
return form.submit().follow()
resp=form.submit()
if resp.status_int == 302:
return resp.follow()
else:
return resp
# Sample test
resp = phyloget('/home/login/?next=/browse/project/PHA/sample/969/')
## Test home
resp = phyloget('/home/')
assert resp.status == '200 OK'
assert 'Welcome on the PhyloAlps project database' in resp
## Test a sample
resp = phyloget('/browse/project/PHA/sample/969/')
assert 'Asplenium lepidum' in resp
# Sample failing test
resp = phyloget('/home/login/?next=/browse/project/PHA/sample/969/')
assert 'Asplenium lepidumm' in resp
## Sample failing test
#resp = phyloget('/home/login/?next=/browse/project/PHA/sample/969/')
#assert 'Asplenium lepidumm' in resp
## Test a taxon
resp = phyloget('/browse/taxon/4946/')
assert 'Suaeda vera L.' in resp
# test the array (async query of the above taxon)
# DOES NOT WORK :-( -> params not passed as we are already into a GET with the url as a param...
#resp = phyloget('/browse/taxon/4946/samples/json?draw=1&columns%5B0%5D%5Bdata%5D=lab_id&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=project__name&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=date&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=true&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B3%5D%5Bdata%5D=collector__lastname&columns%5B3%5D%5Bname%5D=&columns%5B3%5D%5Bsearchable%5D=true&columns%5B3%5D%5Borderable%5D=true&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B4%5D%5Bdata%5D=location_name&columns%5B4%5D%5Bname%5D=&columns%5B4%5D%5Bsearchable%5D=true&columns%5B4%5D%5Borderable%5D=true&columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B5%5D%5Bdata%5D=nb_extracts&columns%5B5%5D%5Bname%5D=&columns%5B5%5D%5Bsearchable%5D=true&columns%5B5%5D%5Borderable%5D=true&columns%5B5%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B5%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B6%5D%5Bdata%5D=nb_assemblings&columns%5B6%5D%5Bname%5D=&columns%5B6%5D%5Bsearchable%5D=true&columns%5B6%5D%5Borderable%5D=true&columns%5B6%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B6%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B7%5D%5Bdata%5D=comment&columns%5B7%5D%5Bname%5D=&columns%5B7%5D%5Bsearchable%5D=true&columns%5B7%5D%5Borderable%5D=true&columns%5B7%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B7%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B8%5D%5Bdata%5D=url&columns%5B8%5D%5Bname%5D=&columns%5B8%5D%5Bsearchable%5D=true&columns%5B8%5D%5Borderable%5D=false&columns%5B8%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B8%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1539939245006')
#assert 'PYR010533' in resp
## Test a person
resp = phyloget('/browse/person/39/')
assert 'SAJF' in resp
## Test editor query
resp = phyloget('/edit/project/PHA/sample/20/')
assert 'Acer negundo' in resp
## Test a search
# DOES NOT WORK: timeout
#resp = phyloget('/browse/search/everything/Cardamine%20amara')
#assert 'PHA001676' in resp.follow
Markdown is supported
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