dodil/erp-platform

tests/test_claim_tables.py

"""A duplicate key on a declared claim table is a Conflict wherever it surfaces (DataK3 reports it at COMMIT)."""
import pytest

from erp_platform import repository


def test_a_commit_time_duplicate_on_a_declared_claim_table_is_a_conflict(monkeypatch):
    monkeypatch.setattr(repository, "CLAIM_TABLES", set())
    err = Exception('duplicate key value violates unique constraint "pay_source_claim_pkey"')
    assert repository.as_conflict(err) is None                 # undeclared: not ours to call a conflict
    repository.claim_tables("pay_source_claim")
    assert isinstance(repository.as_conflict(err), repository.Conflict)


def test_a_duplicate_on_any_other_table_is_not_a_conflict(monkeypatch):
    monkeypatch.setattr(repository, "CLAIM_TABLES", {"pay_source_claim"})
    assert repository.as_conflict(Exception('duplicate key value violates unique constraint "pay_receipt_pkey"')) is None


def test_a_claim_table_name_is_a_plain_name():
    with pytest.raises(ValueError):
        repository.claim_tables("pay; drop")