2016-08-11 02:13:59 -04:00
|
|
|
from datetime import datetime, date, timedelta
|
2016-11-10 02:08:22 -05:00
|
|
|
from superset import utils
|
2016-08-11 02:13:59 -04:00
|
|
|
import unittest
|
|
|
|
|
2016-12-01 18:18:55 -05:00
|
|
|
from mock import Mock, patch
|
2016-08-11 02:13:59 -04:00
|
|
|
|
|
|
|
class UtilsTestCase(unittest.TestCase):
|
|
|
|
def test_json_int_dttm_ser(self):
|
2016-08-30 00:55:31 -04:00
|
|
|
dttm = datetime(2020, 1, 1)
|
|
|
|
ts = 1577836800000.0
|
|
|
|
json_int_dttm_ser = utils.json_int_dttm_ser
|
|
|
|
assert json_int_dttm_ser(dttm) == ts
|
|
|
|
assert json_int_dttm_ser(date(2020, 1, 1)) == ts
|
|
|
|
assert json_int_dttm_ser(datetime(1970, 1, 1)) == 0
|
|
|
|
assert json_int_dttm_ser(date(1970, 1, 1)) == 0
|
|
|
|
assert json_int_dttm_ser(dttm + timedelta(milliseconds=1)) == (ts + 1)
|
2016-08-11 02:13:59 -04:00
|
|
|
|
|
|
|
with self.assertRaises(TypeError):
|
|
|
|
utils.json_int_dttm_ser("this is not a date")
|
2016-12-01 18:18:55 -05:00
|
|
|
|
|
|
|
@patch('superset.utils.datetime')
|
|
|
|
def test_parse_human_timedelta(self, mock_now):
|
|
|
|
mock_now.return_value = datetime(2016, 12, 1)
|
|
|
|
self.assertEquals(utils.parse_human_timedelta('now'), timedelta(0))
|