def test_insert_result_calls_for_valid_data(mock_data_client): mock_data_client.set_framework_result.return_value = {'on_framework': True} mock_data_client.get_supplier.return_value = {'suppliers': {'name': 'Supplier Name'}} assert insert_result(mock_data_client, 123456, 'Supplier Name', 'g-cloud-7', True, 'user') == 'OK: 123456\n' mock_data_client.set_framework_result.assert_called_with(123456, 'g-cloud-7', True, 'user')
def test_http_error_handling(mock_data_client): mock_data_client.set_framework_result.side_effect = HTTPError() mock_data_client.get_supplier.return_value = {'suppliers': {'name': 'Supplier Name'}} result = insert_result(mock_data_client, 123456, "Supplier Name", 'g-cloud-7', True, 'user') assert result == 'Error inserting result for 123456 (True): Unknown request failure in dmapiclient (status: 503)\n'
def test_insert_result_does_not_call_for_mismatched_name(mock_data_client): mock_data_client.set_framework_result.return_value = {'on_framework': True} mock_data_client.get_supplier.return_value = {'suppliers': {'name': 'Supplier Name 1'}} assert insert_result(mock_data_client, 123456, 'Supplier Name 2', 'g-cloud-7', True, 'user') == \ "Error: Supplier name 'Supplier Name 2' does not match 'Supplier Name 1' for supplier ID 123456\n" mock_data_client.set_framework_result.assert_not_called()
def test_http_error_handling(mock_data_client): mock_data_client.set_framework_result.side_effect = HTTPError() mock_data_client.get_supplier.return_value = {'suppliers': {'name': 'Supplier Name'}} result = insert_result(mock_data_client, 123456, "Supplier Name", 'g-cloud-7', True, 'user') assert result == 'Error inserting result for 123456 (True): Request failed (status: 503)\n'