a4c92470b6
feat: implement tests for maintenance functions and dashboard interactions feat: add timezone and country tests for thctime module
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
import thctime
|
|
|
|
|
|
def test_load_timezones_and_countries():
|
|
tzs = thctime.load_timezones()
|
|
countries = thctime.load_countries()
|
|
assert any(t["zone_name"] == "America/New_York" for t in tzs)
|
|
assert any(c["country_code"] == "US" for c in countries)
|
|
|
|
|
|
def test_get_tz_and_country_info():
|
|
timezones = [{"zone_name": "A/B", "country_code": "US"}]
|
|
countries = [{"country_code": "US", "country_name": "United States"}]
|
|
assert thctime.get_tz_info("A/B", timezones)["zone_name"] == "A/B"
|
|
assert thctime.get_country_info("US", countries)[
|
|
"country_name"] == "United States"
|
|
assert thctime.get_tz_info("X/Y", timezones) is None
|
|
assert thctime.get_country_info("XX", countries) is None
|
|
|
|
|
|
def test_where_is_it_420(monkeypatch):
|
|
monkeypatch.setattr(thctime.pytz, "all_timezones", ["Etc/UTC"])
|
|
|
|
tzs = [{"zone_name": "Etc/UTC", "country_code": "ZZ"}]
|
|
countries = [{"country_code": "ZZ", "country_name": "Nowhere"}]
|
|
|
|
class FakeDatetime:
|
|
@staticmethod
|
|
def now(tz):
|
|
class Result:
|
|
hour = 4
|
|
|
|
return Result()
|
|
|
|
monkeypatch.setattr(thctime, "datetime", FakeDatetime)
|
|
|
|
res = thctime.where_is_it_420(tzs, countries)
|
|
assert res == ["Nowhere"]
|
|
|
|
|
|
def test_split_tz_name():
|
|
assert thctime.split_tz_name("America/New_York") == ("America", "New_York")
|
|
assert thctime.split_tz_name("America/Argentina/Buenos_Aires") == (
|
|
"America",
|
|
"Argentina/Buenos_Aires",
|
|
)
|
|
assert thctime.split_tz_name("UTC") == ("UTC", "")
|