import copy
import json
import unittest
from pathlib import Path
from verify_final import fixture_check,verify_all

class FinalEvidenceChecks(unittest.TestCase):
    def test_full_replay(self):
        result=verify_all()
        self.assertEqual(result['true_HTTP'],60)
        self.assertEqual(result['strict_effective_BC_pairs'],26)
        self.assertEqual(result['B_old_raw_trace_only_equal'],4)

    def test_fixture_mutations(self):
        p=Path(__file__).parent
        journal=json.loads((p/'private-evidence/C/fixture-journal.json').read_text())
        proposal=json.loads((p/'fixture-proposal-C.json').read_text())
        fixture_check('C',journal,proposal)
        mutations=[]
        bad=copy.deepcopy(journal);bad['statements'][0]['rowCount']=2;mutations.append(bad)
        bad=copy.deepcopy(journal);bad['statements'][0]['executed']=False;mutations.append(bad)
        bad=copy.deepcopy(journal);bad['statements'][0]['bindValue'][0]['pdo_type']=1;mutations.append(bad)
        bad=copy.deepcopy(journal);bad['owned'][0]['original']['img']='missing';mutations.append(bad)
        bad=copy.deepcopy(journal);bad['owned'][0]['original']['extra']=1;mutations.append(bad)
        bad=copy.deepcopy(journal);bad['refs']['@staff_store']=99999;mutations.append(bad)
        bad=copy.deepcopy(journal);bad['after']['user'][0]['points']=99999;mutations.append(bad)
        bad=copy.deepcopy(journal);bad['committed']=False;mutations.append(bad)
        for bad in mutations:
            with self.assertRaises((AssertionError,KeyError)):fixture_check('C',bad,proposal)
        self.assertEqual(len(mutations),8)

if __name__=='__main__':unittest.main()
