TaskOrders domain class can query EDA api via client
This commit is contained in:
parent
735b9b5179
commit
42325d5a28
@ -8,12 +8,32 @@ from .exceptions import NotFoundError
|
|||||||
class TaskOrders(object):
|
class TaskOrders(object):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get(self, order_number):
|
def get(cls, order_number, client=None):
|
||||||
try:
|
try:
|
||||||
task_order = (
|
task_order = (
|
||||||
db.session.query(TaskOrder).filter_by(number=order_number).one()
|
db.session.query(TaskOrder).filter_by(number=order_number).one()
|
||||||
)
|
)
|
||||||
except NoResultFound:
|
except NoResultFound:
|
||||||
|
if client:
|
||||||
|
task_order = TaskOrders._get_from_eda(order_number, client)
|
||||||
|
else:
|
||||||
raise NotFoundError("task_order")
|
raise NotFoundError("task_order")
|
||||||
|
|
||||||
return task_order
|
return task_order
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _get_from_eda(cls, order_number, client):
|
||||||
|
to_data = client.get_contract(order_number, status="y")
|
||||||
|
if to_data:
|
||||||
|
return TaskOrders.create(to_data["contract_no"])
|
||||||
|
else:
|
||||||
|
raise NotFoundError("task_order")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create(cls, order_number):
|
||||||
|
task_order = TaskOrder(number=order_number)
|
||||||
|
|
||||||
|
db.session.add(task_order)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return task_order
|
||||||
|
@ -71,8 +71,10 @@ class MockEDAClient(EDAClientBase):
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
MOCK_CONTRACT_NUMBER = "DCA10096D0052"
|
||||||
|
|
||||||
def get_contract(self, contract_number, status):
|
def get_contract(self, contract_number, status):
|
||||||
if contract_number == "DCA10096D0052" and status == "y":
|
if contract_number == self.MOCK_CONTRACT_NUMBER and status == "y":
|
||||||
return {
|
return {
|
||||||
"aco_mod": "01",
|
"aco_mod": "01",
|
||||||
"admin_dodaac": None,
|
"admin_dodaac": None,
|
||||||
|
@ -2,6 +2,7 @@ import pytest
|
|||||||
|
|
||||||
from atst.domain.exceptions import NotFoundError
|
from atst.domain.exceptions import NotFoundError
|
||||||
from atst.domain.task_orders import TaskOrders
|
from atst.domain.task_orders import TaskOrders
|
||||||
|
from atst.eda_client import MockEDAClient
|
||||||
|
|
||||||
from tests.factories import TaskOrderFactory
|
from tests.factories import TaskOrderFactory
|
||||||
|
|
||||||
@ -13,6 +14,17 @@ def test_can_get_task_order():
|
|||||||
assert to.id == to.id
|
assert to.id == to.id
|
||||||
|
|
||||||
|
|
||||||
def test_nonexistent_task_order_raises():
|
def test_can_get_task_order_from_eda():
|
||||||
|
to = TaskOrders.get(MockEDAClient.MOCK_CONTRACT_NUMBER, client=MockEDAClient())
|
||||||
|
|
||||||
|
assert to.number == MockEDAClient.MOCK_CONTRACT_NUMBER
|
||||||
|
|
||||||
|
|
||||||
|
def test_nonexistent_task_order_raises_without_client():
|
||||||
with pytest.raises(NotFoundError):
|
with pytest.raises(NotFoundError):
|
||||||
TaskOrders.get("some fake number")
|
TaskOrders.get("some fake number")
|
||||||
|
|
||||||
|
|
||||||
|
def test_nonexistent_task_order_raises_with_client():
|
||||||
|
with pytest.raises(NotFoundError):
|
||||||
|
TaskOrders.get("some other fake numer", client=MockEDAClient())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user