Skip to content

Commit

Permalink
[FIX] Fix flaky permit condition requirement test (#3349)
Browse files Browse the repository at this point in the history
* [FIX] Fix reports resource test flakiness

* Remove unused import

* [FIX] Permit condition test flakiness

* Updated permit conditions
  • Loading branch information
simensma-fresh authored Dec 16, 2024
1 parent f3fe530 commit 25bb447
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,24 @@ def find_by_condition_category_code(cls, condition_category_code):
return cls.query.filter_by(
condition_category_code=condition_category_code, deleted_ind=False
).all()

@classmethod
def find_by_permit_amendment_id_ordered(cls, permit_amendment_id):
# Returns a list of root conditions ordered by display_order
# within each parent condition, subconditions are ordered by display_order

def get_all_conditions(condition):
conditions = [condition]
for sub_condition in condition.all_sub_conditions:
if not sub_condition.deleted_ind:
conditions.extend(get_all_conditions(sub_condition))
return conditions

all_conditions = []
root_conditions = cls.query\
.filter_by(parent_permit_condition_id=None, deleted_ind=False, permit_amendment_id=permit_amendment_id)\
.order_by(cls.display_order)\
.all()
for root_condition in root_conditions:
all_conditions.extend(get_all_conditions(root_condition))
return all_conditions
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ def permit_amendment(test_client, db_session):
mine, permit = create_mine_and_permit()
permit_amendment = permit.permit_amendments[0]
PermitConditions.query.delete()
db_session.flush()

yield permit_amendment


@pytest.fixture(scope="function")
def permit_conditions(permit_amendment):
def permit_conditions(permit_amendment, db_session):
task = PermitExtractionTask(
task_result={
"conditions": [
Expand Down Expand Up @@ -128,15 +129,16 @@ def permit_conditions(permit_amendment):
create_permit_conditions_from_task(task)

# Retrieve the created permit conditions from the database
permit_conditions = PermitConditions.query.all()
permit_conditions = PermitConditions.find_by_permit_amendment_id_ordered(permit_amendment.permit_amendment_id)

return permit_conditions


def test_create_permit_conditions_from_task(
permit_conditions, permit_amendment, db_session
):
):

assert len(permit_conditions) == 7
### General Section
gen_cat = permit_conditions[0]

Expand Down

0 comments on commit 25bb447

Please sign in to comment.