first-pass automatic testing

This commit is contained in:
John Krauss 2016-05-12 14:21:31 -04:00
parent e74964c1ee
commit d0122786db
4 changed files with 86 additions and 0 deletions

2
.gitignore vendored
View File

@ -2,3 +2,5 @@
src/pg/observatory--current--dev.sql src/pg/observatory--current--dev.sql
src/pg/observatory--dev--current.sql src/pg/observatory--dev--current.sql
src/pg/observatory--dev.sql src/pg/observatory--dev.sql
venv
*.pyc

15
scripts/README.md Normal file
View File

@ -0,0 +1,15 @@
## Automatic tests and utilities
### Installation
Python 2.7 should cover you. Virtualenv recommended.
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
### Execution
Run automated tests against a hostname:
(venv) OBS_HOSTNAME=<hostname.cartodb.com> OBS_API_KEY=foobar nosetests autotest.py

66
scripts/autotest.py Normal file
View File

@ -0,0 +1,66 @@
from nose.tools import assert_equal
from nose_parameterized import parameterized
import os
import re
import requests
HOSTNAME = os.environ['OBS_HOSTNAME']
API_KEY = os.environ['OBS_API_KEY']
def query(q, **options):
'''
Query the account. Returned is the response, wrapped by the requests
library.
'''
url = 'https://{hostname}/api/v2/sql'.format(hostname=HOSTNAME)
params = options.copy()
params['q'] = re.sub(r'\s+', ' ', q)
params['api_key'] = API_KEY
return requests.get(url, params=params)
MEASURE_COLUMNS = [(r['id'], ) for r in query('''
SELECT id FROM observatory.obs_column
WHERE type ILIKE 'numeric'
AND weight > 0
''').json()['rows']]
CATEGORY_COLUMNS = [(r['id'], ) for r in query('''
SELECT id FROM observatory.obs_column
WHERE type ILIKE 'text'
AND weight > 0
''').json()['rows']]
BOUNDARY_COLUMNS = [(r['id'], ) for r in query('''
SELECT id FROM observatory.obs_column
WHERE type ILIKE 'geometry'
AND weight > 0
''').json()['rows']]
@parameterized(MEASURE_COLUMNS)
def test_measure_points(column_id):
resp = query('''
SELECT *
FROM cdb_observatory.OBS_GetMeasure(cdb_observatory._TestPoint(),
'{column_id}')
'''.format(column_id=column_id))
assert_equal(resp.status_code, 200)
@parameterized(CATEGORY_COLUMNS)
def test_category_points(column_id):
resp = query('''
SELECT *
FROM cdb_observatory.OBS_GetCategory(cdb_observatory._TestPoint(),
'{column_id}')
'''.format(column_id=column_id))
assert_equal(resp.status_code, 200)
@parameterized(BOUNDARY_COLUMNS)
def test_boundary_points(column_id):
resp = query('''
SELECT *
FROM cdb_observatory.OBS_GetBoundary(cdb_observatory._TestPoint(),
'{column_id}')
'''.format(column_id=column_id))
assert_equal(resp.status_code, 200)

3
scripts/requirements.txt Normal file
View File

@ -0,0 +1,3 @@
requests
nose
nose_parameterized