mirror of
https://github.com/GSA/notifications-api.git
synced 2026-06-17 03:38:14 -04:00
Refactored code, changed now to utcnow in test
This commit is contained in:
@@ -31,7 +31,7 @@ from app.models import (
|
||||
)
|
||||
from app.service.statistics import format_monthly_template_notification_stats
|
||||
from app.statsd_decorators import statsd
|
||||
from app.utils import get_london_month_from_utc_column
|
||||
from app.utils import get_london_month_from_utc_column, get_london_midnight_in_utc
|
||||
|
||||
|
||||
def dao_fetch_all_services(only_active=False):
|
||||
@@ -324,9 +324,8 @@ def dao_fetch_todays_stats_for_all_services(include_from_test_key=True):
|
||||
|
||||
@statsd(namespace='dao')
|
||||
def fetch_stats_by_date_range_for_all_services(start_date, end_date, include_from_test_key=True):
|
||||
if not isinstance(end_date, datetime):
|
||||
end_date = datetime.combine(end_date, datetime.min.time())
|
||||
|
||||
start_date = get_london_midnight_in_utc(start_date)
|
||||
end_date = get_london_midnight_in_utc(end_date)
|
||||
end_date += timedelta(hours=23, minutes=59, seconds=59)
|
||||
|
||||
query = db.session.query(
|
||||
|
||||
@@ -53,7 +53,7 @@ from app.schemas import (
|
||||
notifications_filter_schema,
|
||||
detailed_service_schema
|
||||
)
|
||||
from app.utils import pagination_links, get_london_midnight_in_utc
|
||||
from app.utils import pagination_links
|
||||
from flask import Blueprint
|
||||
|
||||
service_blueprint = Blueprint('service', __name__)
|
||||
@@ -297,8 +297,8 @@ def get_detailed_services(start_date, end_date, only_active=False, include_from_
|
||||
stats = dao_fetch_todays_stats_for_all_services(include_from_test_key=include_from_test_key)
|
||||
else:
|
||||
|
||||
stats = fetch_stats_by_date_range_for_all_services(start_date=get_london_midnight_in_utc(start_date),
|
||||
end_date=get_london_midnight_in_utc(end_date),
|
||||
stats = fetch_stats_by_date_range_for_all_services(start_date=start_date,
|
||||
end_date=end_date,
|
||||
include_from_test_key=include_from_test_key)
|
||||
|
||||
for service_id, rows in itertools.groupby(stats, lambda x: x.service_id):
|
||||
|
||||
@@ -1401,10 +1401,10 @@ def test_get_detailed_services_for_date_range(notify_db, notify_db_session, set_
|
||||
from app.service.rest import get_detailed_services
|
||||
|
||||
with freeze_time(set_time):
|
||||
create_sample_notification(notify_db, notify_db_session, created_at=datetime.now() - timedelta(days=3))
|
||||
create_sample_notification(notify_db, notify_db_session, created_at=datetime.now() - timedelta(days=2))
|
||||
create_sample_notification(notify_db, notify_db_session, created_at=datetime.now() - timedelta(days=1))
|
||||
create_sample_notification(notify_db, notify_db_session, created_at=datetime.now())
|
||||
create_sample_notification(notify_db, notify_db_session, created_at=datetime.utcnow() - timedelta(days=3))
|
||||
create_sample_notification(notify_db, notify_db_session, created_at=datetime.utcnow() - timedelta(days=2))
|
||||
create_sample_notification(notify_db, notify_db_session, created_at=datetime.utcnow() - timedelta(days=1))
|
||||
create_sample_notification(notify_db, notify_db_session, created_at=datetime.utcnow())
|
||||
|
||||
start_date = (datetime.utcnow() - timedelta(days=2)).date()
|
||||
end_date = (datetime.utcnow() - timedelta(days=1)).date()
|
||||
|
||||
Reference in New Issue
Block a user