2021-02-22 15:42:29 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
2021-02-23 14:24:46 +00:00
|
|
|
from freezegun import freeze_time
|
|
|
|
|
|
2021-02-22 15:42:29 +00:00
|
|
|
from app.dao import fact_processing_time_dao
|
2021-03-10 13:55:06 +00:00
|
|
|
from app.dao.fact_processing_time_dao import (
|
|
|
|
|
get_processing_time_percentage_for_date_range,
|
|
|
|
|
)
|
2021-02-22 15:42:29 +00:00
|
|
|
from app.models import FactProcessingTime
|
2021-03-10 11:12:29 +00:00
|
|
|
from tests.app.db import create_process_time
|
2021-02-22 15:42:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_insert_update_processing_time(notify_db_session):
|
|
|
|
|
data = FactProcessingTime(
|
2022-11-21 11:49:59 -05:00
|
|
|
local_date=datetime(2021, 2, 22).date(),
|
2021-02-22 15:42:29 +00:00
|
|
|
messages_total=3,
|
2023-08-29 14:54:30 -07:00
|
|
|
messages_within_10_secs=2,
|
2021-02-22 15:42:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
fact_processing_time_dao.insert_update_processing_time(data)
|
|
|
|
|
|
2024-11-18 14:30:22 -08:00
|
|
|
result = db.session.execute(select(FactProcessingTime)).scalars().all()
|
2021-02-22 15:42:29 +00:00
|
|
|
|
|
|
|
|
assert len(result) == 1
|
2022-11-21 11:49:59 -05:00
|
|
|
assert result[0].local_date == datetime(2021, 2, 22).date()
|
2021-02-22 15:42:29 +00:00
|
|
|
assert result[0].messages_total == 3
|
|
|
|
|
assert result[0].messages_within_10_secs == 2
|
2021-02-23 14:24:46 +00:00
|
|
|
assert result[0].created_at
|
|
|
|
|
assert not result[0].updated_at
|
2021-02-22 15:42:29 +00:00
|
|
|
|
|
|
|
|
data = FactProcessingTime(
|
2022-11-21 11:49:59 -05:00
|
|
|
local_date=datetime(2021, 2, 22).date(),
|
2021-02-22 15:42:29 +00:00
|
|
|
messages_total=4,
|
2023-08-29 14:54:30 -07:00
|
|
|
messages_within_10_secs=3,
|
2021-02-22 15:42:29 +00:00
|
|
|
)
|
2021-02-23 14:24:46 +00:00
|
|
|
with freeze_time("2021-02-23 13:23:33"):
|
|
|
|
|
fact_processing_time_dao.insert_update_processing_time(data)
|
2021-02-22 15:42:29 +00:00
|
|
|
|
2024-11-18 14:30:22 -08:00
|
|
|
result = FactProcessingTime.query.all()
|
2021-02-22 15:42:29 +00:00
|
|
|
|
|
|
|
|
assert len(result) == 1
|
2022-11-21 11:49:59 -05:00
|
|
|
assert result[0].local_date == datetime(2021, 2, 22).date()
|
2021-02-22 15:42:29 +00:00
|
|
|
assert result[0].messages_total == 4
|
|
|
|
|
assert result[0].messages_within_10_secs == 3
|
2021-02-23 14:24:46 +00:00
|
|
|
assert result[0].created_at
|
|
|
|
|
assert result[0].updated_at == datetime(2021, 2, 23, 13, 23, 33)
|
2021-03-04 16:10:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_processing_time_percentage_for_date_range(notify_db_session):
|
2021-03-10 11:12:29 +00:00
|
|
|
create_process_time(
|
2023-08-29 14:54:30 -07:00
|
|
|
local_date="2021-02-21", messages_total=5, messages_within_10_secs=4
|
2021-03-10 11:12:29 +00:00
|
|
|
)
|
|
|
|
|
create_process_time(
|
2023-08-29 14:54:30 -07:00
|
|
|
local_date="2021-02-22", messages_total=3, messages_within_10_secs=2
|
2021-03-04 16:10:53 +00:00
|
|
|
)
|
2021-03-10 11:12:29 +00:00
|
|
|
create_process_time(
|
2023-08-29 14:54:30 -07:00
|
|
|
local_date="2021-02-23", messages_total=4, messages_within_10_secs=3
|
2021-03-10 11:12:29 +00:00
|
|
|
)
|
2021-03-04 16:10:53 +00:00
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
results = get_processing_time_percentage_for_date_range("2021-02-22", "2021-02-22")
|
2021-03-04 16:10:53 +00:00
|
|
|
|
|
|
|
|
assert len(results) == 1
|
2023-08-29 14:54:30 -07:00
|
|
|
assert results[0].date == "2021-02-22"
|
2021-03-04 16:10:53 +00:00
|
|
|
assert results[0].messages_total == 3
|
|
|
|
|
assert results[0].messages_within_10_secs == 2
|
|
|
|
|
assert round(results[0].percentage, 1) == 66.7
|
Fix division by zero error on performance page
For preview and staging environments, we often send no messages
in a single day. This is currently causing a `DivisionByZero` error
that is rendering the page with no results. This makes it impossible
to look at preview/staging and see if the performance page is
working correctly or not.
(psycopg2.errors.DivisionByZero) division by zero
[SQL: SELECT CAST(ft_processing_time.bst_date AS TEXT) AS date, ft_processing_time.messages_total AS ft_processing_time_messages_total, ft_processing_time.messages_within_10_secs AS ft_processing_time_messages_within_10_secs, (ft_processing_time.messages_within_10_secs / CAST(ft_processing_time.messages_total AS FLOAT)) * %(param_1)s AS percentage
FROM ft_processing_time
WHERE ft_processing_time.bst_date >= %(bst_date_1)s AND ft_processing_time.bst_date <= %(bst_date_2)s ORDER BY ft_processing_time.bst_date]
[parameters: {'param_1': 100, 'bst_date_1': datetime.date(2021, 11, 12), 'bst_date_2': datetime.date(2021, 11, 19)}]
(Background on this error at: http://sqlalche.me/e/14/9h9h)
I've fixed this by falling back to 100.0% for days we send
no messages. Maybe some argument that it should be N/A rather than
100% but I think it doesn't really matter as this is only
going to affect preview and staging as we will never have a day
sending no messages in production.
2021-11-22 11:11:52 +00:00
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
def test_get_processing_time_percentage_for_date_range_handles_zero_cases(
|
|
|
|
|
notify_db_session,
|
|
|
|
|
):
|
Fix division by zero error on performance page
For preview and staging environments, we often send no messages
in a single day. This is currently causing a `DivisionByZero` error
that is rendering the page with no results. This makes it impossible
to look at preview/staging and see if the performance page is
working correctly or not.
(psycopg2.errors.DivisionByZero) division by zero
[SQL: SELECT CAST(ft_processing_time.bst_date AS TEXT) AS date, ft_processing_time.messages_total AS ft_processing_time_messages_total, ft_processing_time.messages_within_10_secs AS ft_processing_time_messages_within_10_secs, (ft_processing_time.messages_within_10_secs / CAST(ft_processing_time.messages_total AS FLOAT)) * %(param_1)s AS percentage
FROM ft_processing_time
WHERE ft_processing_time.bst_date >= %(bst_date_1)s AND ft_processing_time.bst_date <= %(bst_date_2)s ORDER BY ft_processing_time.bst_date]
[parameters: {'param_1': 100, 'bst_date_1': datetime.date(2021, 11, 12), 'bst_date_2': datetime.date(2021, 11, 19)}]
(Background on this error at: http://sqlalche.me/e/14/9h9h)
I've fixed this by falling back to 100.0% for days we send
no messages. Maybe some argument that it should be N/A rather than
100% but I think it doesn't really matter as this is only
going to affect preview and staging as we will never have a day
sending no messages in production.
2021-11-22 11:11:52 +00:00
|
|
|
create_process_time(
|
2023-08-29 14:54:30 -07:00
|
|
|
local_date="2021-02-21", messages_total=0, messages_within_10_secs=0
|
Fix division by zero error on performance page
For preview and staging environments, we often send no messages
in a single day. This is currently causing a `DivisionByZero` error
that is rendering the page with no results. This makes it impossible
to look at preview/staging and see if the performance page is
working correctly or not.
(psycopg2.errors.DivisionByZero) division by zero
[SQL: SELECT CAST(ft_processing_time.bst_date AS TEXT) AS date, ft_processing_time.messages_total AS ft_processing_time_messages_total, ft_processing_time.messages_within_10_secs AS ft_processing_time_messages_within_10_secs, (ft_processing_time.messages_within_10_secs / CAST(ft_processing_time.messages_total AS FLOAT)) * %(param_1)s AS percentage
FROM ft_processing_time
WHERE ft_processing_time.bst_date >= %(bst_date_1)s AND ft_processing_time.bst_date <= %(bst_date_2)s ORDER BY ft_processing_time.bst_date]
[parameters: {'param_1': 100, 'bst_date_1': datetime.date(2021, 11, 12), 'bst_date_2': datetime.date(2021, 11, 19)}]
(Background on this error at: http://sqlalche.me/e/14/9h9h)
I've fixed this by falling back to 100.0% for days we send
no messages. Maybe some argument that it should be N/A rather than
100% but I think it doesn't really matter as this is only
going to affect preview and staging as we will never have a day
sending no messages in production.
2021-11-22 11:11:52 +00:00
|
|
|
)
|
|
|
|
|
create_process_time(
|
2023-08-29 14:54:30 -07:00
|
|
|
local_date="2021-02-22", messages_total=10, messages_within_10_secs=0
|
Fix division by zero error on performance page
For preview and staging environments, we often send no messages
in a single day. This is currently causing a `DivisionByZero` error
that is rendering the page with no results. This makes it impossible
to look at preview/staging and see if the performance page is
working correctly or not.
(psycopg2.errors.DivisionByZero) division by zero
[SQL: SELECT CAST(ft_processing_time.bst_date AS TEXT) AS date, ft_processing_time.messages_total AS ft_processing_time_messages_total, ft_processing_time.messages_within_10_secs AS ft_processing_time_messages_within_10_secs, (ft_processing_time.messages_within_10_secs / CAST(ft_processing_time.messages_total AS FLOAT)) * %(param_1)s AS percentage
FROM ft_processing_time
WHERE ft_processing_time.bst_date >= %(bst_date_1)s AND ft_processing_time.bst_date <= %(bst_date_2)s ORDER BY ft_processing_time.bst_date]
[parameters: {'param_1': 100, 'bst_date_1': datetime.date(2021, 11, 12), 'bst_date_2': datetime.date(2021, 11, 19)}]
(Background on this error at: http://sqlalche.me/e/14/9h9h)
I've fixed this by falling back to 100.0% for days we send
no messages. Maybe some argument that it should be N/A rather than
100% but I think it doesn't really matter as this is only
going to affect preview and staging as we will never have a day
sending no messages in production.
2021-11-22 11:11:52 +00:00
|
|
|
)
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
results = get_processing_time_percentage_for_date_range("2021-02-21", "2021-02-22")
|
Fix division by zero error on performance page
For preview and staging environments, we often send no messages
in a single day. This is currently causing a `DivisionByZero` error
that is rendering the page with no results. This makes it impossible
to look at preview/staging and see if the performance page is
working correctly or not.
(psycopg2.errors.DivisionByZero) division by zero
[SQL: SELECT CAST(ft_processing_time.bst_date AS TEXT) AS date, ft_processing_time.messages_total AS ft_processing_time_messages_total, ft_processing_time.messages_within_10_secs AS ft_processing_time_messages_within_10_secs, (ft_processing_time.messages_within_10_secs / CAST(ft_processing_time.messages_total AS FLOAT)) * %(param_1)s AS percentage
FROM ft_processing_time
WHERE ft_processing_time.bst_date >= %(bst_date_1)s AND ft_processing_time.bst_date <= %(bst_date_2)s ORDER BY ft_processing_time.bst_date]
[parameters: {'param_1': 100, 'bst_date_1': datetime.date(2021, 11, 12), 'bst_date_2': datetime.date(2021, 11, 19)}]
(Background on this error at: http://sqlalche.me/e/14/9h9h)
I've fixed this by falling back to 100.0% for days we send
no messages. Maybe some argument that it should be N/A rather than
100% but I think it doesn't really matter as this is only
going to affect preview and staging as we will never have a day
sending no messages in production.
2021-11-22 11:11:52 +00:00
|
|
|
|
|
|
|
|
assert len(results) == 2
|
2023-08-29 14:54:30 -07:00
|
|
|
assert results[0].date == "2021-02-21"
|
Fix division by zero error on performance page
For preview and staging environments, we often send no messages
in a single day. This is currently causing a `DivisionByZero` error
that is rendering the page with no results. This makes it impossible
to look at preview/staging and see if the performance page is
working correctly or not.
(psycopg2.errors.DivisionByZero) division by zero
[SQL: SELECT CAST(ft_processing_time.bst_date AS TEXT) AS date, ft_processing_time.messages_total AS ft_processing_time_messages_total, ft_processing_time.messages_within_10_secs AS ft_processing_time_messages_within_10_secs, (ft_processing_time.messages_within_10_secs / CAST(ft_processing_time.messages_total AS FLOAT)) * %(param_1)s AS percentage
FROM ft_processing_time
WHERE ft_processing_time.bst_date >= %(bst_date_1)s AND ft_processing_time.bst_date <= %(bst_date_2)s ORDER BY ft_processing_time.bst_date]
[parameters: {'param_1': 100, 'bst_date_1': datetime.date(2021, 11, 12), 'bst_date_2': datetime.date(2021, 11, 19)}]
(Background on this error at: http://sqlalche.me/e/14/9h9h)
I've fixed this by falling back to 100.0% for days we send
no messages. Maybe some argument that it should be N/A rather than
100% but I think it doesn't really matter as this is only
going to affect preview and staging as we will never have a day
sending no messages in production.
2021-11-22 11:11:52 +00:00
|
|
|
assert results[0].messages_total == 0
|
|
|
|
|
assert results[0].messages_within_10_secs == 0
|
|
|
|
|
assert results[0].percentage == 100.0
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
assert results[1].date == "2021-02-22"
|
Fix division by zero error on performance page
For preview and staging environments, we often send no messages
in a single day. This is currently causing a `DivisionByZero` error
that is rendering the page with no results. This makes it impossible
to look at preview/staging and see if the performance page is
working correctly or not.
(psycopg2.errors.DivisionByZero) division by zero
[SQL: SELECT CAST(ft_processing_time.bst_date AS TEXT) AS date, ft_processing_time.messages_total AS ft_processing_time_messages_total, ft_processing_time.messages_within_10_secs AS ft_processing_time_messages_within_10_secs, (ft_processing_time.messages_within_10_secs / CAST(ft_processing_time.messages_total AS FLOAT)) * %(param_1)s AS percentage
FROM ft_processing_time
WHERE ft_processing_time.bst_date >= %(bst_date_1)s AND ft_processing_time.bst_date <= %(bst_date_2)s ORDER BY ft_processing_time.bst_date]
[parameters: {'param_1': 100, 'bst_date_1': datetime.date(2021, 11, 12), 'bst_date_2': datetime.date(2021, 11, 19)}]
(Background on this error at: http://sqlalche.me/e/14/9h9h)
I've fixed this by falling back to 100.0% for days we send
no messages. Maybe some argument that it should be N/A rather than
100% but I think it doesn't really matter as this is only
going to affect preview and staging as we will never have a day
sending no messages in production.
2021-11-22 11:11:52 +00:00
|
|
|
assert results[1].messages_total == 10
|
|
|
|
|
assert results[1].messages_within_10_secs == 0
|
|
|
|
|
assert results[1].percentage == 0.0
|