def test_check_contract_org_not_found(self, get_data_mock, get_org_mock, get_context_mock, prepare_context_mock, save_context_mock, send_contract_xml_mock): contract_id = "4444" tender_id = "555555555" get_org_mock.return_value = None contract_data = dict( id=contract_id, status="active", tender_id=tender_id, dateSigned="2021-03-11T13:49:00+02:00", procuringEntity=dict( identifier=dict(id="12345678", scheme="UA-EDR"))) get_data_mock.return_value = contract_data # run check_contract(contract_id) # checks get_data_mock.assert_called_once_with(check_contract, contract_data["id"], "contract") get_org_mock.assert_called_once_with( check_contract, contract_data["procuringEntity"]["identifier"]["id"]) get_context_mock.assert_not_called() prepare_context_mock.assert_not_called() save_context_mock.assert_not_called() send_contract_xml_mock.delay.assert_not_called()
def test_check_contract_invalid_identifier_scheme( self, get_data_mock, get_org_mock, get_context_mock, prepare_context_mock, save_context_mock, send_contract_xml_mock): contract_id = "4444" tender_id = "555555555" contract_data = dict( id=contract_id, status="cancelled", tender_id=tender_id, dateSigned="2021-03-11T13:49:00+02:00", procuringEntity=dict( identifier=dict(id="12345678", scheme="INVALID-SCHEME"))) get_data_mock.return_value = contract_data # run check_contract(contract_id) # checks get_data_mock.assert_called_once_with(check_contract, contract_data["id"], "contract") get_org_mock.assert_not_called() get_context_mock.assert_not_called() prepare_context_mock.assert_not_called() save_context_mock.assert_not_called() send_contract_xml_mock.delay.assert_not_called()
def test_check_contract_before_start(self, get_data_mock, get_org_mock, get_context_mock, prepare_context_mock, save_context_mock, send_contract_xml_mock): contract_id = "4444" tender_id = "123456" contract_data = dict( id=contract_id, status="active", dateSigned="2020-03-11T13:49:00+02:00", tender_id=tender_id, procuringEntity=dict( identifier=dict(scheme="UA-EDR", id="555555"))) get_data_mock.return_value = contract_data # run with patch("treasury.tasks.TREASURY_INT_START_DATE", "2020-03-12"): check_contract(contract_id) # checks get_data_mock.assert_called_once_with(check_contract, contract_data["id"], "contract") get_org_mock.assert_not_called() get_context_mock.assert_not_called() prepare_context_mock.assert_not_called() save_context_mock.assert_not_called() send_contract_xml_mock.delay.assert_not_called()
def test_check_contract_skip_not_active_status( self, get_data_mock, get_org_mock, get_context_mock, prepare_context_mock, save_context_mock, send_contract_xml_mock): contract_id = 123456 procuring_entity_id = 1234 tender_id = "123456" contract_data = dict( id=contract_id, tender_id=tender_id, dateSigned="2020-05-20T13:49:00+02:00", status="complete", procuringEntity=dict( identifier=dict(id=procuring_entity_id, scheme="UA-EDR"))) get_data_mock.return_value = contract_data get_org_mock.return_value = {"org data"} # run check_contract(contract_id) # checks self.assertEqual(get_data_mock.mock_calls, [ call(check_contract, contract_id, "contract"), ]) get_org_mock.assert_not_called() get_context_mock.assert_not_called() prepare_context_mock.assert_not_called() save_context_mock.assert_not_called() send_contract_xml_mock.delay.assert_not_called()
def test_check_contract_ignore_date_signed(self, get_data_mock, get_org_mock, get_context_mock, prepare_context_mock, save_context_mock, send_contract_xml_mock): contract_id = 123456 procuring_entity_id = 1234 tender_id = "123456" contract_data = dict( id=contract_id, tender_id=tender_id, dateSigned="2020-05-20T13:49:00+02:00", status="active", procuringEntity=dict( identifier=dict(id=procuring_entity_id, scheme="UA-EDR"))) get_data_mock.return_value = contract_data get_org_mock.return_value = {"org data"} # run with patch("treasury.tasks.TREASURY_INT_START_DATE", "2020-08-25"): check_contract(contract_id, ignore_date_signed=True) # checks get_data_mock.assert_called_once_with(check_contract, contract_data["id"], "contract") get_org_mock.assert_called_once_with(check_contract, procuring_entity_id) get_context_mock.assert_called_once_with(check_contract, contract_data["id"]) prepare_context_mock.assert_not_called() save_context_mock.assert_not_called() send_contract_xml_mock.delay.assert_not_called()
def test_check_contract(self, get_data_mock, get_first_stage_tender_mock, get_org_mock, get_context_mock, prepare_context_mock, save_context_mock, send_contract_xml_mock): contract_id = "4444" get_org_mock.return_value = {"org data"} contract_data = dict( id=contract_id, status="active", tender_id="1234", dateSigned="2021-03-11T13:49:00+02:00", procuringEntity=dict( identifier=dict(id="12345678", scheme="UA-EDR"))) first_stage_tender_id = "23456789" tender_data_second_stage = dict( id="1234", procurementMethodType="competitiveDialogueEU.stage2", dialogueID=first_stage_tender_id) tender_data_first_stage = dict( id=first_stage_tender_id, procurementMethodType="competitiveDialogueEU", plans=[dict(id="321")]) get_first_stage_tender_mock.return_value = tender_data_first_stage plan_data = dict(id="321") get_data_mock.side_effect = [ contract_data, tender_data_first_stage, plan_data ] get_context_mock.return_value = None prepare_context_mock.return_value = {"iam": "context"} # run check_contract(contract_id) # checks get_org_mock.assert_called_once_with( check_contract, contract_data["procuringEntity"]["identifier"]["id"]) get_context_mock.assert_called_once_with(check_contract, contract_id) self.assertEqual(get_data_mock.mock_calls, [ call(check_contract, contract_id, "contract"), call(check_contract, contract_data["tender_id"], "tender"), call(check_contract, tender_data_first_stage["plans"][0]["id"], "plan") ]) prepare_context_mock.assert_called_once_with(check_contract, contract_data, tender_data_first_stage, plan_data) save_context_mock.assert_called_once_with( check_contract, contract_id, prepare_context_mock.return_value) send_contract_xml_mock.delay.assert_called_once_with(contract_id)
def test_check_contract_no_updates(self, get_data_mock, get_data_mock_prcontract, get_org_mock, get_context_mock, prepare_context_mock, save_context_mock, send_change_xml_mock): contract_id = "4444" tender_id = "555555555" get_org_mock.return_value = {"org data"} contract_data = dict( id=contract_id, status="active", tender_id=tender_id, changes=[ dict(id="111"), dict(id="222"), ], procuringEntity=dict( identifier=dict(id="12345678", scheme="UA-EDR"))) tender_data = dict( id=tender_id, date="2021-03-11T13:49:00+02:00", contracts=[dict(id=contract_id, date="2021-03-11T13:49:00+02:00")], procurementMethodType="aboveThresholdUA", ) get_data_mock.return_value = contract_data get_data_mock_prcontract.return_value = tender_data get_context_mock.return_value = dict(contract=dict(changes=[ dict(id="111"), dict(id="222"), ])) # run check_contract(contract_id) # checks get_data_mock.assert_called_once_with(check_contract, contract_data["id"], "contract") get_data_mock_prcontract.assert_called_once_with( check_contract, contract_data["tender_id"], "tender") get_org_mock.assert_called_once_with( check_contract, contract_data["procuringEntity"]["identifier"]["id"]) prepare_context_mock.assert_not_called() save_context_mock.assert_not_called() send_change_xml_mock.assert_not_called()
def test_check_contract_update(self, get_data_mock, get_org_mock, get_context_mock, prepare_context_mock, save_context_mock, send_change_xml_mock): contract_id = "4444" tender_id = "555555555" get_org_mock.return_value = {"org data"} contract_data = dict( id=contract_id, status="active", tender_id=tender_id, dateSigned="2021-03-11T13:49:00+02:00", changes=[ dict(id="222"), dict(id="333"), ], procuringEntity=dict( identifier=dict(id="12345678", scheme="UA-EDR"))) get_data_mock.return_value = contract_data get_context_mock.return_value = dict(contract=dict( changes=[dict(id="111")])) prepare_context_mock.return_value = {"iam": "context"} # run check_contract(contract_id) # checks get_context_mock.assert_called_once_with(check_contract, contract_id) get_data_mock.assert_called_once_with(check_contract, contract_data["id"], "contract") get_org_mock.assert_called_once_with( check_contract, contract_data["procuringEntity"]["identifier"]["id"]) prepare_context_mock.assert_called_once_with(contract_data) save_context_mock.assert_called_once_with(check_contract, contract_id, {"contract": contract_data}) self.assertEqual(send_change_xml_mock.delay.mock_calls, [ call(contract_id, contract_data["changes"][0]["id"]), call(contract_id, contract_data["changes"][1]["id"]), ])