def test_hash_not_found_block_after_end(self):
        """
        Log: check existing hash specifying datetime after interval
        The Repository must fail to verify existence of a hash if a
        datetime of the incorrect interval is specified.

        """
        time_res_s = self.repo._config['time_res_s']
        data = self.get_logging_test_data()
        req = self.repo.append_log(data,
                                   hasher_class=self.hasher_class,
                                   hasher_config=self.hasher_kwargs)
        dt = req['datetime']

        n = muteacle.interval_number(dt, time_res_s)
        intv_late = muteacle.interval_start(dt.year, dt.month, dt.day,
                                            time_res_s, n + 1)

        # logged data
        for i in self.data:
            with self.subTest(intv_late=intv_late, item=i):
                result = self.repo.check_log(intv_late, i)
                self.assertFalse(result)
        # unlogged data
        self.assertFalse(self.repo.check_log(intv_late, self.item_skipped))
Example #2
0
 def test_all_time_res_s(self):
     valid_values = [x for x in range(1,86401) if 86400%x == 0]
     combs = combinations(valid_values, 2)
     dt = datetime.utcnow()
     for c in combs:
         # combs should contain 2-element tuples with different valid
         # values of time_res_s
         with self.subTest(time_res_s_a=c[0], time_res_s_b=c[1]):
             dt_ns = interval_next_common_start(dt, c[0], c[1])
             na = interval_number(dt_ns, c[0])
             nb = interval_number(dt_ns, c[1])
             dt_ia = interval_start(
                 dt_ns.year, dt_ns.month, dt_ns.day, na, c[0]
             )
             dt_ib = interval_start(
                 dt_ns.year, dt_ns.month, dt_ns.day, nb, c[1]
             )
             self.assertEqual(dt_ia, dt_ns)
             self.assertEqual(dt_ib, dt_ns)
             self.assertGreater(dt_ns, dt)
Example #3
0
 def test_all_values(self):
     valid_trs = [x for x in range(1,86401) if 86400%x == 0]
     for trs in valid_trs:
         mn = datetime(2020, 12, 25) # midnight xmas 2020
         for n in range(86400//trs):
             # for all intervals...
             with self.subTest(time_res_s=trs, n=n):
                 # ...verify by number of seconds from midnight
                 dt_start = interval_start(mn.year, mn.month, mn.day, trs, n)
                 td = dt_start - mn
                 seconds = td.total_seconds()
                 self.assertEqual(seconds//trs, n)
    def test_hash_not_found_interval_start(self):
        """
        Log: check non-existing hash specifying start-of-interval datetime

        """
        time_res_s = self.repo._config['time_res_s']
        data = self.get_logging_test_data()
        req = self.repo.append_log(data,
                                   hasher_class=self.hasher_class,
                                   hasher_config=self.hasher_kwargs)
        dt = req['datetime']

        n = muteacle.interval_number(dt, time_res_s)
        intv_start = muteacle.interval_start(dt.year, dt.month, dt.day,
                                             time_res_s, n)

        result = self.repo.check_log(intv_start, self.item_skipped)
        self.assertFalse(result)
    def test_hash_found_interval_start(self):
        """
        Log: check existing hash specifying start-of-interval datetime

        """
        time_res_s = self.repo._config['time_res_s']
        data = self.get_logging_test_data()
        req = self.repo.append_log(data,
                                   hasher_class=self.hasher_class,
                                   hasher_config=self.hasher_kwargs)
        dt = req['datetime']
        n = muteacle.interval_number(dt, time_res_s)
        intv_start = muteacle.interval_start(dt.year, dt.month, dt.day,
                                             time_res_s, n)

        for i in data:
            with self.subTest(intv_start=intv_start, item=i):
                result = self.repo.check_log(intv_start, i)
                self.assertTrue(result)
    def test_get_hashers_interval_start(self):
        """
        Hasher: load hashers specifying datetime at start of interval

        """
        ts = datetime.utcnow().timestamp()
        meta = {'test': 'get_hashers_interval_start', 'ts': ts}
        time_res_s = self.repo._config['time_res_s']

        muteacle.sleep_until_interval_end(time_res_s)
        req = self.repo.new_hasher(config={'meta': meta})
        hasher = req['hasher']
        dt = req['datetime']

        n = muteacle.interval_number(dt, time_res_s)
        dt_load = muteacle.interval_start(dt.year, dt.month, dt.day,
                                          time_res_s, n)
        hashers_loaded = self.repo.get_hashers(dt_load)

        self.assertIn(hasher, hashers_loaded)