File size: 2,193 Bytes
4b6e3ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77fa5a9
 
5d646a8
 
77fa5a9
 
 
5d646a8
77fa5a9
 
5d646a8
 
3f60fb7
77fa5a9
 
 
5d646a8
3f60fb7
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from src.config.runtime_config import RuntimeConfig


def test_runtime_config_reads_hf_project_state_writes_flag(monkeypatch) -> None:  # noqa: ANN001
    monkeypatch.setenv("BIRDNET_HF_PROJECT_STATE_WRITES_ENABLED", "true")

    config = RuntimeConfig.from_env()

    assert config.hf_project_state_writes_enabled is True


def test_runtime_config_disables_hf_project_state_writes_by_default(monkeypatch) -> None:  # noqa: ANN001
    monkeypatch.delenv("BIRDNET_HF_PROJECT_STATE_WRITES_ENABLED", raising=False)

    config = RuntimeConfig.from_env()

    assert config.hf_project_state_writes_enabled is False


def test_runtime_config_reads_hf_project_state_repo_list(monkeypatch) -> None:  # noqa: ANN001
    monkeypatch.setenv("BIRDNET_HF_PROJECT_STATE_REPOS", "owner/a_state; owner/b_state,\nowner/c_state")

    config = RuntimeConfig.from_env()

    assert config.hf_project_state_repos == ("owner/a_state", "owner/b_state", "owner/c_state")


def test_runtime_config_reads_bucket_validation_flag(monkeypatch) -> None:  # noqa: ANN001
    monkeypatch.setenv("BIRDNET_HF_BUCKET_VALIDATIONS_ENABLED", "true")

    config = RuntimeConfig.from_env()

    assert config.hf_bucket_validations_enabled is True


def test_runtime_config_reads_hf_admin_storage_mode_flag(monkeypatch) -> None:  # noqa: ANN001
    monkeypatch.setenv("BIRDNET_HF_ADMIN_STORAGE_MODE_ENABLED", "true")

    config = RuntimeConfig.from_env()

    assert config.hf_admin_storage_mode_enabled is True


def test_runtime_config_disables_hf_admin_storage_mode_by_default(monkeypatch) -> None:  # noqa: ANN001
    monkeypatch.delenv("BIRDNET_HF_ADMIN_STORAGE_MODE_ENABLED", raising=False)
    monkeypatch.delenv("BIRDNET_HF_STORAGE_TOKEN", raising=False)

    config = RuntimeConfig.from_env()

    assert config.hf_admin_storage_mode_enabled is False


def test_runtime_config_enables_hf_admin_storage_mode_when_dedicated_secret_exists(monkeypatch) -> None:  # noqa: ANN001
    monkeypatch.delenv("BIRDNET_HF_ADMIN_STORAGE_MODE_ENABLED", raising=False)
    monkeypatch.setenv("BIRDNET_HF_STORAGE_TOKEN", "hf_storage_secret")

    config = RuntimeConfig.from_env()

    assert config.hf_admin_storage_mode_enabled is True