I am currently writing tests and trying to assert if the expiry date is similar to what I expect it to me. Now I have the problem that the seconds are not similar and differ. E.g. >>> session_expiry_date = 1550744238.096939
while >>> expiry_date = 1550744238.087822
. My best idea is to abandon the numbers after the dot and just compare if it's the same day.
I now struggle to convert the timestamps into dates (YEAR-MONTH-DAY) that I can compare it in a way with self.assertTrue
. Can you explain to me how to convert these timestamps to comparable Year-Month-Day format?
def test_st_code_via_get(self):
self.assertFalse(self.session_name in self.client.session)
current_time = timezone.now().timestamp()
expiry_date = timezone.now() + timezone.timedelta(
days=settings.ST_ATTRIBUTION_WINDOW
)
self.client.get(self.path, {'a': 'LOREM'})
session_expiry_date = self.client.session[self.session_name].get('expiry_date')
self.assertTrue(expiry_date, session_expiry_date)