2014-10-11 23:39:01 +02:00
|
|
|
import os
|
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from pyhamtools.qsl import get_lotw_users
|
|
|
|
|
|
|
|
|
|
class Test_lotw_methods:
|
|
|
|
|
|
|
|
|
|
def test_check_content_with_mocked_http_server(self, httpserver):
|
2017-08-20 16:26:37 +02:00
|
|
|
httpserver.serve_content(open('./fixtures/lotw-user-activity.csv').read())
|
2014-10-11 23:39:01 +02:00
|
|
|
|
2017-08-20 16:26:37 +02:00
|
|
|
exec(open(os.path.join("./fixtures/","lotw_fixture.py")).read())
|
2014-10-11 23:39:01 +02:00
|
|
|
assert get_lotw_users(url=httpserver.url) == lotw_fixture
|
|
|
|
|
|
|
|
|
|
def test_download_lotw_list_and_check_types(self):
|
|
|
|
|
|
|
|
|
|
data = get_lotw_users()
|
|
|
|
|
assert isinstance(data, dict)
|
|
|
|
|
for key, value in data.iteritems():
|
|
|
|
|
assert isinstance(key, unicode)
|
|
|
|
|
assert isinstance(value, datetime.datetime )
|
|
|
|
|
assert len(data) > 1000
|
|
|
|
|
|
|
|
|
|
def test_with_invalid_url(self):
|
|
|
|
|
with pytest.raises(IOError):
|
2017-08-20 16:26:37 +02:00
|
|
|
get_lotw_users(url="https://lotw.arrl.org/lotw-user-activity_FAKE.csv")
|
2014-10-11 23:39:01 +02:00
|
|
|
|
2015-04-06 20:00:30 +02:00
|
|
|
def test_with_more_than_10_invalid_dates(self, httpserver):
|
|
|
|
|
httpserver.serve_content(open('./fixtures/lotw_data_with_errors.html').read())
|
|
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
|
get_lotw_users(url=httpserver.url)
|
|
|
|
|
|
|
|
|
|
|
2014-10-11 23:39:01 +02:00
|
|
|
|