Debian Codegraph @

extensions/stravaupload/test_strava.py

raw
1 import unittest, os
2 from time import sleep
3 from stravaupload import ProgressDialog, StravaUpload
4
5 class StravaUploadTest(unittest.TestCase):
6 """ nose-compatible test to drive the class that wraps up
7 zenity. Ensures the zenity process is closed correctly.
8
9 Not part of the larger test cases as extensions are
10 not installed as importable modules without modifying
11 the path.
12
13 Run 'nosetests extensions' from the project root to test. """
14 def tearDown(self):
15 try:
16 os.remove('./.strava_uploads')
17 except:
18 pass
19
20 def test_progress_process_closes_cleanly(self):
21 with ProgressDialog("testing") as p:
22 sleep(2)
23 self.assert_(p.progress.poll() is not None, 'zenity still running!')
24
25 def test_store_upload_id_crates_file(self):
26 exists = False
27 with StravaUpload(None, None, '.', None) as app:
28 app.store_upload_id(1, 12345)
29 try:
30 with open(app.strava_uploads) as f:
31 exists = True
32 except:
33 pass
34 self.assert_(exists is True, 'Store upload token failed')
35
36 def test_store_upload_id(self):
37 """ Ensure id can be found -- note that Strava
38 mints a new upload id (pytrainer's id aren't
39 unique to Strava!) for each upload... but the docs
40 don't say what the type is; treat as a string """
41 upload_id = ''
42 with StravaUpload(None, None, '.', None) as app:
43 app.store_upload_id(1, '11111')
44 app.store_upload_id(2, 'some made up id')
45 app.store_upload_id(3, 33333)
46 try:
47 with open(app.strava_uploads) as f:
48 upload_id = app.find_upload(3)
49 except:
50 pass
51 self.assert_(upload_id == '33333', 'Failed to find entry')
52
53 def test_upload_id_is_none(self):
54 expected = None
55 upload_id = 0
56 with StravaUpload(None, None, '.', None) as app:
57 upload_id = app.find_upload(1)
58 self.assert_(expected == upload_id, 'Upload ID found, expected None')
59