mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-05 18:18:25 -04:00
clean log messages
This commit is contained in:
@@ -401,7 +401,9 @@ def get_job_partials(job):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if request.referrer is not None:
|
if request.referrer is not None:
|
||||||
session["arrived_from_preview_page"] = ("check" in request.referrer) or ("help=0" in request.referrer)
|
session["arrived_from_preview_page"] = ("check" in request.referrer) or (
|
||||||
|
"help=0" in request.referrer
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
session["arrived_from_preview_page"] = False
|
session["arrived_from_preview_page"] = False
|
||||||
|
|
||||||
|
|||||||
@@ -6,17 +6,36 @@ from app.notify_client import NotifyAdminAPIClient
|
|||||||
|
|
||||||
class BillingAPIClient(NotifyAdminAPIClient):
|
class BillingAPIClient(NotifyAdminAPIClient):
|
||||||
def get_monthly_usage_for_service(self, service_id, year):
|
def get_monthly_usage_for_service(self, service_id, year):
|
||||||
return self.get(
|
monthly_usage = redis_client.get(f"monthly-usage-summary-{service_id}-{year}")
|
||||||
|
if monthly_usage is not None:
|
||||||
|
return json.loads(monthly_usage.decode("utf-8"))
|
||||||
|
result = self.get(
|
||||||
"/service/{0}/billing/monthly-usage".format(service_id),
|
"/service/{0}/billing/monthly-usage".format(service_id),
|
||||||
params=dict(year=year),
|
params=dict(year=year),
|
||||||
)
|
)
|
||||||
|
redis_client.set(
|
||||||
|
f"monthly-usage-summary-{service_id}-{year}",
|
||||||
|
json.dumps(result),
|
||||||
|
ex=30,
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
|
||||||
def get_annual_usage_for_service(self, service_id, year=None):
|
def get_annual_usage_for_service(self, service_id, year=None):
|
||||||
return self.get(
|
annual_usage = redis_client.get(f"yearly-usage-summary-{service_id}-{year}")
|
||||||
|
if annual_usage is not None:
|
||||||
|
return json.loads(annual_usage.decode("utf-8"))
|
||||||
|
result = self.get(
|
||||||
"/service/{0}/billing/yearly-usage-summary".format(service_id),
|
"/service/{0}/billing/yearly-usage-summary".format(service_id),
|
||||||
params=dict(year=year),
|
params=dict(year=year),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
redis_client.set(
|
||||||
|
f"yearly-usage-summary-{service_id}-{year}",
|
||||||
|
json.dumps(result),
|
||||||
|
ex=30,
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
|
||||||
def get_free_sms_fragment_limit_for_year(self, service_id, year=None):
|
def get_free_sms_fragment_limit_for_year(self, service_id, year=None):
|
||||||
frag_limit = redis_client.get(f"free-sms-fragment-limit-{service_id}-{year}")
|
frag_limit = redis_client.get(f"free-sms-fragment-limit-{service_id}-{year}")
|
||||||
if frag_limit is not None:
|
if frag_limit is not None:
|
||||||
@@ -48,13 +67,28 @@ class BillingAPIClient(NotifyAdminAPIClient):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_data_for_billing_report(self, start_date, end_date):
|
def get_data_for_billing_report(self, start_date, end_date):
|
||||||
return self.get(
|
x_start_date = str(start_date)
|
||||||
|
x_start_date = x_start_date.replace(" ", "_")
|
||||||
|
x_end_date = str(end_date)
|
||||||
|
x_end_date = x_end_date.replace(" ", "_")
|
||||||
|
billing_data = redis_client.get(
|
||||||
|
f"get-data-for-billing-report-{x_start_date}-{x_end_date}"
|
||||||
|
)
|
||||||
|
if billing_data is not None:
|
||||||
|
return json.loads(billing_data.decode("utf-8"))
|
||||||
|
result = self.get(
|
||||||
url="/platform-stats/data-for-billing-report",
|
url="/platform-stats/data-for-billing-report",
|
||||||
params={
|
params={
|
||||||
"start_date": str(start_date),
|
"start_date": str(start_date),
|
||||||
"end_date": str(end_date),
|
"end_date": str(end_date),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
redis_client.set(
|
||||||
|
f"get-data-for-billing-report-{x_start_date}-{x_end_date}",
|
||||||
|
json.dumps(result),
|
||||||
|
ex=30,
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
|
||||||
def get_data_for_volumes_by_service_report(self, start_date, end_date):
|
def get_data_for_volumes_by_service_report(self, start_date, end_date):
|
||||||
return self.get(
|
return self.get(
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
from app.extensions import redis_client
|
||||||
from app.notify_client import NotifyAdminAPIClient, _attach_current_user
|
from app.notify_client import NotifyAdminAPIClient, _attach_current_user
|
||||||
|
|
||||||
|
|
||||||
@@ -41,7 +44,7 @@ class NotificationApiClient(NotifyAdminAPIClient):
|
|||||||
if job_id:
|
if job_id:
|
||||||
return method(
|
return method(
|
||||||
url="/service/{}/job/{}/notifications".format(service_id, job_id),
|
url="/service/{}/job/{}/notifications".format(service_id, job_id),
|
||||||
**kwargs
|
**kwargs,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if limit_days is not None:
|
if limit_days is not None:
|
||||||
@@ -96,9 +99,20 @@ class NotificationApiClient(NotifyAdminAPIClient):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_notification_count_for_job_id(self, *, service_id, job_id):
|
def get_notification_count_for_job_id(self, *, service_id, job_id):
|
||||||
return self.get(
|
counts = redis_client.get(
|
||||||
|
f"notification-count-for-job-id-{service_id}-{job_id}"
|
||||||
|
)
|
||||||
|
if counts is not None:
|
||||||
|
return json.loads(counts.decode("utf-8"))
|
||||||
|
result = self.get(
|
||||||
url="/service/{}/job/{}/notification_count".format(service_id, job_id)
|
url="/service/{}/job/{}/notification_count".format(service_id, job_id)
|
||||||
)["count"]
|
)
|
||||||
|
redis_client.set(
|
||||||
|
f"notification-count-for-job-id-{service_id}-{job_id}",
|
||||||
|
json.dumps(result["count"]),
|
||||||
|
ex=30,
|
||||||
|
)
|
||||||
|
return result["count"]
|
||||||
|
|
||||||
|
|
||||||
notification_api_client = NotificationApiClient()
|
notification_api_client = NotificationApiClient()
|
||||||
|
|||||||
@@ -141,8 +141,15 @@ def test_get_notification(mocker):
|
|||||||
|
|
||||||
def test_get_notification_count_for_job_id(mocker):
|
def test_get_notification_count_for_job_id(mocker):
|
||||||
mock_get = mocker.patch(
|
mock_get = mocker.patch(
|
||||||
"app.notify_client.notification_api_client.NotificationApiClient.get"
|
"app.notify_client.notification_api_client.NotificationApiClient.get",
|
||||||
|
return_value={"count": 0},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
mocker.patch(
|
||||||
|
"app.notify_client.notification_api_client.redis_client.get", return_value=None
|
||||||
|
)
|
||||||
|
|
||||||
|
mocker.patch("app.notify_client.billing_api_client.redis_client.set")
|
||||||
NotificationApiClient().get_notification_count_for_job_id(
|
NotificationApiClient().get_notification_count_for_job_id(
|
||||||
service_id="foo", job_id="bar"
|
service_id="foo", job_id="bar"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user