Skip to content

Commit

Permalink
Should support testing on semaphore.ci
Browse files Browse the repository at this point in the history
Closes #105 issue with CEHQ remote gages impacted by ice.
  • Loading branch information
abkfenris committed Feb 25, 2017
1 parent 3409919 commit 233b8b0
Show file tree
Hide file tree
Showing 72 changed files with 1,575 additions and 149 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "tests/gage_client"]
path = tests/gage_client
url = https://[email protected]/abkfenris/gage-client.git
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ down:
docker-compose down

stop:
docker-compose stop
docker-compose stop

test:
docker-compose --project-name testing -f docker-compose.test.yml up -d --build
docker-compose --project-name testing -f docker-compose.test.yml run wait
docker-compose --project-name testing -f docker-compose.test.yml run web py.test -v tests
docker-compose --project-name testing -f docker-compose.test.yml down
25 changes: 25 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '2'

services:
postgis:
image: "mdillon/postgis:9.6"
environment:
- POSTGRES_PASSWORD=testing
- POSTGRES_DB=gage-web

web:
build: ./web
links:
- postgis:postgis
command: "python /app/manage.py runserver -d -r -p 8000 --host=0.0.0.0"
volumes:
- ./web:/usr/src/app
environment:
- GAGE_DB=postgresql://postgres:testing@postgis/gage-web

wait:
links:
- postgis:postgis
image: waisbrot/wait
environment:
- TARGETS=postgis:5432
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ services:
- redis:redis
command: "gunicorn --log-level debug --log-config logging.conf -w 2 -b :8000 wsgi:app"
volumes:
- .:/app
- ./web:/usr/src/app
env_file:
- ./common.env

Expand Down
9 changes: 0 additions & 9 deletions tests.yml

This file was deleted.

1 change: 0 additions & 1 deletion tests/gage_client
Submodule gage_client deleted from 8a7600
110 changes: 0 additions & 110 deletions tests/test_main_plot.py

This file was deleted.

2 changes: 1 addition & 1 deletion web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ RUN apt-get update && apt-get install -y \


COPY requirements/ /usr/src/app/requirements/
RUN pip install --no-cache-dir -r requirements/core.txt
RUN pip install --no-cache-dir -r requirements/develop.txt

COPY . /usr/src/app
2 changes: 1 addition & 1 deletion web/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os

from flask import Flask
from flask.ext.bootstrap import Bootstrap
from flask_bootstrap import Bootstrap
from flask_security import Security
from flask_debugtoolbar import DebugToolbarExtension
import logging
Expand Down
2 changes: 1 addition & 1 deletion web/app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Database builder
"""

from flask.ext.sqlalchemy import SQLAlchemy
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.sql import text

db = SQLAlchemy()
Expand Down
8 changes: 7 additions & 1 deletion web/app/remote/cehq.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
logger = logging.getLogger(__name__)


def digit_or_period(c):
"""Returns True if the character c given is a string or a period"""
return str.isdigit(c) or c is '.'


class CEHQ(RemoteGage):
URLBASE = 'http://www.cehq.gouv.qc.ca/suivihydro/fichier_donnees.asp'

Expand All @@ -27,7 +32,8 @@ def response(self, site_num):
def recent_flow(self, site_num):
r = self.response(site_num)
line = r.text.splitlines()[2]
return float(line.split('\t')[2].replace(',', '.'))
number = line.split('\t')[2].replace(',', '.')
return float(''.join(list(filter(digit_or_period, number))))

def get_sample(self, sensor_id):
sensor = self.sensor(sensor_id)
Expand Down
2 changes: 1 addition & 1 deletion web/app/templates/section.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h1>{{ section.name }}</h1>

{% for correlation in section.correlations %}
<div class="tab-pane" id="{{ correlation.sensor.stype}}">
<img src="{{ url_for('.correlationplotpng', stype=correlation.sensor.stype, gage=correlation.sensor.gage.slug, section=correlation.section.slug, river=correlation.section.river.slug ) }}" class="img-responsive">
Plots will return sometime
</div>
{% endfor %}

Expand Down
2 changes: 1 addition & 1 deletion web/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TestingConfig(Config):
API_GAGES_PER_PAGE = 1
SECRET_KEY = '1' # noqa
CSRF_ENABLED = False
SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/gage_web_testing'
SQLALCHEMY_DATABASE_URI = os.environ.get('GAGE_DB', 'postgresql://localhost/gage_web_testing')
CELERY_ALWAYS_EAGER = True
# SQLALCHEMY_ECHO = True

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion web/requirements/develop.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-r core.txt
-r testing.txt
-r not-travis.txt
#-r not-travis.txt

# Flask Extensions
1 change: 1 addition & 0 deletions web/requirements/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ mock==1.3.0
pytest==2.8.2
vcrpy==1.7.2
codecov==1.5.1
pytest-cov==2.4.0
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions web/tests/gage_client/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[report]
omit =
*__init__*
*/python?.?/*
*/site-packages/*
*/docs/*
55 changes: 55 additions & 0 deletions web/tests/gage_client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/
*.ipynb
13 changes: 13 additions & 0 deletions web/tests/gage_client/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: python
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
- "3.4"
# install dependencies
install: "pip install -r dev-requirements.txt"
# run tests
script: nosetests --cover-package=gage_client --with-xcoverage
after_success:
- coveralls
22 changes: 22 additions & 0 deletions web/tests/gage_client/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Alex Kerney

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

14 changes: 14 additions & 0 deletions web/tests/gage_client/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
gage-client
===========

Python client to talk to gage-web

.. image:: https://img.shields.io/travis/abkfenris/gage-client.svg
:target: https://travis-ci.org/abkfenris/gage-client
.. image:: https://img.shields.io/coveralls/abkfenris/gage-client.svg
:target: https://coveralls.io/r/abkfenris/gage-client
.. image:: https://img.shields.io/github/issues/abkfenris/gage-client.svg
:target: https://github.com/abkfenris/gage-client/issues

Implementation should be Python 3 compatable, but Responses is currently not
Python 3 compatable for testing purposes.
Empty file.
11 changes: 11 additions & 0 deletions web/tests/gage_client/dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
coverage==3.7.1
itsdangerous==0.24
mock==1.0.1
nose==1.3.4
nosexcover==1.0.10
python-coveralls==2.5.0
PyYAML==3.11
requests==2.6.0
responses==0.3.0
sh==1.11
six==1.9.0
Loading

0 comments on commit 233b8b0

Please sign in to comment.