API: tests update
This commit is contained in:
parent
d96795b559
commit
63f64d8acb
@ -441,3 +441,12 @@ def gpx_file_wo_track():
|
|||||||
' <metadata/>'
|
' <metadata/>'
|
||||||
'</gpx>'
|
'</gpx>'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def gpx_file_invalid_xml():
|
||||||
|
return (
|
||||||
|
'<?xml version=\'1.0\' encoding=\'UTF-8\'?>'
|
||||||
|
'<gpx xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:gpxext="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns="http://www.topografix.com/GPX/1/1">' # noqa
|
||||||
|
' <metadata/>'
|
||||||
|
)
|
||||||
|
@ -227,3 +227,85 @@ def test_get_an_activity_invalid_id(app, user_1):
|
|||||||
assert response.status_code == 404
|
assert response.status_code == 404
|
||||||
assert 'not found' in data['status']
|
assert 'not found' in data['status']
|
||||||
assert len(data['data']['activities']) == 0
|
assert len(data['data']['activities']) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_an_activity_no_actvity_no_gpx(app, user_1):
|
||||||
|
client = app.test_client()
|
||||||
|
resp_login = client.post(
|
||||||
|
'/api/auth/login',
|
||||||
|
data=json.dumps(dict(
|
||||||
|
email='test@test.com',
|
||||||
|
password='12345678'
|
||||||
|
)),
|
||||||
|
content_type='application/json'
|
||||||
|
)
|
||||||
|
response = client.get(
|
||||||
|
'/api/activities/11/gpx',
|
||||||
|
headers=dict(
|
||||||
|
Authorization='Bearer ' + json.loads(
|
||||||
|
resp_login.data.decode()
|
||||||
|
)['auth_token']
|
||||||
|
)
|
||||||
|
)
|
||||||
|
data = json.loads(response.data.decode())
|
||||||
|
|
||||||
|
assert response.status_code == 404
|
||||||
|
assert 'not found' in data['status']
|
||||||
|
assert 'Activity not found (id: 11)' in data['message']
|
||||||
|
assert data['data']['gpx'] == ''
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_an_activity_actvity_no_gpx(
|
||||||
|
app, user_1, sport_1_cycling, activity_cycling_user_1
|
||||||
|
):
|
||||||
|
client = app.test_client()
|
||||||
|
resp_login = client.post(
|
||||||
|
'/api/auth/login',
|
||||||
|
data=json.dumps(dict(
|
||||||
|
email='test@test.com',
|
||||||
|
password='12345678'
|
||||||
|
)),
|
||||||
|
content_type='application/json'
|
||||||
|
)
|
||||||
|
response = client.get(
|
||||||
|
'/api/activities/1/gpx',
|
||||||
|
headers=dict(
|
||||||
|
Authorization='Bearer ' + json.loads(
|
||||||
|
resp_login.data.decode()
|
||||||
|
)['auth_token']
|
||||||
|
)
|
||||||
|
)
|
||||||
|
data = json.loads(response.data.decode())
|
||||||
|
|
||||||
|
assert response.status_code == 400
|
||||||
|
assert 'fail' in data['status']
|
||||||
|
assert 'No gpx file for this activity (id: 1)' in data['message']
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_an_activity_actvity_invalid_gpx(
|
||||||
|
app, user_1, sport_1_cycling, activity_cycling_user_1
|
||||||
|
):
|
||||||
|
activity_cycling_user_1.gpx = "some path"
|
||||||
|
client = app.test_client()
|
||||||
|
resp_login = client.post(
|
||||||
|
'/api/auth/login',
|
||||||
|
data=json.dumps(dict(
|
||||||
|
email='test@test.com',
|
||||||
|
password='12345678'
|
||||||
|
)),
|
||||||
|
content_type='application/json'
|
||||||
|
)
|
||||||
|
response = client.get(
|
||||||
|
'/api/activities/1/gpx',
|
||||||
|
headers=dict(
|
||||||
|
Authorization='Bearer ' + json.loads(
|
||||||
|
resp_login.data.decode()
|
||||||
|
)['auth_token']
|
||||||
|
)
|
||||||
|
)
|
||||||
|
data = json.loads(response.data.decode())
|
||||||
|
|
||||||
|
assert response.status_code == 500
|
||||||
|
assert 'error' in data['status']
|
||||||
|
assert 'internal error' in data['message']
|
||||||
|
assert data['data']['gpx'] == ''
|
||||||
|
@ -134,7 +134,7 @@ def test_add_an_activity_gpx(app, user_1, sport_1_cycling, gpx_file):
|
|||||||
assert_activity_data_with_gpx(data)
|
assert_activity_data_with_gpx(data)
|
||||||
|
|
||||||
|
|
||||||
def test_add_an_activity_with_gpx(app, user_1, sport_1_cycling, gpx_file):
|
def test_get_an_activity_with_gpx(app, user_1, sport_1_cycling, gpx_file):
|
||||||
client = app.test_client()
|
client = app.test_client()
|
||||||
resp_login = client.post(
|
resp_login = client.post(
|
||||||
'/api/auth/login',
|
'/api/auth/login',
|
||||||
@ -173,6 +173,21 @@ def test_add_an_activity_with_gpx(app, user_1, sport_1_cycling, gpx_file):
|
|||||||
assert 'just an activity' == data['data']['activities'][0]['title']
|
assert 'just an activity' == data['data']['activities'][0]['title']
|
||||||
assert_activity_data_with_gpx(data)
|
assert_activity_data_with_gpx(data)
|
||||||
|
|
||||||
|
response = client.get(
|
||||||
|
'/api/activities/1/gpx',
|
||||||
|
headers=dict(
|
||||||
|
Authorization='Bearer ' + json.loads(
|
||||||
|
resp_login.data.decode()
|
||||||
|
)['auth_token']
|
||||||
|
)
|
||||||
|
)
|
||||||
|
data = json.loads(response.data.decode())
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert 'success' in data['status']
|
||||||
|
assert '' in data['message']
|
||||||
|
assert len(data['data']['gpx']) != ''
|
||||||
|
|
||||||
|
|
||||||
def test_add_an_activity_with_gpx_without_name(
|
def test_add_an_activity_with_gpx_without_name(
|
||||||
app, user_1, sport_1_cycling, gpx_file_wo_name
|
app, user_1, sport_1_cycling, gpx_file_wo_name
|
||||||
@ -241,6 +256,39 @@ def test_add_an_activity_with_gpx_invalid_file(
|
|||||||
assert 'data' not in data
|
assert 'data' not in data
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_an_activity_with_gpx_invalid_xml(
|
||||||
|
app, user_1, sport_1_cycling, gpx_file_invalid_xml
|
||||||
|
):
|
||||||
|
client = app.test_client()
|
||||||
|
resp_login = client.post(
|
||||||
|
'/api/auth/login',
|
||||||
|
data=json.dumps(dict(
|
||||||
|
email='test@test.com',
|
||||||
|
password='12345678'
|
||||||
|
)),
|
||||||
|
content_type='application/json'
|
||||||
|
)
|
||||||
|
response = client.post(
|
||||||
|
'/api/activities',
|
||||||
|
data=dict(
|
||||||
|
file=(BytesIO(str.encode(gpx_file_invalid_xml)), 'example.gpx'),
|
||||||
|
data='{"sport_id": 1}'
|
||||||
|
),
|
||||||
|
headers=dict(
|
||||||
|
content_type='multipart/form-data',
|
||||||
|
Authorization='Bearer ' + json.loads(
|
||||||
|
resp_login.data.decode()
|
||||||
|
)['auth_token']
|
||||||
|
)
|
||||||
|
)
|
||||||
|
data = json.loads(response.data.decode())
|
||||||
|
|
||||||
|
assert response.status_code == 500
|
||||||
|
assert 'error' in data['status']
|
||||||
|
assert 'Error during gpx file parsing.' in data['message']
|
||||||
|
assert 'data' not in data
|
||||||
|
|
||||||
|
|
||||||
def test_add_an_activity_gpx_invalid_extension(
|
def test_add_an_activity_gpx_invalid_extension(
|
||||||
app, user_1, sport_1_cycling, gpx_file
|
app, user_1, sport_1_cycling, gpx_file
|
||||||
):
|
):
|
||||||
|
@ -28,6 +28,27 @@ def test_record_model(
|
|||||||
assert 'value' in record_serialize
|
assert 'value' in record_serialize
|
||||||
|
|
||||||
|
|
||||||
|
def test_record_model_none_value(
|
||||||
|
app, user_1, sport_1_cycling, activity_cycling_user_1
|
||||||
|
):
|
||||||
|
record_ld = Record.query.filter_by(
|
||||||
|
user_id=activity_cycling_user_1.user_id,
|
||||||
|
sport_id=activity_cycling_user_1.sport_id,
|
||||||
|
record_type='LD',
|
||||||
|
).first()
|
||||||
|
record_ld.value = None
|
||||||
|
assert 1 == record_ld.user_id
|
||||||
|
assert 1 == record_ld.sport_id
|
||||||
|
assert 1 == record_ld.activity_id
|
||||||
|
assert 'LD' == record_ld.record_type
|
||||||
|
assert '2018-01-01 00:00:00' == str(record_ld.activity_date)
|
||||||
|
assert '<Record Cycling - LD - 2018-01-01>' == str(record_ld)
|
||||||
|
assert record_ld.value is None
|
||||||
|
|
||||||
|
record_serialize = record_ld.serialize()
|
||||||
|
assert record_serialize['value'] is None
|
||||||
|
|
||||||
|
|
||||||
def test_add_as_records(
|
def test_add_as_records(
|
||||||
app, user_1, sport_1_cycling, activity_cycling_user_1
|
app, user_1, sport_1_cycling, activity_cycling_user_1
|
||||||
):
|
):
|
||||||
|
Loading…
Reference in New Issue
Block a user