Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Kehl committed Nov 15, 2024
1 parent 5c6a5f9 commit 5f4da49
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .ds.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,15 @@
"filename": "tests/app/user/test_rest.py",
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
"is_verified": false,
"line_number": 108,
"line_number": 110,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "tests/app/user/test_rest.py",
"hashed_secret": "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33",
"is_verified": false,
"line_number": 850,
"line_number": 858,
"is_secret": false
}
],
Expand Down Expand Up @@ -384,5 +384,5 @@
}
]
},
"generated_at": "2024-11-15T16:25:55Z"
"generated_at": "2024-11-15T18:43:06Z"
}
66 changes: 51 additions & 15 deletions tests/app/celery/test_reporting_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ def test_create_nightly_billing_for_day_sms_rate_multiplier(
assert len(records) == 0

create_nightly_billing_for_day(str(yesterday.date()))
records = FactBilling.query.order_by("rate_multiplier").all()
records = (
db.session.execute(select(FactBilling).order_by("rate_multiplier"))
.scalars()
.all()
)
assert len(records) == records_num

for i, record in enumerate(records):
Expand Down Expand Up @@ -232,7 +236,11 @@ def test_create_nightly_billing_for_day_different_templates(
assert len(records) == 0
create_nightly_billing_for_day(str(yesterday.date()))

records = FactBilling.query.order_by("rate_multiplier").all()
records = (
db.session.execute(select(FactBilling).order_by("rate_multiplier"))
.query()
.all()
)
assert len(records) == 2
multiplier = [0, 1]
billable_units = [0, 1]
Expand Down Expand Up @@ -276,7 +284,11 @@ def test_create_nightly_billing_for_day_same_sent_by(
assert len(records) == 0
create_nightly_billing_for_day(str(yesterday.date()))

records = FactBilling.query.order_by("rate_multiplier").all()
records = (
db.session.execute(select(FactBilling).order_by("rate_multiplier"))
.scalars()
.all()
)
assert len(records) == 1

for _, record in enumerate(records):
Expand Down Expand Up @@ -371,7 +383,11 @@ def test_create_nightly_billing_for_day_use_BST(
assert count == 0

create_nightly_billing_for_day("2018-03-25")
records = FactBilling.query.order_by(FactBilling.local_date).all()
records = (
db.session.execute(select(FactBilling).order_by(FactBilling.local_date))
.scalars()
.all()
)

assert len(records) == 1
assert records[0].local_date == date(2018, 3, 25)
Expand All @@ -398,7 +414,11 @@ def test_create_nightly_billing_for_day_update_when_record_exists(
assert len(records) == 0

create_nightly_billing_for_day("2018-01-14")
records = FactBilling.query.order_by(FactBilling.local_date).all()
records = (
db.session.execute(select(FactBilling).order_by(FactBilling.local_date))
.scalars()
.all()
)

assert len(records) == 1
assert records[0].local_date == date(2018, 1, 14)
Expand Down Expand Up @@ -477,10 +497,16 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio
NotificationType.EMAIL,
)

new_fact_data = FactNotificationStatus.query.order_by(
FactNotificationStatus.notification_type,
FactNotificationStatus.notification_status,
).all()
new_fact_data = (
db.session.execute(
select(FactNotificationStatus).order_by(
FactNotificationStatus.notification_type,
FactNotificationStatus.notification_status,
)
)
.scalars()
.all()
)

assert len(new_fact_data) == 4

Expand Down Expand Up @@ -555,9 +581,15 @@ def test_create_nightly_notification_status_for_service_and_day_overwrites_old_d
NotificationType.SMS,
)

updated_fact_data = FactNotificationStatus.query.order_by(
FactNotificationStatus.notification_status
).all()
updated_fact_data = (
db.session.execute(
select(FactNotificationStatus).order_by(
FactNotificationStatus.notification_status
)
)
.scalars()
.all()
)

assert len(updated_fact_data) == 2
assert updated_fact_data[0].notification_count == 1
Expand Down Expand Up @@ -600,9 +632,13 @@ def test_create_nightly_notification_status_for_service_and_day_respects_bst(
NotificationType.SMS,
)

noti_status = FactNotificationStatus.query.order_by(
FactNotificationStatus.local_date
).all()
noti_status = (
db.session.execute(
select(FactNotificationStatus).order_by(FactNotificationStatus.local_date)
)
.scalars()
.all()
)
assert len(noti_status) == 1

assert noti_status[0].local_date == date(2019, 4, 1)
Expand Down
10 changes: 6 additions & 4 deletions tests/app/provider_details/test_rest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest
from flask import json
from freezegun import freeze_time
from sqlalchemy import select

from app import db
from app.models import ProviderDetails, ProviderDetailsHistory
from tests import create_admin_authorization_header
from tests.app.db import create_ft_billing
Expand Down Expand Up @@ -53,7 +55,7 @@ def test_get_provider_contains_correct_fields(client, sample_template):


def test_should_be_able_to_update_status(client, restore_provider_details):
provider = ProviderDetails.query.first()
provider = db.session.execute(select(ProviderDetails)).scalars().first()

update_resp_1 = client.post(
"/provider-details/{}".format(provider.id),
Expand All @@ -76,7 +78,7 @@ def test_should_be_able_to_update_status(client, restore_provider_details):
def test_should_not_be_able_to_update_disallowed_fields(
client, restore_provider_details, field, value
):
provider = ProviderDetails.query.first()
provider = db.session.execute(select(ProviderDetails)).scalars().first()

resp = client.post(
"/provider-details/{}".format(provider.id),
Expand All @@ -94,7 +96,7 @@ def test_should_not_be_able_to_update_disallowed_fields(


def test_get_provider_versions_contains_correct_fields(client, notify_db_session):
provider = ProviderDetailsHistory.query.first()
provider = db.session.execute(select(ProviderDetailsHistory)).scalars().first()
response = client.get(
"/provider-details/{}/versions".format(provider.id),
headers=[create_admin_authorization_header()],
Expand All @@ -117,7 +119,7 @@ def test_get_provider_versions_contains_correct_fields(client, notify_db_session
def test_update_provider_should_store_user_id(
client, restore_provider_details, sample_user
):
provider = ProviderDetails.query.first()
provider = db.session.execute(select(ProviderDetails)).scalars().first()

update_resp_1 = client.post(
"/provider-details/{}".format(provider.id),
Expand Down
18 changes: 13 additions & 5 deletions tests/app/user/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
from flask import current_app
from freezegun import freeze_time
from sqlalchemy import func, select
from sqlalchemy import delete, func, select

from app import db
from app.dao.service_user_dao import dao_get_service_user, dao_update_service_user
Expand Down Expand Up @@ -101,7 +101,9 @@ def test_post_user(admin_request, notify_db_session):
"""
Tests POST endpoint '/' to create a user.
"""
User.query.delete()
db.session.execute(delete(User))
db.session.commit()

data = {
"name": "Test User",
"email_address": "[email protected]",
Expand Down Expand Up @@ -129,7 +131,9 @@ def test_post_user(admin_request, notify_db_session):


def test_post_user_without_auth_type(admin_request, notify_db_session):
User.query.delete()

db.session.execute(delete(User))
db.session.commit()
data = {
"name": "Test User",
"email_address": "[email protected]",
Expand All @@ -155,7 +159,9 @@ def test_post_user_missing_attribute_email(admin_request, notify_db_session):
"""
Tests POST endpoint '/' missing attribute email.
"""
User.query.delete()

db.session.execute(delete(User))
db.session.commit()
data = {
"name": "Test User",
"password": "password",
Expand All @@ -182,7 +188,9 @@ def test_create_user_missing_attribute_password(admin_request, notify_db_session
"""
Tests POST endpoint '/' missing attribute password.
"""
User.query.delete()

db.session.execute(delete(User))
db.session.commit()
data = {
"name": "Test User",
"email_address": "[email protected]",
Expand Down

0 comments on commit 5f4da49

Please sign in to comment.