Add active & expired task order statuses
This commit is contained in:
parent
c8174bdc10
commit
8f8e7fa65e
@ -1,5 +1,6 @@
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
import pendulum
|
||||||
from sqlalchemy import Column, Numeric, String, ForeignKey, Date, Integer
|
from sqlalchemy import Column, Numeric, String, ForeignKey, Date, Integer
|
||||||
from sqlalchemy.types import ARRAY
|
from sqlalchemy.types import ARRAY
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
@ -9,6 +10,8 @@ from atst.models import Base, types, mixins
|
|||||||
|
|
||||||
class Status(Enum):
|
class Status(Enum):
|
||||||
PENDING = "Pending"
|
PENDING = "Pending"
|
||||||
|
ACTIVE = "Active"
|
||||||
|
EXPIRED = "Expired"
|
||||||
|
|
||||||
|
|
||||||
class TaskOrder(Base, mixins.TimestampsMixin):
|
class TaskOrder(Base, mixins.TimestampsMixin):
|
||||||
@ -69,9 +72,21 @@ class TaskOrder(Base, mixins.TimestampsMixin):
|
|||||||
number = Column(String, unique=True) # Task Order Number
|
number = Column(String, unique=True) # Task Order Number
|
||||||
loa = Column(ARRAY(String)) # Line of Accounting (LOA)
|
loa = Column(ARRAY(String)) # Line of Accounting (LOA)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_submitted(self):
|
||||||
|
return self.number is not None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def status(self):
|
def status(self):
|
||||||
return Status.PENDING
|
if self.is_submitted:
|
||||||
|
now = pendulum.now().date()
|
||||||
|
if self.start_date > now:
|
||||||
|
return Status.PENDING
|
||||||
|
elif self.end_date < now:
|
||||||
|
return Status.EXPIRED
|
||||||
|
return Status.ACTIVE
|
||||||
|
else:
|
||||||
|
return Status.PENDING
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def budget(self):
|
def budget(self):
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import operator
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import factory
|
import factory
|
||||||
@ -41,14 +42,22 @@ def random_phone_number():
|
|||||||
return "".join(random.choices(string.digits, k=10))
|
return "".join(random.choices(string.digits, k=10))
|
||||||
|
|
||||||
|
|
||||||
|
def random_past_date(year_min=1, year_max=5):
|
||||||
|
return _random_date(year_min, year_max, operator.sub)
|
||||||
|
|
||||||
|
|
||||||
def random_future_date(year_min=1, year_max=5):
|
def random_future_date(year_min=1, year_max=5):
|
||||||
|
return _random_date(year_min, year_max, operator.add)
|
||||||
|
|
||||||
|
|
||||||
|
def _random_date(year_min, year_max, operation):
|
||||||
if year_min == year_max:
|
if year_min == year_max:
|
||||||
inc = year_min
|
inc = year_min
|
||||||
else:
|
else:
|
||||||
inc = random.randrange(year_min, year_max)
|
inc = random.randrange(year_min, year_max)
|
||||||
|
|
||||||
return datetime.date(
|
return datetime.date(
|
||||||
datetime.date.today().year + inc,
|
operation(datetime.date.today().year, inc),
|
||||||
random.randrange(1, 12),
|
random.randrange(1, 12),
|
||||||
random.randrange(1, 28),
|
random.randrange(1, 28),
|
||||||
)
|
)
|
||||||
|
@ -1,9 +1,37 @@
|
|||||||
from atst.models.task_order import TaskOrder, Status
|
from atst.models.task_order import TaskOrder, Status
|
||||||
|
|
||||||
|
from tests.factories import random_future_date, random_past_date
|
||||||
|
|
||||||
def test_default_status():
|
|
||||||
|
class TestTaskOrderStatus:
|
||||||
|
|
||||||
|
def test_pending_status(self):
|
||||||
|
to = TaskOrder()
|
||||||
|
assert to.status == Status.PENDING
|
||||||
|
|
||||||
|
to = TaskOrder(number='42', start_date=random_future_date())
|
||||||
|
assert to.status == Status.PENDING
|
||||||
|
|
||||||
|
def test_active_status(self):
|
||||||
|
to = TaskOrder(
|
||||||
|
number='42',
|
||||||
|
start_date=random_past_date(),
|
||||||
|
end_date=random_future_date(),
|
||||||
|
)
|
||||||
|
assert to.status == Status.ACTIVE
|
||||||
|
|
||||||
|
def test_expired_status(self):
|
||||||
|
to = TaskOrder(
|
||||||
|
number='42',
|
||||||
|
start_date=random_past_date(),
|
||||||
|
end_date=random_past_date(),
|
||||||
|
)
|
||||||
|
assert to.status == Status.EXPIRED
|
||||||
|
|
||||||
|
|
||||||
|
def test_is_submitted():
|
||||||
to = TaskOrder()
|
to = TaskOrder()
|
||||||
assert to.status == Status.PENDING
|
assert not to.is_submitted
|
||||||
|
|
||||||
with_args = TaskOrder(number="42")
|
to = TaskOrder(number='42')
|
||||||
assert to.status == Status.PENDING
|
assert to.is_submitted
|
||||||
|
Loading…
x
Reference in New Issue
Block a user