pyhamtools/test/test_lotw.py

53 lines
1.6 KiB
Python
Raw Permalink Normal View History

2018-01-27 19:52:27 +01:00
import os
import datetime
from .execfile import execfile
import pytest
def execfile(filepath, globals=None, locals=None):
if globals is None:
globals = {}
globals.update({
"__file__": filepath,
"__name__": "__main__",
})
with open(filepath, 'rb') as file:
exec(compile(file.read(), filepath, 'exec'), globals, locals)
from pyhamtools.qsl import get_lotw_users
2018-01-27 19:52:27 +01:00
test_dir = os.path.dirname(os.path.abspath(__file__))
fix_dir = os.path.join(test_dir, 'fixtures')
class Test_lotw_methods:
2018-01-27 19:52:27 +01:00
def test_check_content_with_mocked_http_server(self, httpserver):
2018-01-27 19:52:27 +01:00
httpserver.serve_content(open(os.path.join(fix_dir, 'lotw-user-activity.csv')).read())
namespace = {}
execfile(os.path.join(fix_dir,"lotw_fixture.py"), namespace)
assert get_lotw_users(url=httpserver.url) == namespace['lotw_fixture']
@pytest.mark.skip("ARRL has been hacked in May 2024; skipping until LOTW is again up")
def test_download_lotw_list_and_check_types(self):
2018-01-27 19:52:27 +01:00
data = get_lotw_users()
assert isinstance(data, dict)
2023-12-28 21:02:41 +01:00
for key, value in data.items():
assert isinstance(key, str)
assert isinstance(value, datetime.datetime )
assert len(data) > 1000
2018-01-27 19:52:27 +01:00
def test_with_invalid_url(self):
with pytest.raises(IOError):
get_lotw_users(url="https://lotw.arrl.org/lotw-user-activity_FAKE.csv")
2018-01-27 19:52:27 +01:00
def test_with_more_than_10_invalid_dates(self, httpserver):
2018-01-27 19:52:27 +01:00
httpserver.serve_content(open(os.path.join(fix_dir, 'lotw_data_with_errors.html')).read())
with pytest.raises(ValueError):
get_lotw_users(url=httpserver.url)
2018-01-27 19:52:27 +01:00