Skip to content

Commit dc79170

Browse files
committed
test Activity
1 parent 2f0a944 commit dc79170

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

opendata-python/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ athlete.store_locally(data=False)
6363
```
6464
the rest of the data could always be retrieved later:
6565
```python
66-
athlete.download_remote_data()
66+
from opendata.models import LocalAthlete
67+
local_athlete = LocalAthlete(athlete.id)
68+
local_athlete.download_remote_data()
6769
```
6870

6971
### Working with local data storage

opendata-python/opendata/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,8 @@ def store_locally(self, data=True):
173173
self.data_zip.extractall(path=os.path.join(settings.local_storage,
174174
settings.data_prefix,
175175
self.id)) # noqa: E501
176+
else:
177+
warnings.warn(f"""Only metatada will be stored locally for {self.id}.
178+
Data can be fetched later by calling Athlete.download_remote_data()""",
179+
stacklevel=2)
176180
self.metadata_zip.extractall(path=os.path.join(settings.local_storage, settings.metadata_prefix)) # noqa: E501

opendata-python/tests/test_models.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,15 @@
88

99

1010
class TestActivity:
11-
def __init__(self, local_storage):
12-
self.activity = models.Activity(
11+
def test_init(self, local_storage):
12+
activity = models.Activity(
1313
id='1970_01_01_00_00_00.csv',
1414
filepath_or_buffer=\
1515
os.path.join(local_storage.strpath,
1616
settings.data_prefix,
1717
'some-athlete-id-1',
1818
'1970_01_01_00_00_00.csv')
1919
)
20-
return self
21-
22-
def test_init(self, local_storage):
23-
activity = self.activity
2420
assert activity.id == '1970_01_01_00_00_00.csv'
2521
assert activity.filepath_or_buffer == \
2622
os.path.join(local_storage.strpath,
@@ -32,9 +28,16 @@ def test_init(self, local_storage):
3228
assert 'heartrate' in activity.data
3329
assert activity.data.power[0] == 200
3430

35-
def test_data_not_stored_locally(self, local_storage):
36-
data = self.activity.data()
37-
assert data is not None
31+
def test_init__not_stored_locally(self, local_storage):
32+
activity = models.Activity(
33+
id='not_stored_activity.csv',
34+
filepath_or_buffer=\
35+
os.path.join(local_storage.strpath,
36+
settings.data_prefix,
37+
'some-athlete-id-1',
38+
'not_stored_activity.csv')
39+
)
40+
assert activity is not None
3841

3942

4043
class TestBaseAthlete:

0 commit comments

Comments
 (0)