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
예제 #2
0
    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
예제 #3
0
    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"
예제 #4
0
    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_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) == {}
예제 #7
0
    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_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
예제 #10
0
    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
예제 #11
0
    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
예제 #12
0
    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
예제 #13
0
 def test_reset(self):
     sc = StatsCache()
     assert len(sc.stats) > 1
     sc._reset_at = datetime.datetime.now() - datetime.timedelta(days=1)
     sc.get_stat(name="test7", dt=datetime.datetime.now(), step_size=15)
     assert len(sc.stats) == 1
예제 #14
0
 def test_reset(self):
     sc = StatsCache()
     assert len(sc.stats) > 1
     sc._reset_at = datetime.datetime.now() - datetime.timedelta(days=1)
     sc.get_stat(name="test7", dt=datetime.datetime.now(), step_size=15)
     assert len(sc.stats) == 1