File size: 1,340 Bytes
a3c85ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Source refresh tests."""

from datetime import datetime, timezone

from coastwise.schemas import RefreshStatus
from coastwise.source_cache import DEFAULT_SEED_CACHE_DIR, load_seed_cache
from coastwise.source_refresh import refresh_official_sources
from coastwise.source_registry import load_official_sources


NOW = datetime(2026, 6, 14, 13, tzinfo=timezone.utc)


def test_refresh_official_sources_reports_updated_unchanged_failed_and_partial():
    sources = load_official_sources()[:3]
    cache = load_seed_cache(DEFAULT_SEED_CACHE_DIR)

    def fetcher(source):
        if source.id == sources[0].id:
            return cache.snapshots_by_source_id[source.id].raw_text + " updated"
        if source.id == sources[1].id:
            return cache.snapshots_by_source_id[source.id].raw_text
        raise OSError("network unavailable")

    result, refreshed_cache = refresh_official_sources(sources, cache, NOW, fetcher)

    assert result.source_results[sources[0].id] is RefreshStatus.UPDATED
    assert result.source_results[sources[1].id] is RefreshStatus.UNCHANGED
    assert result.source_results[sources[2].id] is RefreshStatus.FAILED
    assert sources[2].id in result.cache_preserved_source_ids
    assert refreshed_cache.snapshots_by_source_id[sources[2].id].content_hash
    assert "failed" in result.user_message.lower()