Cleaning up tests.

Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
Cliff Hill
2024-01-16 14:46:17 -05:00
parent 9523cc1d97
commit 8c6046b03b
33 changed files with 268 additions and 315 deletions

View File

@@ -11,12 +11,8 @@ from notifications_utils.recipients import (
)
from sqlalchemy.exc import SQLAlchemyError
from app.models import (
Notification,
NotificationHistory,
ServicePermissionType,
TemplateType,
)
from app.enums import ServicePermissionType, TemplateType
from app.models import Notification, NotificationHistory
from app.notifications.process_notifications import (
create_content_for_notification,
persist_notification,

View File

@@ -5,7 +5,8 @@ from unittest import mock
import pytest
from flask import json
from app.models import InboundSms, ServicePermissionType
from app.models import InboundSms
from app.enums import ServicePermissionType
from app.notifications.receive_notifications import (
create_inbound_sms_object,
fetch_potential_service,

View File

@@ -8,7 +8,8 @@ from notifications_python_client.authentication import create_jwt_token
from app.dao.api_key_dao import save_model_api_key
from app.dao.notifications_dao import dao_update_notification
from app.dao.templates_dao import dao_update_template
from app.models import KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST, ApiKey
from app.enums import KeyType
from app.models import ApiKey
from tests import create_service_authorization_header
from tests.app.db import create_api_key, create_notification
@@ -80,12 +81,12 @@ def test_get_notifications_empty_result(client, sample_api_key):
@pytest.mark.parametrize(
"api_key_type,notification_key_type",
[
(KEY_TYPE_NORMAL, KEY_TYPE_TEAM),
(KEY_TYPE_NORMAL, KEY_TYPE_TEST),
(KEY_TYPE_TEST, KEY_TYPE_NORMAL),
(KEY_TYPE_TEST, KEY_TYPE_TEAM),
(KEY_TYPE_TEAM, KEY_TYPE_NORMAL),
(KEY_TYPE_TEAM, KEY_TYPE_TEST),
(KeyType.NORMAL, KeyType.TEAM),
(KeyType.NORMAL, KeyType.TEST),
(KeyType.TEST, KeyType.NORMAL),
(KeyType.TEST, KeyType.TEAM),
(KeyType.TEAM, KeyType.NORMAL),
(KeyType.TEAM, KeyType.TEST),
],
)
def test_get_notification_from_different_api_key_works(
@@ -107,7 +108,7 @@ def test_get_notification_from_different_api_key_works(
assert response.status_code == 200
@pytest.mark.parametrize("key_type", [KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST])
@pytest.mark.parametrize("key_type", [KeyType.NORMAL, KeyType.TEAM, KeyType.TEST])
def test_get_notification_from_different_api_key_of_same_type_succeeds(
client, sample_notification, key_type
):
@@ -190,7 +191,7 @@ def test_normal_api_key_returns_notifications_created_from_jobs_and_from_api(
}
@pytest.mark.parametrize("key_type", [KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST])
@pytest.mark.parametrize("key_type", [KeyType.NORMAL, KeyType.TEAM, KeyType.TEST])
def test_get_all_notifications_only_returns_notifications_of_matching_type(
client,
sample_template,
@@ -200,19 +201,19 @@ def test_get_all_notifications_only_returns_notifications_of_matching_type(
key_type,
):
normal_notification = create_notification(
sample_template, api_key=sample_api_key, key_type=KEY_TYPE_NORMAL
sample_template, api_key=sample_api_key, key_type=KeyType.NORMAL
)
team_notification = create_notification(
sample_template, api_key=sample_team_api_key, key_type=KEY_TYPE_TEAM
sample_template, api_key=sample_team_api_key, key_type=KeyType.TEAM
)
test_notification = create_notification(
sample_template, api_key=sample_test_api_key, key_type=KEY_TYPE_TEST
sample_template, api_key=sample_test_api_key, key_type=KeyType.TEST
)
notification_objs = {
KEY_TYPE_NORMAL: normal_notification,
KEY_TYPE_TEAM: team_notification,
KEY_TYPE_TEST: test_notification,
KeyType.NORMAL: normal_notification,
KeyType.TEAM: team_notification,
KeyType.TEST: test_notification,
}
response = client.get(
@@ -227,13 +228,13 @@ def test_get_all_notifications_only_returns_notifications_of_matching_type(
assert notifications[0]["id"] == str(notification_objs[key_type].id)
@pytest.mark.parametrize("key_type", [KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST])
@pytest.mark.parametrize("key_type", [KeyType.NORMAL, KeyType.TEAM, KeyType.TEST])
def test_do_not_return_job_notifications_by_default(
client, sample_template, sample_job, key_type
):
team_api_key = create_api_key(sample_template.service, KEY_TYPE_TEAM)
normal_api_key = create_api_key(sample_template.service, KEY_TYPE_NORMAL)
test_api_key = create_api_key(sample_template.service, KEY_TYPE_TEST)
team_api_key = create_api_key(sample_template.service, KeyType.TEAM)
normal_api_key = create_api_key(sample_template.service, KeyType.NORMAL)
test_api_key = create_api_key(sample_template.service, KeyType.TEST)
create_notification(sample_template, job=sample_job)
normal_notification = create_notification(sample_template, api_key=normal_api_key)
@@ -241,9 +242,9 @@ def test_do_not_return_job_notifications_by_default(
test_notification = create_notification(sample_template, api_key=test_api_key)
notification_objs = {
KEY_TYPE_NORMAL: normal_notification,
KEY_TYPE_TEAM: team_notification,
KEY_TYPE_TEST: test_notification,
KeyType.NORMAL: normal_notification,
KeyType.TEAM: team_notification,
KeyType.TEST: test_notification,
}
response = client.get(
@@ -259,7 +260,7 @@ def test_do_not_return_job_notifications_by_default(
@pytest.mark.parametrize(
"key_type", [(KEY_TYPE_NORMAL, 2), (KEY_TYPE_TEAM, 1), (KEY_TYPE_TEST, 1)]
"key_type", [(KeyType.NORMAL, 2), (KeyType.TEAM, 1), (KeyType.TEST, 1)]
)
def test_only_normal_api_keys_can_return_job_notifications(
client,
@@ -271,19 +272,19 @@ def test_only_normal_api_keys_can_return_job_notifications(
key_type,
):
normal_notification = create_notification(
template=sample_template, api_key=sample_api_key, key_type=KEY_TYPE_NORMAL
template=sample_template, api_key=sample_api_key, key_type=KeyType.NORMAL
)
team_notification = create_notification(
template=sample_template, api_key=sample_team_api_key, key_type=KEY_TYPE_TEAM
template=sample_template, api_key=sample_team_api_key, key_type=KeyType.TEAM
)
test_notification = create_notification(
template=sample_template, api_key=sample_test_api_key, key_type=KEY_TYPE_TEST
template=sample_template, api_key=sample_test_api_key, key_type=KeyType.TEST
)
notification_objs = {
KEY_TYPE_NORMAL: normal_notification,
KEY_TYPE_TEAM: team_notification,
KEY_TYPE_TEST: test_notification,
KeyType.NORMAL: normal_notification,
KeyType.TEAM: team_notification,
KeyType.TEST: test_notification,
}
response = client.get(

View File

@@ -5,12 +5,7 @@ from notifications_utils import SMS_CHAR_COUNT_LIMIT
import app
from app.dao import templates_dao
from app.models import (
KEY_TYPE_NORMAL,
NotificationType,
ServicePermissionType,
TemplateType,
)
from app.enums import KeyType, NotificationType, ServicePermissionType, TemplateType
from app.notifications.process_notifications import create_content_for_notification
from app.notifications.sns_cert_validator import (
VALID_SNS_TOPICS,
@@ -783,6 +778,6 @@ def test_check_service_over_total_message_limit(mocker, sample_service):
get_redis_mock = mocker.patch("app.notifications.validators.redis_store.get")
get_redis_mock.return_value = None
service_stats = check_service_over_total_message_limit(
KEY_TYPE_NORMAL, sample_service
KeyType.NORMAL, sample_service
)
assert service_stats == 0