def test_update_changed_default(self): sc = StatsCache() sc._init_stats() dt = datetime.datetime(2017, 5, 15, 15, 9, 22) sc.update(name="test9", set_dt=dt, step_size=15, default="Doge") assert sc.get_stat(name="test9", dt=dt, step_size=15) == "Doge"
def test_update_to_default(self): sc = StatsCache() sc._init_stats() dt = datetime.datetime(2017, 5, 15, 15, 9, 22) sc.update(name="test8", set_dt=dt, step_size=15) assert sc.get_stat(name="test8", dt=dt, step_size=15) == {}
def test_update_to_default(self): sc = StatsCache() sc._init_stats() dt = datetime.datetime(2017, 5, 15, 15, 9, 22) sc.update(name="test8", set_dt=dt, step_size=15) assert sc.get_stat(name="test8", dt=dt, step_size=15) == {}
def test_update_changed_default(self): sc = StatsCache() sc._init_stats() dt = datetime.datetime(2017, 5, 15, 15, 9, 22) sc.update(name="test9", set_dt=dt, step_size=15, default="Doge") assert sc.get_stat(name="test9", dt=dt, step_size=15) == "Doge"
def test_update_increment(self): sc = StatsCache() sc._init_stats() dt = datetime.datetime.now() key = sc.round_nearest_step(dt, 15).strftime(sc.dt_ftm) sc.update(name="test1", step_size=15) assert sc.stats["test1"][key] == 1
def test_update_increment(self): sc = StatsCache() sc._init_stats() dt = datetime.datetime.now() key = sc.round_nearest_step(dt, 15).strftime(sc.dt_ftm) sc.update(name="test1", step_size=15) assert sc.stats["test1"][key] == 1
def test_update_set_dt_value(self): sc = StatsCache() sc._init_stats() value = os.urandom(64) dt1 = datetime.datetime(2017, 5, 15, 15, 9, 22) sc.update(name="test2", step_size=15, set_dt=dt1, set_value=value) dt2 = datetime.datetime(2017, 5, 15, 15, 13, 42) assert sc.get_stat(name="test2", dt=dt2, step_size=15) == value
def test_update_set_dt_value(self): sc = StatsCache() sc._init_stats() value = os.urandom(64) dt1 = datetime.datetime(2017, 5, 15, 15, 9, 22) sc.update(name="test2", step_size=15, set_dt=dt1, set_value=value) dt2 = datetime.datetime(2017, 5, 15, 15, 13, 42) assert sc.get_stat(name="test2", dt=dt2, step_size=15) == value
def test_get_nonexistant(self): sc = StatsCache() sc._init_stats() dt = datetime.datetime(2017, 5, 15, 15, 9, 22) assert sc.get_stat(name="test5", dt=dt, step_size=15) is None sc.update(name="test5", step_size=15, set_dt=datetime.datetime(2017, 5, 15, 1, 5, 19)) assert sc.get_stat(name="test5", dt=dt, step_size=15) is None
def test_get_nonexistant(self): sc = StatsCache() sc._init_stats() dt = datetime.datetime(2017, 5, 15, 15, 9, 22) assert sc.get_stat(name="test5", dt=dt, step_size=15) is None sc.update( name="test5", step_size=15, set_dt=datetime.datetime(2017, 5, 15, 1, 5, 19) ) assert sc.get_stat(name="test5", dt=dt, step_size=15) is None
def test_get_now_is_none(self): sc = StatsCache() sc._init_stats() value = os.urandom(64) sc.update(name="test4", step_size=15, set_value=value, set_dt=datetime.datetime.now()) assert sc.get_stat( name="test4", step_size=15, dt=datetime.datetime.now()) is None
def test_get_now_is_none(self): sc = StatsCache() sc._init_stats() value = os.urandom(64) sc.update( name="test4", step_size=15, set_value=value, set_dt=datetime.datetime.now() ) assert sc.get_stat( name="test4", step_size=15, dt=datetime.datetime.now() ) is None
def test_update_key_prefix(self): sc = StatsCache() sc._init_stats() value = os.urandom(64) dt1 = datetime.datetime(2017, 5, 15, 15, 9, 22) dt2 = datetime.datetime(2017, 5, 15, 15, 11, 42) sc.update( name="test3", step_size=15, set_dt=dt1, set_value=value, key_prefix="node1" ) key = "node1%s" % sc.round_nearest_step(dt1, 15).strftime(sc.dt_ftm) assert sc.get_stat("test3", dt2, 15, key_prefix="node1") == value assert sc.stats["test3"][key] == value
def test_update_key_prefix(self): sc = StatsCache() sc._init_stats() value = os.urandom(64) dt1 = datetime.datetime(2017, 5, 15, 15, 9, 22) dt2 = datetime.datetime(2017, 5, 15, 15, 11, 42) sc.update(name="test3", step_size=15, set_dt=dt1, set_value=value, key_prefix="node1") key = "node1%s" % sc.round_nearest_step(dt1, 15).strftime(sc.dt_ftm) assert sc.get_stat("test3", dt2, 15, key_prefix="node1") == value assert sc.stats["test3"][key] == value