From 06d64b1d05885eb78598a5f70544104623feb568 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 15 Dec 2021 10:50:00 +0100 Subject: [PATCH] warning wednesday --- rowers/interactiveplots.py | 2 +- rowers/tests/mocks.py | 74 ++++++++++++++++++-------- rowers/tests/test_imports.py | 16 ++++-- rowers/tests/test_uploads.py | 12 ++++- rowers/tests/testdata/testdata.tcx.gz | Bin 4000 -> 0 bytes 5 files changed, 76 insertions(+), 28 deletions(-) delete mode 100644 rowers/tests/testdata/testdata.tcx.gz diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 5b14e466..27fe8f3b 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -1926,7 +1926,7 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, df.sort_values(['date'],inplace=True) df = df.groupby(['date']).max() df['date'] = df.index.values - mask = df['date'] > np.datetime64(startdate) + mask = df['date'] > np.datetime64(startdate.astimezone(tz=datetime.timezone.utc).replace(tzinfo=None)) df = df.loc[mask] diff --git a/rowers/tests/mocks.py b/rowers/tests/mocks.py index 2ca6677d..3b8d45cd 100644 --- a/rowers/tests/mocks.py +++ b/rowers/tests/mocks.py @@ -761,7 +761,8 @@ def mocked_requests(*args, **kwargs): 'available-user-data': [] } - c2workoutlist = json.load(open('rowers/tests/testdata/c2workoutlist.txt')) + with open('rowers/tests/testdata/c2workoutlist.txt') as f: + c2workoutlist = json.load(f) c2uploadjson = { "data": { @@ -782,29 +783,52 @@ def mocked_requests(*args, **kwargs): } } - stravaworkoutlist = json.load(open('rowers/tests/testdata/stravaworkoutlist.txt')) - sporttracksworkoutlist = json.load(open('rowers/tests/testdata/sporttracksworkouts.txt')) + with open('rowers/tests/testdata/stravaworkoutlist.txt') as f: + stravaworkoutlist = json.load(f) + + with open('rowers/tests/testdata/sporttracksworkouts.txt') as f: + sporttracksworkoutlist = json.load(f) #nkworkoutlist = json.load(open('rowers/tests/testdata/nkworkouts.txt')) - rkworkoutlistjson = json.load(open('rowers/tests/testdata/rkworkoutslist.txt','r')) - uaworkoutlistjson = json.load(open('rowers/tests/testdata/uaworkoutlist.txt','r')) - stravasummaryjson = json.load(open('rowers/tests/testdata/stravaworkoutsummary.txt','r')) + with open('rowers/tests/testdata/rkworkoutslist.txt','r') as f: + rkworkoutlistjson = json.load(f) - stravatimejson = json.load(open('rowers/tests/testdata/stravatimetestdata.txt','r')) - stravavelojson = json.load(open('rowers/tests/testdata/stravavelotestdata.txt','r')) + with open('rowers/tests/testdata/uaworkoutlist.txt','r') as f: + uaworkoutlistjson = json.load(f) - stravapowerjson = json.load(open('rowers/tests/testdata/stravapowertestdata.txt','r')) + with open('rowers/tests/testdata/stravaworkoutsummary.txt','r') as f: + stravasummaryjson = json.load(f) - stravadistancejson = json.load(open('rowers/tests/testdata/stravadistancetestdata.txt','r')) - stravalatlongjson = json.load(open('rowers/tests/testdata/stravalatlongtestdata.txt','r')) - stravahrjson = json.load(open('rowers/tests/testdata/stravahrtestdata.txt','r')) - stravaspmjson = json.load(open('rowers/tests/testdata/stravaspmtestdata.txt','r')) + with open('rowers/tests/testdata/stravatimetestdata.txt','r') as f: + stravatimejson = json.load(f) - uapostworkoutjson = json.load(open('rowers/tests/testdata/uapostworkoutresponse.txt','r')) + with open('rowers/tests/testdata/stravavelotestdata.txt','r') as f: + stravavelojson = json.load(f) - tpuploadresponse = json.load(open('rowers/tests/testdata/tpuploadresponse.txt','r')) + with open('rowers/tests/testdata/stravapowertestdata.txt','r') as f: + stravapowerjson = json.load(f) + + with open('rowers/tests/testdata/stravadistancetestdata.txt','r') as f: + stravadistancejson = json.load(f) + + with open('rowers/tests/testdata/stravalatlongtestdata.txt','r') as f: + stravalatlongjson = json.load(f) + + with open('rowers/tests/testdata/stravahrtestdata.txt','r') as f: + stravahrjson = json.load(f) + + with open('rowers/tests/testdata/stravaspmtestdata.txt','r') as f: + stravaspmjson = json.load(f) + + + with open('rowers/tests/testdata/uapostworkoutresponse.txt','r') as f: + uapostworkoutjson = json.load(f) + + + with open('rowers/tests/testdata/tpuploadresponse.txt','r') as f: + tpuploadresponse = json.load(f) stravastreamjson = { 'time':stravatimejson, @@ -816,15 +840,23 @@ def mocked_requests(*args, **kwargs): 'watts':stravapowerjson, } - ststrokesjson = json.load(open('rowers/tests/testdata/sporttracksstrokedata.txt','r')) - ststrokesjson_nogps = json.load(open('rowers/tests/testdata/sporttracksstrokedatanolocation.txt','r')) + with open('rowers/tests/testdata/sporttracksstrokedata.txt','r') as f: + ststrokesjson = json.load(f) - rkstrokesjson = json.load(open('rowers/tests/testdata/rkstrokes.txt','r')) + with open('rowers/tests/testdata/sporttracksstrokedatanolocation.txt','r') as f: + ststrokesjson_nogps = json.load(f) - uastrokesjson = json.load(open('rowers/tests/testdata/uastrokes.txt','r')) - uauserjson = json.load(open('rowers/tests/testdata/uauser.txt','r')) + with open('rowers/tests/testdata/rkstrokes.txt','r') as f: + rkstrokesjson = json.load(f) - stravaathletejson = json.load(open('rowers/tests/testdata/strava_athlete.txt')) + with open('rowers/tests/testdata/uastrokes.txt','r') as f: + uastrokesjson = json.load(f) + + with open('rowers/tests/testdata/uauser.txt','r') as f: + uauserjson = json.load(f) + + with open('rowers/tests/testdata/strava_athlete.txt') as f: + stravaathletejson = json.load(f) class MockResponse: def __init__(self, json_data, status_code): diff --git a/rowers/tests/test_imports.py b/rowers/tests/test_imports.py index 71ff008c..151a36a6 100644 --- a/rowers/tests/test_imports.py +++ b/rowers/tests/test_imports.py @@ -73,7 +73,9 @@ class GarminObjects(DjangoTestCase): w.delete() def test_garmin_push_summaries(self): - data = json.load(open('rowers/tests/testdata/garminsummarydata.txt','r')) + + with open('rowers/tests/testdata/garminsummarydata.txt','r') as f: + data = json.load(f) response = self.c.post('/rowers/garmin/summaries/',json.dumps(data), content_type="application/json") self.assertEqual(response.status_code, 200) @@ -85,7 +87,8 @@ class GarminObjects(DjangoTestCase): self.assertEqual(ws.count(),3) def test_garmin_push_details3(self): - data = json.load(open('rowers/tests/testdata/garmindetail3.txt','r')) + with open('rowers/tests/testdata/garmindetail3.txt','r') as f: + data = json.load(f) response = self.c.post('/rowers/garmin/activities/',json.dumps(data), content_type='application/json') @@ -99,7 +102,8 @@ class GarminObjects(DjangoTestCase): self.assertEqual(len(data),515) def test_garmin_push_details4(self): - data = json.load(open('rowers/tests/testdata/garmindetail4.txt','r')) + with open('rowers/tests/testdata/garmindetail4.txt','r') as f: + data = json.load(f) response = self.c.post('/rowers/garmin/activities/',json.dumps(data), content_type='application/json') @@ -113,7 +117,8 @@ class GarminObjects(DjangoTestCase): self.assertEqual(len(data),18) def test_garmin_push_details2(self): - data = json.load(open('rowers/tests/testdata/garmindetail2.txt','r')) + with open('rowers/tests/testdata/garmindetail2.txt','r') as f: + data = json.load(f) response = self.c.post('/rowers/garmin/activities/',json.dumps(data), content_type='application/json') @@ -126,7 +131,8 @@ class GarminObjects(DjangoTestCase): self.assertEqual(len(data),451) def test_garmin_push_details1(self): - data = json.load(open('rowers/tests/testdata/garmindetail1.txt','r')) + with open('rowers/tests/testdata/garmindetail1.txt','r') as f: + data = json.load(f) response = self.c.post('/rowers/garmin/activities/',json.dumps(data), content_type='application/json') diff --git a/rowers/tests/test_uploads.py b/rowers/tests/test_uploads.py index d15cd83c..649e8d63 100644 --- a/rowers/tests/test_uploads.py +++ b/rowers/tests/test_uploads.py @@ -119,7 +119,7 @@ class ViewTest(TestCase): 'notes':'noot mies', } form = WorkoutForm(data=form_data) - + self.assertTrue(form.is_valid()) response = self.c.post('/rowers/workout/'+encoded1+'/edit/', form_data, follow=True) self.assertEqual(response.status_code, 200) @@ -644,6 +644,7 @@ class ViewTest(TestCase): form = DocumentsForm(form_data,file_data) response = self.c.post('/rowers/workout/upload/', form_data, follow=True) + f.close() self.assertRedirects(response, expected_url='/rowers/workout/'+encoded1+'/edit/', status_code=302,target_status_code=200) self.assertEqual(response.status_code, 200) @@ -680,6 +681,7 @@ class ViewTest(TestCase): form = DocumentsForm(form_data,file_data) response = self.c.post('/rowers/workout/upload/', form_data, follow=True) + f.close() self.assertRedirects(response, expected_url='/rowers/workout/'+encoded1+'/edit/', status_code=302,target_status_code=200) self.assertEqual(response.status_code, 200) @@ -715,6 +717,7 @@ class ViewTest(TestCase): form = DocumentsForm(form_data,file_data) response = self.c.post('/rowers/workout/upload/', form_data, follow=True) + f.close() self.assertRedirects(response, expected_url='/rowers/workout/'+encoded1+'/edit/', status_code=302,target_status_code=200) self.assertEqual(response.status_code, 200) @@ -752,6 +755,7 @@ class ViewTest(TestCase): form = DocumentsForm(form_data,file_data) response = self.c.post('/rowers/workout/upload/', form_data, follow=True) + f.close() self.assertRedirects(response, expected_url='/rowers/workout/'+encoded1+'/edit/', status_code=302,target_status_code=200) self.assertEqual(response.status_code, 200) @@ -789,6 +793,7 @@ class ViewTest(TestCase): form = DocumentsForm(form_data,file_data) response = self.c.post('/rowers/workout/upload/', form_data, follow=True) + f.close() self.assertRedirects(response, expected_url='/rowers/workout/'+encoded1+'/edit/', status_code=302,target_status_code=200) self.assertEqual(response.status_code, 200) @@ -824,6 +829,7 @@ class ViewTest(TestCase): form = DocumentsForm(form_data,file_data) response = self.c.post('/rowers/workout/upload/', form_data, follow=True) + f.close() self.assertRedirects(response, expected_url='/rowers/workout/'+encoded1+'/edit/', status_code=302,target_status_code=200) self.assertEqual(response.status_code, 200) @@ -861,6 +867,7 @@ class ViewTest(TestCase): form = DocumentsForm(form_data,file_data) response = self.c.post('/rowers/workout/upload/', form_data, follow=True) + f.close() self.assertRedirects(response, expected_url='/rowers/workout/'+encoded1+'/edit/', status_code=302,target_status_code=200) self.assertEqual(response.status_code, 200) @@ -898,6 +905,7 @@ class ViewTest(TestCase): form = DocumentsForm(form_data,file_data) response = self.c.post('/rowers/workout/upload/', form_data, follow=True) + f.close() self.assertRedirects(response, expected_url='/rowers/workout/'+encoded1+'/edit/', status_code=302,target_status_code=200) self.assertEqual(response.status_code, 200) @@ -943,3 +951,5 @@ class ViewTest(TestCase): os.remove(f_to_be_deleted+'.gz') except (FileNotFoundError,OSError): pass + + f.close() diff --git a/rowers/tests/testdata/testdata.tcx.gz b/rowers/tests/testdata/testdata.tcx.gz deleted file mode 100644 index 4e0d4d34bce924a83caa6a2f25bc10c2935d513e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4000 zcmV;R4`1*fiwFp00J&iT|8!+@bYx+4VJ>uIcmVC4TW=Ic7J%RR6&4T4!zwlBQl~DC zaYP`iMFKVoD4VxcV&?BpuloLcf3bM` z_N_VYE>2f#b98pPNMCM_UM)|%&EopQ7jNk9?iBmoyKgwl{iA;MX4Sv{fJ=Ir8lK>)b;iX@kz0nQq>5qCt z=H2GyUmy7Qu7A*-oL#Jzo5dUa>;3=i`lH?c%gamQw_R!w&`l5B{l>e8clP!UK0JW* zGxEnz8{Y3dJ3qVV@7?`p|7v-0clTxb`q9fn0(3us{6O#=dEeqbITIamguemo0~{>U zP9OJw+@0?|>${8o`Ra6e@9tk6dwHRB=<~C_JIRMVTOOUQUv3VC{lVg^t)C8fxZ1rz zPnPM&Zqj|`d--DHr@cSoJ46fzi_1@+cDSEJtvg=+W0~&$x2|9Qe15upHT(DH>6ct? zezg91+4Y-Wmlsb~>(~AA-~E*zkxuh_ck+69h&Ekh_vfc8EUvl4m9L+4?^dU;PybIh zAnuwQxaJa9zJ9dczN-EE!|hwKOk^*&Tz!x)m+1i?66VLa`}+#Ti`DUQy0vBh>g?s= zlWzUGJ4qBj+j@2H?&!at-TijU`PpjSU)`L)NbkTmyo=l2K0oq{S3-;(eoeLq+>*dm z3go|{up@Cjg3lf>T=RUlJ6w)lo3AeW{MSFec_z4a4FB?s>74)S`aX$GJXq}h`tq8K zbkQ$=-u1VbUxe%MYN<1rB<*4q)R7HN1ABhZ6>%q55%&ZU!370(N_ta4?&0R#sV;f9 zQW1A&h*34lry+t1a*wm&?rcTeW0H3(Uc)_>ly`>NaQ78)x3nGSor1d!h6-}WTX4s! zxCf|+yCm*Os5IKVH*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