fix template folder dao

This commit is contained in:
Kenneth Kehl
2024-10-14 10:28:44 -07:00
parent 1eb46b39b1
commit ef5a45d6a2
2 changed files with 32 additions and 39 deletions

View File

@@ -239,7 +239,7 @@
"filename": "tests/app/dao/test_services_dao.py", "filename": "tests/app/dao/test_services_dao.py",
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", "hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
"is_verified": false, "is_verified": false,
"line_number": 266, "line_number": 269,
"is_secret": false "is_secret": false
} }
], ],
@@ -384,5 +384,5 @@
} }
] ]
}, },
"generated_at": "2024-10-14T16:21:01Z" "generated_at": "2024-10-14T17:28:40Z"
} }

View File

@@ -103,7 +103,8 @@ def test_create_service(notify_db_session):
) )
dao_create_service(service, user) dao_create_service(service, user)
assert service_query_count() == 1 assert service_query_count() == 1
service_db = Service.query.one() stmt = select(Service)
service_db = db.session.execute(stmt).scalars().one()
assert service_db.name == "service_name" assert service_db.name == "service_name"
assert service_db.id == service.id assert service_db.id == service.id
assert service_db.email_from == "email_from" assert service_db.email_from == "email_from"
@@ -132,7 +133,8 @@ def test_create_service_with_organization(notify_db_session):
) )
dao_create_service(service, user) dao_create_service(service, user)
assert service_query_count() == 1 assert service_query_count() == 1
service_db = Service.query.one() stmt = select(Service)
service_db = db.session.execute(stmt).scalars().one()
organization = db.session.get(Organization, organization.id) organization = db.session.get(Organization, organization.id)
assert service_db.name == "service_name" assert service_db.name == "service_name"
assert service_db.id == service.id assert service_db.id == service.id
@@ -163,7 +165,8 @@ def test_fetch_service_by_id_with_api_keys(notify_db_session):
) )
dao_create_service(service, user) dao_create_service(service, user)
assert service_query_count() == 1 assert service_query_count() == 1
service_db = Service.query.one() stmt = select(Service)
service_db = db.session.execute(stmt).scalars().one()
organization = db.session.get(Organization, organization.id) organization = db.session.get(Organization, organization.id)
assert service_db.name == "service_name" assert service_db.name == "service_name"
assert service_db.id == service.id assert service_db.id == service.id
@@ -385,11 +388,12 @@ def test_should_remove_user_from_service_exception(notify_db_session):
def test_removing_a_user_from_a_service_deletes_their_permissions( def test_removing_a_user_from_a_service_deletes_their_permissions(
sample_user, sample_service sample_user, sample_service
): ):
assert len(Permission.query.all()) == 7 stmt = select(Permission)
assert len(db.session.execute(stmt).scalars().all()) == 7
dao_remove_user_from_service(sample_service, sample_user) dao_remove_user_from_service(sample_service, sample_user)
assert Permission.query.all() == [] assert db.session.execute(stmt).scalars().all() == []
def test_removing_a_user_from_a_service_deletes_their_folder_permissions_for_that_service( def test_removing_a_user_from_a_service_deletes_their_folder_permissions_for_that_service(
@@ -685,7 +689,9 @@ def test_create_service_creates_a_history_record_with_current_data(notify_db_ses
assert service_history_query_count() == 1 assert service_history_query_count() == 1
service_from_db = service_query_first() service_from_db = service_query_first()
service_history = Service.get_history_model().query.first() stmt = select(Service.get_history_model())
service_history = db.session.execute(stmt).scalars().first()
assert service_from_db.id == service_history.id assert service_from_db.id == service_history.id
assert service_from_db.name == service_history.name assert service_from_db.name == service_history.name
@@ -737,17 +743,10 @@ def test_update_service_creates_a_history_record_with_current_data(notify_db_ses
assert service_from_db.version == 2 assert service_from_db.version == 2
assert ( stmt = select(Service.get_history_model()).filter_by(name="service_name")
Service.get_history_model().query.filter_by(name="service_name").one().version assert db.session.execute(stmt).scalars().one().version == 1
== 1 stmt = select(Service.get_history_model()).filter_by(name="updated_service_name")
) assert db.session.execute(stmt).scalars().one().version == 2
assert (
Service.get_history_model()
.query.filter_by(name="updated_service_name")
.one()
.version
== 2
)
def test_update_service_permission_creates_a_history_record_with_current_data( def test_update_service_permission_creates_a_history_record_with_current_data(
@@ -815,12 +814,12 @@ def test_update_service_permission_creates_a_history_record_with_current_data(
), ),
) )
history = ( stmt = (
Service.get_history_model() select(Service.get_history_model())
.query.filter_by(name="service_name") .filter_by(name="service_name")
.order_by("version") .order_by("version")
.all()
) )
history = db.session.execute(stmt).scalars().all()
assert len(history) == 3 assert len(history) == 3
assert history[2].version == 3 assert history[2].version == 3
@@ -926,9 +925,8 @@ def test_add_existing_user_to_another_service_doesnot_change_old_permissions(
dao_create_service(service_one, user) dao_create_service(service_one, user)
assert user.id == service_one.users[0].id assert user.id == service_one.users[0].id
test_user_permissions = Permission.query.filter_by( stmt = select(Permission).filter_by(service=service_one, user=user)
service=service_one, user=user test_user_permissions = db.session.execute(stmt).scalars().all()
).all()
assert len(test_user_permissions) == 7 assert len(test_user_permissions) == 7
other_user = User( other_user = User(
@@ -948,14 +946,11 @@ def test_add_existing_user_to_another_service_doesnot_change_old_permissions(
dao_create_service(service_two, other_user) dao_create_service(service_two, other_user)
assert other_user.id == service_two.users[0].id assert other_user.id == service_two.users[0].id
other_user_permissions = Permission.query.filter_by( stmt = select(Permission).filter_by(service=service_two, user=other_user)
service=service_two, user=other_user other_user_permissions = db.session.execute(stmt).scalars().all()
).all()
assert len(other_user_permissions) == 7 assert len(other_user_permissions) == 7
stmt = select(Permission).filter_by(service=service_one, user=other_user)
other_user_service_one_permissions = Permission.query.filter_by( other_user_service_one_permissions = db.session.execute(stmt).scalars().all()
service=service_one, user=other_user
).all()
assert len(other_user_service_one_permissions) == 0 assert len(other_user_service_one_permissions) == 0
# adding the other_user to service_one should leave all other_user permissions on service_two intact # adding the other_user to service_one should leave all other_user permissions on service_two intact
@@ -965,14 +960,12 @@ def test_add_existing_user_to_another_service_doesnot_change_old_permissions(
dao_add_user_to_service(service_one, other_user, permissions=permissions) dao_add_user_to_service(service_one, other_user, permissions=permissions)
other_user_service_one_permissions = Permission.query.filter_by( stmt = select(Permission).filter_by(service=service_one, user=other_user)
service=service_one, user=other_user other_user_service_one_permissions = db.session.execute(stmt).scalars().all()
).all()
assert len(other_user_service_one_permissions) == 2 assert len(other_user_service_one_permissions) == 2
other_user_service_two_permissions = Permission.query.filter_by( stmt = select(Permission).filter_by(service=service_two, user=other_user)
service=service_two, user=other_user other_user_service_two_permissions = db.session.execute(stmt).scalars().all()
).all()
assert len(other_user_service_two_permissions) == 7 assert len(other_user_service_two_permissions) == 7