Skip to content

Commit

Permalink
add test case for date type
Browse files Browse the repository at this point in the history
  • Loading branch information
codemaster08240328 committed Jun 28, 2022
1 parent feadb35 commit 8ac748f
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion tests/integration_tests/reports/commands_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.
import json
from contextlib import contextmanager
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Any, Dict, List, Optional
from unittest.mock import Mock, patch
from uuid import uuid4
Expand Down Expand Up @@ -960,6 +960,8 @@ def test_email_chart_report_schedule_with_text(
mock_open.return_value = response
mock_urlopen.return_value = response
mock_urlopen.return_value.getcode.return_value = 200

# test without date type.
response.read.return_value = json.dumps(
{
"result": [
Expand Down Expand Up @@ -1012,6 +1014,59 @@ def test_email_chart_report_schedule_with_text(
# Assert logs are correct
assert_log(ReportState.SUCCESS)

# test with date type.
dt = datetime(2022, 1, 1).replace(tzinfo=timezone.utc)
ts = datetime.timestamp(dt) * 1000
response.read.return_value = json.dumps(
{
"result": [
{
"data": {
"t1": {0: "c11", 1: "c21"},
"t2__date": {0: ts, 1: ts},
"t3__sum": {0: "c13", 1: "c23"},
},
"colnames": [("t1",), ("t2__date",), ("t3__sum",)],
"indexnames": [(0,), (1,)],
"coltypes": [1, 2],
},
],
}
).encode("utf-8")

with freeze_time("2020-01-01T00:00:00Z"):
AsyncExecuteReportScheduleCommand(
TEST_ID, create_report_email_chart_with_text.id, datetime.utcnow()
).run()

# assert that the data is embedded correctly
table_html = """<table border="1" class="dataframe">
<thead>
<tr>
<th></th>
<th>t1</th>
<th>t2__date</th>
<th>t3__sum</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>c11</td>
<td>2022-01-01</td>
<td>c13</td>
</tr>
<tr>
<th>1</th>
<td>c21</td>
<td>2022-01-01</td>
<td>c23</td>
</tr>
</tbody>
</table>"""

assert table_html in email_mock.call_args[0][2]


@pytest.mark.usefixtures(
"load_birth_names_dashboard_with_slices", "create_report_email_dashboard"
Expand Down

0 comments on commit 8ac748f

Please sign in to comment.