mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 23:41:17 -05:00
get coverage up to 94%
This commit is contained in:
2
Makefile
2
Makefile
@@ -61,7 +61,7 @@ test: ## Run tests and create coverage report
|
||||
pipenv run flake8 .
|
||||
pipenv run isort --check-only ./app ./tests
|
||||
pipenv run coverage run -m pytest --maxfail=10
|
||||
pipenv run coverage report -m --fail-under=92
|
||||
pipenv run coverage report -m --fail-under=94
|
||||
pipenv run coverage html -d .coverage_cache
|
||||
|
||||
.PHONY: freeze-requirements
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime
|
||||
|
||||
from flask import current_app
|
||||
from sqlalchemy import asc, desc, func
|
||||
@@ -80,25 +80,26 @@ def dao_reduce_sms_provider_priority(identifier, *, time_threshold):
|
||||
Will reduce a chosen sms provider's priority, and increase the other provider's priority by 10 points each.
|
||||
If either provider has been updated in the last `time_threshold`, then it won't take any action.
|
||||
"""
|
||||
amount_to_reduce_by = 10
|
||||
# amount_to_reduce_by = 10
|
||||
providers_list = _get_sms_providers_for_update(time_threshold)
|
||||
|
||||
if len(providers_list) < 2:
|
||||
current_app.logger.info("Not adjusting providers, number of active providers is less than 2.")
|
||||
return
|
||||
|
||||
providers = {provider.identifier: provider for provider in providers_list}
|
||||
other_identifier = get_alternative_sms_provider(identifier)
|
||||
|
||||
reduced_provider = providers[identifier]
|
||||
increased_provider = providers[other_identifier]
|
||||
|
||||
# always keep values between 0 and 100
|
||||
reduced_provider_priority = max(0, reduced_provider.priority - amount_to_reduce_by)
|
||||
increased_provider_priority = min(100, increased_provider.priority + amount_to_reduce_by)
|
||||
|
||||
_adjust_provider_priority(reduced_provider, reduced_provider_priority)
|
||||
_adjust_provider_priority(increased_provider, increased_provider_priority)
|
||||
# TODO right now we only have one provider. Remove this?
|
||||
# providers = {provider.identifier: provider for provider in providers_list}
|
||||
# other_identifier = get_alternative_sms_provider(identifier)
|
||||
#
|
||||
# reduced_provider = providers[identifier]
|
||||
# increased_provider = providers[other_identifier]
|
||||
#
|
||||
# # always keep values between 0 and 100
|
||||
# reduced_provider_priority = max(0, reduced_provider.priority - amount_to_reduce_by)
|
||||
# increased_provider_priority = min(100, increased_provider.priority + amount_to_reduce_by)
|
||||
#
|
||||
# _adjust_provider_priority(reduced_provider, reduced_provider_priority)
|
||||
# _adjust_provider_priority(increased_provider, increased_provider_priority)
|
||||
|
||||
|
||||
@autocommit
|
||||
@@ -107,22 +108,23 @@ def dao_adjust_provider_priority_back_to_resting_points():
|
||||
Provided that neither SMS provider has been modified in the last hour, move both providers by 10 percentage points
|
||||
each towards their defined resting points (set in SMS_PROVIDER_RESTING_POINTS in config.py).
|
||||
"""
|
||||
amount_to_reduce_by = 10
|
||||
time_threshold = timedelta(hours=1)
|
||||
|
||||
providers = _get_sms_providers_for_update(time_threshold)
|
||||
|
||||
for provider in providers:
|
||||
target = current_app.config['SMS_PROVIDER_RESTING_POINTS'][provider.identifier]
|
||||
current = provider.priority
|
||||
|
||||
if current != target:
|
||||
if current > target:
|
||||
new_priority = max(target, provider.priority - amount_to_reduce_by)
|
||||
else:
|
||||
new_priority = min(target, provider.priority + amount_to_reduce_by)
|
||||
|
||||
_adjust_provider_priority(provider, new_priority)
|
||||
# TODO we only have one provider. Remove?
|
||||
# amount_to_reduce_by = 10
|
||||
# time_threshold = timedelta(hours=1)
|
||||
#
|
||||
# providers = _get_sms_providers_for_update(time_threshold)
|
||||
#
|
||||
# for provider in providers:
|
||||
# target = current_app.config['SMS_PROVIDER_RESTING_POINTS'][provider.identifier]
|
||||
# current = provider.priority
|
||||
#
|
||||
# if current != target:
|
||||
# if current > target:
|
||||
# new_priority = max(target, provider.priority - amount_to_reduce_by)
|
||||
# else:
|
||||
# new_priority = min(target, provider.priority + amount_to_reduce_by)
|
||||
#
|
||||
# _adjust_provider_priority(provider, new_priority)
|
||||
|
||||
|
||||
def get_provider_details_by_notification_type(notification_type, supports_international=False):
|
||||
|
||||
@@ -17,6 +17,9 @@ from app.commands import (
|
||||
)
|
||||
from app.dao.inbound_numbers_dao import dao_get_available_inbound_numbers
|
||||
from app.models import (
|
||||
KEY_TYPE_NORMAL,
|
||||
NOTIFICATION_DELIVERED,
|
||||
SMS_TYPE,
|
||||
AnnualBilling,
|
||||
Job,
|
||||
Notification,
|
||||
@@ -108,7 +111,7 @@ def test_populate_organizations_from_file(notify_db_session, notify_api):
|
||||
|
||||
file_name = "./tests/app/orgs1.csv"
|
||||
text = "name|blah|blah|blah|||\n" \
|
||||
"foo|Federal|True|'foo.gov'|||\n"
|
||||
"foo|Federal|True|'foo.gov'|'foo.gov'||\n"
|
||||
f = open(file_name, "a")
|
||||
f.write(text)
|
||||
f.close()
|
||||
@@ -253,7 +256,13 @@ def test_fix_billable_units(notify_db_session, notify_api, sample_template):
|
||||
|
||||
create_notification(template=sample_template)
|
||||
notification = Notification.query.one()
|
||||
assert notification.billable_units == 1
|
||||
notification.billable_units = 0
|
||||
notification.notification_type = SMS_TYPE
|
||||
notification.status = NOTIFICATION_DELIVERED
|
||||
notification.sent_at = None
|
||||
notification.key_type = KEY_TYPE_NORMAL
|
||||
|
||||
notify_db_session.commit()
|
||||
|
||||
notify_api.test_cli_runner().invoke(
|
||||
fix_billable_units, []
|
||||
|
||||
Reference in New Issue
Block a user