API: db models tests
This commit is contained in:
parent
59a3ca6a3a
commit
5d6a095348
@ -72,7 +72,7 @@ class Activity(db.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.sports.label) + \
|
return str(self.sports.label) + \
|
||||||
" - " + self.activity_date.strftime('%Y-%m-%d')
|
" - " + self.activity_date.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
def __init__(self, user_id, sport_id, activity_date, distance, duration):
|
def __init__(self, user_id, sport_id, activity_date, distance, duration):
|
||||||
self.user_id = user_id
|
self.user_id = user_id
|
||||||
|
23
mpwo_api/mpwo_api/tests/test_activities_model.py
Normal file
23
mpwo_api/mpwo_api/tests/test_activities_model.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import datetime
|
||||||
|
|
||||||
|
from mpwo_api.tests.utils import add_activity, add_sport, add_user
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_activity(app):
|
||||||
|
add_user('test', 'test@test.com', '12345678')
|
||||||
|
add_sport('cycling')
|
||||||
|
activity = add_activity(
|
||||||
|
user_id=1,
|
||||||
|
sport_id=1,
|
||||||
|
activity_date=datetime.datetime.strptime('01/01/2018 13:36', '%d/%m/%Y %H:%M'), # noqa
|
||||||
|
distance=10,
|
||||||
|
duration=datetime.timedelta(seconds=1024)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert 1 == activity.id
|
||||||
|
assert 1 == activity.user_id
|
||||||
|
assert 1 == activity.sport_id
|
||||||
|
assert '2018-01-01 13:36:00' == str(activity.activity_date)
|
||||||
|
assert 10.0 == float(activity.distance)
|
||||||
|
assert '0:17:04' == str(activity.duration)
|
||||||
|
assert 'cycling - 2018-01-01 13:36:00' == str(activity)
|
25
mpwo_api/mpwo_api/tests/test_records_model.py
Normal file
25
mpwo_api/mpwo_api/tests/test_records_model.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import datetime
|
||||||
|
|
||||||
|
from mpwo_api.tests.utils import add_activity, add_record, add_sport, add_user
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_record(app):
|
||||||
|
add_user('test', 'test@test.com', '12345678')
|
||||||
|
add_sport('cycling')
|
||||||
|
|
||||||
|
activity = add_activity(
|
||||||
|
user_id=1,
|
||||||
|
sport_id=1,
|
||||||
|
activity_date=datetime.datetime.strptime('01/01/2018 13:36', '%d/%m/%Y %H:%M'), # noqa
|
||||||
|
distance=10,
|
||||||
|
duration=datetime.timedelta(seconds=1024)
|
||||||
|
)
|
||||||
|
record = add_record(1, 1, activity, 'LD')
|
||||||
|
|
||||||
|
assert 1 == record.id
|
||||||
|
assert 1 == record.user_id
|
||||||
|
assert 1 == record.sport_id
|
||||||
|
assert 1 == record.activity_id
|
||||||
|
assert 'LD' == record.record_type
|
||||||
|
assert '2018-01-01 13:36:00' == str(record.activity_date)
|
||||||
|
assert 'cycling - LD - 2018-01-01' == str(record)
|
10
mpwo_api/mpwo_api/tests/test_sports_model.py
Normal file
10
mpwo_api/mpwo_api/tests/test_sports_model.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from mpwo_api.tests.utils import add_sport, add_user
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_sport(app):
|
||||||
|
add_user('test', 'test@test.com', '12345678')
|
||||||
|
sport = add_sport('cycling')
|
||||||
|
|
||||||
|
assert 1 == sport.id
|
||||||
|
assert 'cycling' == sport.label
|
||||||
|
assert 'cycling' == str(sport)
|
7
mpwo_api/mpwo_api/tests/test_users_model.py
Normal file
7
mpwo_api/mpwo_api/tests/test_users_model.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from mpwo_api.tests.utils import add_user
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_user(app):
|
||||||
|
user = add_user('test', 'test@test.com', '12345678')
|
||||||
|
assert '<User \'test\'>' == str(user)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user