Commit cab38f58 authored by Ruben.Havre's avatar Ruben.Havre
Browse files

Merge branch 'SETRA-92' into 'master'

SETRA-92: Added methods to check if batch can be deleted, and to delete batch

See merge request !71
parents 9c5df969 3210311e
Pipeline #103443 passed with stage
in 10 minutes and 11 seconds
......@@ -360,6 +360,12 @@ def m_test_save_transaction_without_transaction_service(client):
assert tx_error.value.args[0] == "Transaction API is not configured"
def m_test_check_if_can_delete_batch_input_without_transaction_service(client):
with pytest.raises(ClientError) as tx_error:
client.check_if_can_delete_batch_input("batch_id", "interface_id")
assert tx_error.value.args[0] == "Transaction API is not configured"
def m_test_get_transaction_status_without_import_service(client):
with pytest.raises(ClientError) as imp_error:
client.get_transaction_status("GA07", 1)
......
......@@ -23,6 +23,30 @@ def test_save_transactions(service_config):
assert resp.batch_id is not None
@pytest.mark.integration
def test_check_if_can_delete_batch_input(service_config):
client = get_client(**service_config)
resp = client.check_if_can_delete_batch_input("19102820", "FA")
assert resp is not None
assert resp is True
@pytest.mark.integration
def test_check_if_can_delete_batch_input_2(service_config):
client = get_client(**service_config)
resp = client.check_if_can_delete_batch_input("UL0000030", "UL")
assert resp is not None
assert resp is True
@pytest.mark.integration
def test_check_if_can_delete_non_existing_batch_input(service_config):
client = get_client(**service_config)
resp = client.check_if_can_delete_batch_input("UL0001111", "UL")
assert resp is not None
assert resp is False
@pytest.mark.integration
def test_get_status_for_existing_transactions(service_config):
client = get_client(**service_config)
......
......@@ -372,6 +372,60 @@ class UBWClient:
else:
return client, client.service
def check_if_can_delete_batch_input(self, batch_id: str, interface_id: str) -> bool:
if not (self.transaction_client and self.transaction_service):
raise ClientError("Transaction API is not configured")
logger.info(
"Checking if we can delete batch input for batchid,interface: %s, %s",
batch_id,
interface_id,
)
try:
req = self.transaction_service.CanDeleteBatchInput(
batchId=batch_id,
interfaceId=interface_id,
credentials=dict(self.config.transaction_service.credentials),
)
except zeep.exceptions.Fault as e:
logger.warning("Ubw-client error: %s", e.code)
raise ClientError(e.code) from e
logger.info("Received the following from ubw api: %s", req)
# Response data contains string with either
# "400, NoRowsToDelete" or "200, CanDeleteRows"
if len(req) > 3 and req.startswith("200"):
return True
return False
def delete_batch_input(self, batch_id: str, interface_id: str) -> bool:
if not (self.transaction_client and self.transaction_service):
raise ClientError("Transaction API is not configured")
logger.info(
"Requesting to delete batch input for batchid,interface: %s, %s",
batch_id,
interface_id,
)
try:
req = self.transaction_service.DeleteBatchInput(
batchId=batch_id,
interfaceId=interface_id,
credentials=dict(self.config.transaction_service.credentials),
)
except zeep.exceptions.Fault as e:
logger.warning("Ubw-client error: %s", e.code)
raise ClientError(e.code) from e
logger.info("Received the following from ubw api: %s", req)
# Response data contains either
# "200 Operation succeeded" or "400 Operation failed"
if len(req) > 3 and req.startswith("200"):
return True
return False
def save_transactions(
self,
transactions: models.Transactions,
......@@ -380,7 +434,7 @@ class UBWClient:
period: int,
batch_id: str,
) -> models.SaveTransactionResponse:
if not self.transaction_client and not self.transaction_service:
if not (self.transaction_client and self.transaction_service):
raise ClientError("Transaction API is not configured")
batch_inputs = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment