-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathtest_pandas.py
More file actions
39 lines (30 loc) · 1.45 KB
/
Copy pathtest_pandas.py
File metadata and controls
39 lines (30 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Unit tests for pandas helper."""
# standard library
import unittest
from unittest.mock import patch, sentinel, ANY
# first party
from delphi.epidata.server.main import app
from delphi.epidata.server._pandas import as_pandas
from delphi.epidata.server._config import MAX_RESULTS
# py3tester coverage target
__test_target__ = "delphi.epidata.server._pandas"
class TestPandas(unittest.TestCase):
"""Basic unit tests."""
def setUp(self):
"""Perform per-test setup."""
app.config["TESTING"] = True
app.config["WTF_CSRF_ENABLED"] = False
app.config["DEBUG"] = False
@patch("delphi.epidata.server._pandas.text")
@patch("pandas.read_sql_query")
def test_as_pandas(self, mock_read_sql_query, mock_sqlalch_text):
with app.test_request_context('covidcast/'):
mock_sqlalch_text.return_value = sentinel.default_limit
as_pandas("", params=None, db_engine=None)
mock_read_sql_query.assert_called()
mock_sqlalch_text.assert_called_with(f" LIMIT {MAX_RESULTS+1}")
mock_read_sql_query.assert_called_with(sentinel.default_limit, ANY, params=ANY, parse_dates=ANY)
mock_sqlalch_text.return_value = sentinel.explicit_limit
as_pandas("", params=None, db_engine=None, limit_rows=5)
mock_sqlalch_text.assert_called_with(f" LIMIT {5}")
mock_read_sql_query.assert_called_with(sentinel.explicit_limit, ANY, params=ANY, parse_dates=ANY)