Skip to content

Commit

Permalink
Removing extraneous from remote.cehq, testing that the remote base cl…
Browse files Browse the repository at this point in the history
…ass will raise exceptions correctly and that the remote.base multiple sensor check will work, fixtures for remote.corps
  • Loading branch information
abkfenris committed Sep 6, 2015
1 parent e692c29 commit 2da7e47
Show file tree
Hide file tree
Showing 9 changed files with 1,083 additions and 22 deletions.
6 changes: 2 additions & 4 deletions app/remote/cawateroffice.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
then site number. e.g.:
The Cheticamp River (http://wateroffice.ec.gc.ca/report/report_e.html?type=realTime&stn=01FC002)
would be NS_01FC002
If discharge is prefered set the remote_parameter to discharge
"""
import csv

Expand All @@ -30,10 +31,7 @@ def get_from_wateroffice(self, remote_id):
lines.append(row)
last = lines[-1]
print(last)
try:
level = float(last[2])
except ValueError:
level = None
level = float(last[2])
try:
discharge = float(last[6])
except ValueError:
Expand Down
12 changes: 0 additions & 12 deletions app/remote/cehq.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,6 @@ def get_sample(self, sensor_id):
c = CEHQ()


def get_response(site_num):
"""
Retrieve a requests.Response object for the plain text representation of a
Quebec CEHQ gage
"""
return c.response(site_num)


def get_recent_flow(site_num):
return c.recent_flow(site_num)


def get_sample(sensor_id):
"""
Takes a sensor id, tries to retrieve the latest sample from the site
Expand Down
46 changes: 46 additions & 0 deletions tests/fixtures/cawateroffice_get_multiple_samples

Large diffs are not rendered by default.

254 changes: 254 additions & 0 deletions tests/fixtures/corps_get_sample

Large diffs are not rendered by default.

748 changes: 748 additions & 0 deletions tests/fixtures/corps_soup_dt_value

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ def setUp(self):
stype='cawater-level',
local=False, remote_type='cawater',
remote_id='NL_02YL012')
cheakamus_discharge = Sensor(name='Cheakamus Discharge',
stype='cawater-discharge',
local=False, remote_type='cawater',
remote_id='BC_08GA043',
remote_parameter='discharge')
canaseraga_stage = Sensor(name='Canaseraga Creek',
stype='canaseraga-stage',
local=False, remote_type='corps',
Expand Down
13 changes: 13 additions & 0 deletions tests/test_remote_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

from .test_basics import BasicTestCase

from app.remote import base


class TestRemoteBase(BasicTestCase):
RemoteGage = base.RemoteGage()

def test_get_sample(self):
with pytest.raises(NotImplementedError):
self.RemoteGage.get_sample(1)
19 changes: 13 additions & 6 deletions tests/test_remote_cawateroffice.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from app.models import Sensor, Sample

my_vcr = vcr.VCR(
#match_on=['method']
# match_on=['method']
)


Expand All @@ -17,25 +17,32 @@ class TestWaterOffice(BasicTestCase):
'NB_01AL002', 'NT_10FB001', 'NS_01FC002', 'NU_06JC002',
'ON_02KB001', 'PE_01CB002', 'QC_02OB011', 'SK_05JK007',
'YT_08AB001']
WaterOffice = cawateroffice.WaterOffice()
WO = cawateroffice.WaterOffice()

@my_vcr.use_cassette('tests/fixtures/cawateroffice_get_from_wateroffice')
def test_get_from_wateroffice(self):
for site_num in self.SITES:
dt, level, discharge = self.WaterOffice.get_from_wateroffice(site_num)
dt, level, discharge = self.WO.get_from_wateroffice(site_num)
assert type(level) == float
assert type(dt) == datetime.datetime
try:
assert type(discharge) == float
except AssertionError:
assert discharge is None



@my_vcr.use_cassette('tests/fixtures/cawateroffice_get_sample')
def test_get_sample(self):
sensor = Sensor.query.filter(Sensor.remote_type == 'cawater').first()
before = Sample.query.count()
self.WaterOffice.get_sample(sensor.id)
self.WO.get_sample(sensor.id)
after = Sample.query.count()
assert after > before

@my_vcr.use_cassette('tests/fixtures/cawateroffice_get_multiple_samples')
def test_get_multiple_samples(self):
sensors = Sensor.query.filter(Sensor.remote_type == 'cawater').all()
sensor_ids = [sensor.id for sensor in sensors]
before = Sample.query.count()
self.WO.get_multiple_samples(sensor_ids)
after = Sample.query.count()
assert after > before
2 changes: 2 additions & 0 deletions tests/test_remote_corps.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ class TestCorps(BasicTestCase):
SITES = ['DSVN6', 'SCNM5', 'SMW']
Corps = corps.Corps()

@my_vcr.use_cassette('tests/fixtures/corps_soup_dt_value')
def test_soup_dt_value(self):
for site_num in self.SITES:
dt, value = self.Corps.dt_value(site_num)
assert type(value) == float
assert type(dt) == datetime.datetime

@my_vcr.use_cassette('tests/fixtures/corps_get_sample')
def test_get_sample(self):
sensor = Sensor.query.filter(Sensor.remote_type == 'corps').first()
before = Sample.query.count()
Expand Down

0 comments on commit 2da7e47

Please sign in to comment.