def test_download_too_long(): etime = "2020/01/01 00:00:00" stime = "2019/12/01 00:01:01" station_id = "over_the_rainbow" with pytest.raises(ValueError) as e: download("u", "p", None, None, stime, etime, station_id, url) assert "however requests longer than 7" in e.message
def test_download_bad_args(stime, etime): """download() should raise a ValueError if it receives *any* time parameters, but not a station_id """ station_id = None with pytest.raises(ValueError) as e: download("u", "p", None, None, stime, etime, station_id, url) assert "Please either specify" in e.message
def main(): # pragma: no cover desc = globals()["__doc__"] parser = ArgumentParser(description=desc) parser = logging_args(parser) parser = common_auth_arguments(parser) parser.add_argument( "-S", "--start_time", help=("Alternate time to use for downloading " "(interpreted with dateutil.parser.parse)." "Defaults to one hour prior to now"), ) parser.add_argument( "-E", "--end_time", help=("Alternate time to use for downloading " "(interpreted with dateutil.parser.parse)." "Defaults to now."), ) parser.add_argument("-s", "--station_id", default=None, help="Station ID for which to download data") parser.add_argument( "-u", "--base_url", default="https://prdoas5.apps.th.gov.bc.ca/saw-data/sawr7110", help="Base URL for the MoTI SAW service", ) args = parser.parse_args() setup_logging( args.log_conf, args.log_filename, args.error_email, args.log_level, "crmprtd.moti", ) download( args.username, args.password, args.auth_fname, args.auth_key, args.start_time, args.end_time, args.station_id, args.base_url, )
def test_download(stime, etime, station_id, expected_payload, mocker): # We don't need/want to test the actually https request going out # so let's just mock that call and ensure that it gets called with # the expected arguments mocker.patch("crmprtd.download.https_download") # Default time arguments are the "present" time at the time # download() is run. Since this is not predictable, we need to # mock out datetime.utcnow() to give us a deterministic time to # test against. mocker.patch("crmprtd.moti.download.utcnow", return_value=now) download("u", "p", None, None, stime, etime, station_id, url) crmprtd.download.https_download.assert_called_once() call_args, _ = crmprtd.download.https_download.call_args _, _, _, _, payload = call_args assert payload == expected_payload
def main(): # pragma: no cover desc = globals()["__doc__"] parser = ArgumentParser(description=desc) parser = logging_args(parser) parser = common_auth_arguments(parser) parser.add_argument( "-S", "--start_time", type=dateutil.parser.parse, help=("Optional start time to use for downloading " "(interpreted with dateutil.parser.parse)." "Defaults to one day prior to now"), ) parser.add_argument( "-E", "--end_time", type=dateutil.parser.parse, help=("Optional end time to use for downloading " "(interpreted with dateutil.parser.parse)." "Defaults to now."), ) args = parser.parse_args() setup_logging( args.log_conf, args.log_filename, args.error_email, args.log_level, "crmprtd.crd", ) verify_dates(args.start_time, args.end_time) auth_yaml = open(args.auth_fname, "r").read() if args.auth_fname else None auth = crmprtd.download.extract_auth(args.username, None, auth_yaml, args.auth_key) download(auth["u"], args.start_time, args.end_time)