git-subtree-dir: fiscal git-subtree-mainline:d95165fc8fgit-subtree-split:102ba84500
36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
import importlib.util
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
spec = importlib.util.spec_from_file_location("dsc", Path(__file__).parents[1] / "scripts" / "discover_testesoficiais_fiscal.py")
|
|
dsc = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(dsc)
|
|
|
|
|
|
class Recorder:
|
|
def __init__(self):
|
|
self.sql = []
|
|
|
|
def execute(self, sql, params=()):
|
|
self.sql.append(sql)
|
|
|
|
|
|
def test_only_select_reaches_the_driver_and_writes_are_counted():
|
|
rec = Recorder()
|
|
cur = dsc.ReadOnlyCursor(rec)
|
|
dsc.ReadOnlyCursor.write_attempts = 0
|
|
cur.execute(" select 1 from rdb$database")
|
|
for bad in ("UPDATE C000025 SET NCM='1'", "delete from c000025", "INSERT INTO x VALUES (1)", "ALTER TABLE x ADD y INT", "EXECUTE PROCEDURE p", "DROP TABLE x"):
|
|
with pytest.raises(RuntimeError):
|
|
cur.execute(bad)
|
|
assert rec.sql == [" select 1 from rdb$database"] and dsc.ReadOnlyCursor.write_attempts == 6 and dsc.ReadOnlyCursor.write_successes == 0
|
|
|
|
|
|
def test_classification_does_not_infer_from_ncm_or_icms_cst():
|
|
assert dsc.classify("C000025", "CCLASSTRIB")[0] == "CONFIRMED_MATCH"
|
|
assert dsc.classify("RTC_CST", "CSTIBSCBS")[1] == "CST IBS/CBS"
|
|
assert dsc.classify("C000025", "CLASSIFICACAO_FISCAL")[0] == "POSSIBLE_MATCH" # NCM holder, not cClassTrib
|
|
assert dsc.classify("C000025", "CST")[0] == "UNRELATED" # ICMS CST is not CST IBS/CBS
|
|
assert dsc.classify("C000025", "NCM")[0] == "UNRELATED"
|