Update seed sample to create multiple task orders for each portfolio
This commit is contained in:
parent
1cd015a862
commit
e41f01398c
@ -14,7 +14,14 @@ from atst.domain.applications import Applications
|
||||
from atst.domain.portfolio_roles import PortfolioRoles
|
||||
from atst.models.invitation import Status as InvitationStatus
|
||||
from atst.domain.exceptions import AlreadyExistsError
|
||||
from tests.factories import RequestFactory, LegacyTaskOrderFactory, InvitationFactory
|
||||
from tests.factories import (
|
||||
InvitationFactory,
|
||||
RequestFactory,
|
||||
TaskOrderFactory,
|
||||
random_future_date,
|
||||
random_past_date,
|
||||
random_task_order_number,
|
||||
)
|
||||
from atst.routes.dev import _DEV_USERS as DEV_USERS
|
||||
|
||||
PORTFOLIO_USERS = [
|
||||
@ -88,25 +95,6 @@ def seed_db():
|
||||
users.append(user)
|
||||
|
||||
for user in users:
|
||||
if Requests.get_many(creator=user):
|
||||
continue
|
||||
|
||||
requests = []
|
||||
for dollar_value in [1, 200, 3000, 40000, 500_000, 1_000_000]:
|
||||
request = RequestFactory.build(creator=user)
|
||||
request.latest_revision.dollar_value = dollar_value
|
||||
db.session.add(request)
|
||||
db.session.commit()
|
||||
|
||||
Requests.submit(request)
|
||||
requests.append(request)
|
||||
|
||||
request = requests[0]
|
||||
request.legacy_task_order = LegacyTaskOrderFactory.build()
|
||||
request = Requests.update(
|
||||
request.id, {"financial_verification": RequestFactory.mock_financial_data()}
|
||||
)
|
||||
|
||||
portfolio = Portfolios.create(
|
||||
user, name="{}'s portfolio".format(user.first_name)
|
||||
)
|
||||
@ -122,6 +110,30 @@ def seed_db():
|
||||
)
|
||||
db.session.add(invitation)
|
||||
|
||||
[expired_start, expired_end] = sorted(
|
||||
[
|
||||
random_past_date(year_max=2, year_min=1),
|
||||
random_past_date(year_max=1, year_min=1),
|
||||
]
|
||||
)
|
||||
active_start = expired_end
|
||||
active_end = random_future_date(year_min=1, year_max=1)
|
||||
|
||||
date_ranges = [(expired_start, expired_end), (active_start, active_end)]
|
||||
for (start_date, end_date) in date_ranges:
|
||||
task_order = TaskOrderFactory.build(
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
number=random_task_order_number(),
|
||||
portfolio=portfolio,
|
||||
)
|
||||
db.session.add(task_order)
|
||||
|
||||
pending_task_order = TaskOrderFactory.build(
|
||||
start_date=None, end_date=None, number=None, portfolio=portfolio
|
||||
)
|
||||
db.session.add(pending_task_order)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
Applications.create(
|
||||
|
@ -42,6 +42,10 @@ def random_phone_number():
|
||||
return "".join(random.choices(string.digits, k=10))
|
||||
|
||||
|
||||
def random_task_order_number():
|
||||
return "-".join([str(random.randint(100, 999)) for _ in range(4)])
|
||||
|
||||
|
||||
def random_past_date(year_min=1, year_max=5):
|
||||
return _random_date(year_min, year_max, operator.sub)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user