Improving tests a little.

Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
Cliff Hill
2023-11-20 12:31:57 -05:00
parent 33c16bdd1e
commit d1dec155b6
3 changed files with 25 additions and 10 deletions

View File

@@ -434,6 +434,18 @@ class Organization(db.Model):
def domain_list(self): def domain_list(self):
return [domain.domain for domain in self.domains] return [domain.domain for domain in self.domains]
@property
def agreement(self):
try:
active_agreements = [
agreement
for agreement in self.agreements
if agreement.status == AgreementStatus.ACTIVE
]
return active_agreements[0]
except IndexError:
return None
@property @property
def is_active(self): def is_active(self):
return self.agreement and self.agreement.status == AgreementStatus.active return self.agreement and self.agreement.status == AgreementStatus.active

View File

@@ -9,17 +9,18 @@ from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
revision = '0405_adjust_agreement_model' revision = "0405_adjust_agreement_model"
down_revision = '0404_expire_invites' down_revision = "0404_expire_invites"
agreement_type_name = 'agreement_types' agreement_type_name = "agreement_types"
agreement_type_options = ("MOU", "IAA") agreement_type_options = ("MOU", "IAA")
agreement_types = sa.Enum(*agreement_type_options, name=agreement_type_name) agreement_types = sa.Enum(*agreement_type_options, name=agreement_type_name)
agreement_status_name = 'agreement_statuses' agreement_status_name = "agreement_statuses"
agreement_status_options = ("active", "expired") agreement_status_options = ("active", "expired")
agreement_statuses = sa.Enum(*agreement_status_options, name=agreement_status_name) agreement_statuses = sa.Enum(*agreement_status_options, name=agreement_status_name)
def upgrade(): def upgrade():
agreement_types.create(op.get_bind()) agreement_types.create(op.get_bind())
op.execute( op.execute(
@@ -34,8 +35,8 @@ def upgrade():
def downgrade(): def downgrade():
op.alter_column( op.alter_column(
'agreements', "agreements",
'status', "status",
existing_type=agreement_statuses, existing_type=agreement_statuses,
type_=sa.VARCHAR(length=255), type_=sa.VARCHAR(length=255),
existing_nullable=False, existing_nullable=False,
@@ -43,8 +44,8 @@ def downgrade():
op.execute(f"DROP TYPE {agreement_status_name}") op.execute(f"DROP TYPE {agreement_status_name}")
op.alter_column( op.alter_column(
'agreements', "agreements",
'type', "type",
existing_type=agreement_types, existing_type=agreement_types,
type_=sa.VARCHAR(length=3), type_=sa.VARCHAR(length=3),
existing_nullable=False, existing_nullable=False,

View File

@@ -133,16 +133,18 @@ def test_should_delete_all_invitations_more_than_one_day_old(
def test_should_not_delete_invitations_less_than_two_days_old( def test_should_not_delete_invitations_less_than_two_days_old(
sample_user, sample_service sample_user, sample_service
): ):
two_days = timedelta(days=2)
one_second = timedelta(seconds=1)
make_invitation( make_invitation(
sample_user, sample_user,
sample_service, sample_service,
age=timedelta(hours=47, minutes=59, seconds=59), age=two_days - one_second, # Not quite two days
email_address="valid@2.com", email_address="valid@2.com",
) )
make_invitation( make_invitation(
sample_user, sample_user,
sample_service, sample_service,
age=timedelta(hours=48), age=two_days,
email_address="expired@1.com", email_address="expired@1.com",
) )