| import gzip | |
| from leaderboard_analytics.geoip_database import ensure_geoip_database | |
| def test_ensure_geoip_database_downloads_and_decompresses_gzip(tmp_path) -> None: | |
| source = tmp_path / "GeoLite2-Country.mmdb.gz" | |
| target = tmp_path / "GeoLite2-Country.mmdb" | |
| expected_bytes = b"fake-mmdb-bytes" | |
| with gzip.open(source, "wb") as gzip_file: | |
| gzip_file.write(expected_bytes) | |
| result = ensure_geoip_database(target, source.as_uri()) | |
| assert result == target | |
| assert target.read_bytes() == expected_bytes | |
| def test_ensure_geoip_database_keeps_existing_file(tmp_path) -> None: | |
| source = tmp_path / "missing.mmdb.gz" | |
| target = tmp_path / "GeoLite2-Country.mmdb" | |
| expected_bytes = b"existing-mmdb-bytes" | |
| target.write_bytes(expected_bytes) | |
| result = ensure_geoip_database(target, source.as_uri()) | |
| assert result == target | |
| assert target.read_bytes() == expected_bytes | |