def test_oldest_cache_event_is_stale_should_be_false_if_event_timestamp_is_less_than_expire_time(self):
     event_log = EventLog(filename="my_fake_eventlog.log")
     cache_events = [json.loads(line) for line in self._FAKE_EVENTLOG_CONTENTS.strip().splitlines()]
     event_log._log_cache = cache_events
     # set the new time to 1 second past the expiration time
     new_timestamp = event_log._log_cache[0]["__timestamp__"] + 45
     time_mock = self.patch("app.util.event_log.time")
     time_mock.time.return_value = new_timestamp
     self.assertFalse(event_log._oldest_cache_event_is_stale())
 def test_oldest_cache_event_is_stale_should_be_true_if_event_timestamp_is_greater_than_expire_time(self):
     event_log = EventLog(filename="my_fake_eventlog.log")
     cache_events = [json.loads(line) for line in self._FAKE_EVENTLOG_CONTENTS.strip().splitlines()]
     event_log._log_cache = cache_events
     events = event_log.get_events()
     # set the new time to 1 second past the expiration time
     new_timestamp = event_log._log_cache[0]["__timestamp__"] + LOG_CACHE_EXPIRE_TIME_IN_HOURS * 60 * 60 + 1
     new_event = {"__id__": 4, "__tag__": "NETWORK_REQUEST_RECEIVED", "__timestamp__": new_timestamp}
     event_log._log_cache.append(new_event)
     self.assertTrue(event_log._oldest_cache_event_is_stale())
 def test_oldest_cache_event_is_stale_should_be_false_if_event_timestamp_is_less_than_expire_time(self):
     event_log = EventLog(filename='my_fake_eventlog.log')
     cache_events = [json.loads(line)
                     for line in self._FAKE_EVENTLOG_CONTENTS.strip().splitlines()]
     event_log._log_cache = cache_events
     # set the new time to 1 second past the expiration time
     new_timestamp = event_log._log_cache[0]['__timestamp__'] + 45
     time_mock = self.patch('app.util.event_log.time')
     time_mock.time.return_value = new_timestamp
     self.assertFalse(event_log._oldest_cache_event_is_stale())
 def test_oldest_cache_event_is_stale_should_be_true_if_event_timestamp_is_greater_than_expire_time(self):
     event_log = EventLog(filename='my_fake_eventlog.log')
     cache_events = [json.loads(line)
                     for line in self._FAKE_EVENTLOG_CONTENTS.strip().splitlines()]
     event_log._log_cache = cache_events
     events = event_log.get_events()
     # set the new time to 1 second past the expiration time
     new_timestamp = event_log._log_cache[0]['__timestamp__'] + LOG_CACHE_EXPIRE_TIME_IN_HOURS * 60 * 60 + 1
     new_event = {'__id__': 4, '__tag__': 'NETWORK_REQUEST_RECEIVED', '__timestamp__': new_timestamp}
     event_log._log_cache.append(new_event)
     self.assertTrue(event_log._oldest_cache_event_is_stale())