Private
Public Access
1
0

get dates timeperiod updates to work better with local time zones

This commit is contained in:
Sander Roosendaal
2021-09-21 11:04:36 +02:00
parent 8205fd3c3f
commit 5b11413068
8 changed files with 170 additions and 27 deletions

View File

@@ -32,6 +32,7 @@ class OtherUnitTests(TestCase):
birthdate=faker.profile()['birthdate'],
gdproptin=True,surveydone=True,
gdproptindate=timezone.now(),
defaulttimezone='US/Pacific',
rowerplan='coach')
workoutsbox = Mailbox.objects.create(name='workouts')
@@ -39,6 +40,64 @@ class OtherUnitTests(TestCase):
failbox = Mailbox.objects.create(name='Failed')
failbox.save()
# Test get_dates_timeperiod
def test_get_dates_timeperiod(self):
rq = RequestFactory().get('/rowers/plannedsessions/')
middleware = SessionMiddleware()
middleware.process_request(rq)
# blanco should just run
startdate,enddate = get_dates_timeperiod(rq,rower=self.r)
# time should be midnight
self.assertEqual(startdate.strftime('%H:%M:%S'),'00:00:00')
# tzinfo should be present
self.assertTrue(startdate.tzinfo is not None)
# time zone should be US/Pacific
self.assertTrue('US/Pacific' in str(startdate.tzinfo))
# now with dates
startdatestring = '2021-09-26'
enddatestring = '2021-10-02'
startdate,enddate = get_dates_timeperiod(rq,startdatestring=startdatestring,
enddatestring=enddatestring)
# time should be midnight
self.assertEqual(startdate.strftime('%H:%M:%S'),'00:00:00')
# startdate and enddate should match
self.assertEqual(startdate.strftime('%m-%d'),'09-26')
self.assertEqual(enddate.strftime('%m-%d'),'10-02')
# tzinfo should be present
self.assertTrue(startdate.tzinfo is not None)
# time zone should be US/Pacific
self.assertTrue('UTC' in str(startdate.tzinfo))
# now with dates and rower
startdatestring = '2021-09-26'
enddatestring = '2021-10-02'
startdate,enddate = get_dates_timeperiod(rq,startdatestring=startdatestring,
enddatestring=enddatestring,rower=self.r)
# time should be midnight
self.assertEqual(startdate.strftime('%H:%M:%S'),'00:00:00')
# startdate and enddate should match
self.assertEqual(startdate.strftime('%m-%d'),'09-26')
self.assertEqual(enddate.strftime('%m-%d'),'10-02')
# tzinfo should be present
self.assertTrue(startdate.tzinfo is not None)
# time zone should be US/Pacific
self.assertTrue('US/Pacific' in str(startdate.tzinfo))
@patch('rowers.tasks.requests.get',side_effect=mocked_requests)
def test_strava_asyncworkout(self,mock_get):