def test_comments(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) comment1 = flight_comments.yeah(flight=flight) comment2 = flight_comments.emoji(flight=flight) comment3 = flight_comments.yeah( flight=flight, user=flight.igc_file.owner, text=u"foo" ) comment4 = flight_comments.yeah(flight=flight, text=u"bar") comment5 = flight_comments.yeah(flight=flight, user=users.jane(), text=u"baz") add_fixtures(db_session, flight, comment1, comment2, comment3, comment4, comment5) res = client.get("/flights/{id}?extended".format(id=flight.id)) assert res.status_code == 200 assert res.json == { u"flight": expected_basic_flight_json(flight), u"near_flights": [], u"comments": [ {u"user": None, u"text": u"Yeah!"}, {u"user": None, u"text": u"\U0001f44d"}, {u"user": {u"id": comment3.user.id, u"name": u"John Doe"}, u"text": u"foo"}, {u"user": None, u"text": u"bar"}, {u"user": {u"id": comment5.user.id, u"name": u"Jane Doe"}, u"text": u"baz"}, ], u"contest_legs": {u"classic": [], u"triangle": []}, u"phases": [], u"performance": {u"circling": [], u"cruise": {}}, }
def test_unauthenticated(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) comment = flight_comments.yeah(flight=flight) add_fixtures(db_session, flight, comment) res = client.get('/flights/{id}?extended'.format(id=flight.id)) assert res.status_code == 200 assert res.json['comments'] == [{ u'user': None, u'text': u'Yeah!', }] res = client.post('/flights/{id}/comments'.format(id=flight.id), json={ u'text': u'foobar', }) assert res.status_code == 401 assert res.json == { u'error': u'invalid_token', u'message': u'Bearer token not found.', } res = client.get('/flights/{id}?extended'.format(id=flight.id)) assert res.status_code == 200 assert res.json['comments'] == [{ u'user': None, u'text': u'Yeah!', }]
def test_basic_flight(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) add_fixtures(db_session, flight) res = client.get("/flights/{id}".format(id=flight.id)) assert res.status_code == 200 assert res.json == {u"flight": expected_basic_flight_json(flight)}
def test_create(db_session, client): john = users.john() flight = flights.one(igc_file=igcs.simple(owner=john)) comment = flight_comments.yeah(flight=flight) add_fixtures(db_session, flight, comment, john) res = client.get('/flights/{id}?extended'.format(id=flight.id)) assert res.status_code == 200 assert res.json['comments'] == [{ u'user': None, u'text': u'Yeah!', }] res = client.post('/flights/{id}/comments'.format(id=flight.id), headers=auth_for(john), json={ u'text': u'foobar', }) assert res.status_code == 200 assert res.json == {} res = client.get('/flights/{id}?extended'.format(id=flight.id)) assert res.status_code == 200 assert res.json['comments'] == [{ u'user': None, u'text': u'Yeah!', }, { u'user': { u'id': john.id, u'name': u'John Doe', }, u'text': u'foobar', }]
def test_invalid_data(db_session, client): john = users.john() flight = flights.one(igc_file=igcs.simple(owner=john)) add_fixtures(db_session, flight, john) res = client.post('/flights/{id}/comments'.format(id=flight.id), headers=auth_for(john), data='foobar?') assert res.status_code == 400 assert res.json == {u'error': u'invalid-request'}
def test_unauthenticated_access_on_link_only_flight(db_session, client): flight = flights.one(privacy_level=Flight.PrivacyLevel.LINK_ONLY, igc_file=igcs.simple(owner=users.john())) add_fixtures(db_session, flight) res = client.get('/flights/{id}'.format(id=flight.id)) assert res.status_code == 200 assert 'flight' in res.json
def test_unauthenticated_access_on_private_flight(db_session, client): flight = flights.one(privacy_level=Flight.PrivacyLevel.PRIVATE, igc_file=igcs.simple(owner=users.john())) add_fixtures(db_session, flight) res = client.get('/flights/{id}'.format(id=flight.id)) assert res.status_code == 404 assert res.json == {}
def test_igc_owner_access_on_private_flight(db_session, client): john = users.john() flight = flights.one(pilot=None, privacy_level=Flight.PrivacyLevel.PRIVATE, igc_file=igcs.simple(owner=john)) add_fixtures(db_session, flight, john) res = client.get('/flights/{id}'.format(id=flight.id), headers=auth_for(john)) assert res.status_code == 200 assert 'flight' in res.json
def test_manager_access_on_private_flight(db_session, client): jane = users.jane(admin=True) flight = flights.one(privacy_level=Flight.PrivacyLevel.PRIVATE, igc_file=igcs.simple(owner=users.john())) add_fixtures(db_session, flight, jane) res = client.get('/flights/{id}'.format(id=flight.id), headers=auth_for(jane)) assert res.status_code == 200 assert 'flight' in res.json
def test_unfriendly_user_access_on_private_flight(db_session, client): jane = users.jane() flight = flights.one( privacy_level=Flight.PrivacyLevel.PRIVATE, igc_file=igcs.simple(owner=users.john()), ) add_fixtures(db_session, flight, jane) res = client.get("/flights/{id}".format(id=flight.id), headers=auth_for(jane)) assert res.status_code == 404 assert res.json == {}
def test_validation_error(db_session, client): john = users.john() flight = flights.one(igc_file=igcs.simple(owner=john)) add_fixtures(db_session, flight, john) res = client.post('/flights/{id}/comments'.format(id=flight.id), headers=auth_for(john), json={}) assert res.status_code == 422 assert res.json == { u'error': u'validation-failed', u'fields': { u'text': [u'Missing data for required field.'], }, }
def test_pilot_changing_same_pilot_and_co(db_session, client): """ Pilot is trying to change copilot to the same as pilot. """ john = users.john(club=clubs.lva()) flight = flights.one(igc_file=igcs.simple(owner=john)) add_fixtures(db_session, flight, john) response = client.post('/flights/{id}'.format(id=flight.id), headers=auth_for(john), json={ 'pilotId': john.id, 'copilotId': john.id, }) assert response.status_code == 422
def test_pilot_changing_pilot_and_co_null(db_session, client): """ Pilot is changing pilot and copilot to unknown user accounts. """ john = users.john(club=clubs.lva()) flight = flights.one(igc_file=igcs.simple(owner=john)) add_fixtures(db_session, flight, john) response = client.post('/flights/{id}'.format(id=flight.id), headers=auth_for(john), json={ 'pilotName': 'foo', 'copilotName': 'bar', }) assert response.status_code == 200
def test_validation_error(db_session, client): john = users.john() flight = flights.one(igc_file=igcs.simple(owner=john)) add_fixtures(db_session, flight, john) res = client.post( "/flights/{id}/comments".format(id=flight.id), headers=auth_for(john), json={} ) assert res.status_code == 422 assert res.json == { u"error": u"validation-failed", u"fields": {u"text": [u"Missing data for required field."]}, }
def test_phases(db_session, client): flight = flights.one( igc_file=igcs.simple(owner=users.john()), takeoff_time=datetime(2016, 5, 4, 8, 12, 46), ) add_fixtures( db_session, flight, flight_phases.example1(flight=flight), flight_phases.example2(flight=flight), ) expected_flight = expected_basic_flight_json(flight) expected_flight["takeoffTime"] = "2016-05-04T08:12:46+00:00" res = client.get("/flights/{id}?extended".format(id=flight.id)) assert res.status_code == 200 assert res.json == { u"flight": expected_flight, u"near_flights": [], u"comments": [], u"contest_legs": {u"classic": [], u"triangle": []}, u"phases": [ { u"circlingDirection": u"right", u"type": u"circling", u"secondsOfDay": 64446, u"startTime": u"2016-05-04T17:54:06+00:00", u"duration": 300, u"altDiff": 417.0, u"distance": 7028.0, u"vario": 1.39000000000002, u"speed": 23.4293014168156, u"glideRate": -16.8556125300829, }, { u"circlingDirection": None, u"type": u"cruise", u"secondsOfDay": 64746, u"startTime": u"2016-05-04T17:59:06+00:00", u"duration": 44, u"altDiff": -93.0, u"distance": 977.0, u"vario": -2.11363636363637, u"speed": 22.2232648999519, u"glideRate": 10.5142328558912, }, ], u"performance": {u"circling": [], u"cruise": {}}, }
def test_pilot_changing_correct_with_co(db_session, client): """ Pilot is changing copilot to user from same club. """ john = users.john(club=clubs.lva()) jane = users.jane(club=john.club) flight = flights.one(igc_file=igcs.simple(owner=john)) add_fixtures(db_session, flight, john, jane) response = client.post('/flights/{id}'.format(id=flight.id), headers=auth_for(john), json={ 'pilotId': john.id, 'copilotId': jane.id, }) assert response.status_code == 200
def test_pilot_changing_disallowed_copilot(db_session, client): """ Pilot is trying to change copilot to user from different club. """ john = users.john(club=clubs.lva()) max = users.max(club=clubs.sfn()) flight = flights.one(igc_file=igcs.simple(owner=john)) add_fixtures(db_session, flight, john, max) response = client.post('/flights/{id}'.format(id=flight.id), headers=auth_for(john), json={ 'pilotId': john.id, 'copilotId': max.id, }) assert response.status_code == 422
def test_empty_extended(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) add_fixtures(db_session, flight) res = client.get("/flights/{id}?extended".format(id=flight.id)) assert res.status_code == 200 assert res.json == { u"flight": expected_basic_flight_json(flight), u"near_flights": [], u"comments": [], u"contest_legs": {u"classic": [], u"triangle": []}, u"phases": [], u"performance": {u"circling": [], u"cruise": {}}, }
def test_pilot_changing_clubless_pilot_and_co(db_session, client): """ Pilot without club is trying to change copilot to user without club. """ john = users.john() jane = users.jane() flight = flights.one(igc_file=igcs.simple(owner=john)) add_fixtures(db_session, flight, john, jane) response = client.post('/flights/{id}'.format(id=flight.id), headers=auth_for(john), json={ 'pilotId': john.id, 'copilotId': jane.id, }) assert response.status_code == 422
def test_contest_legs(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) leg1 = contest_legs.first(flight=flight) leg2 = contest_legs.empty(flight=flight) leg3 = contest_legs.first(flight=flight, trace_type="triangle") add_fixtures(db_session, flight, leg1, leg2, leg3) res = client.get("/flights/{id}?extended".format(id=flight.id)) assert res.status_code == 200 assert res.json == { u"flight": expected_basic_flight_json(flight), u"near_flights": [], u"comments": [], u"contest_legs": { u"classic": [ { u"distance": 234833.0, u"duration": 2880, u"start": 33383, u"climbDuration": 5252, u"climbHeight": 6510.0, u"cruiseDistance": 241148.0, u"cruiseHeight": -6491.0, }, { u"distance": None, u"duration": 480, u"start": 36743, u"climbDuration": None, u"climbHeight": None, u"cruiseDistance": None, u"cruiseHeight": None, }, ], u"triangle": [ { u"distance": 234833.0, u"duration": 2880, u"start": 33383, u"climbDuration": 5252, u"climbHeight": 6510.0, u"cruiseDistance": 241148.0, u"cruiseHeight": -6491.0, } ], }, u"phases": [], u"performance": {u"circling": [], u"cruise": {}}, }
def test_pilot_changing_disowned_flight(db_session, client): """ Unrelated user is trying to change pilots. """ john = users.john(club=clubs.lva()) jane = users.jane(club=john.club) max = users.max(club=clubs.sfn()) flight = flights.one(igc_file=igcs.simple(owner=john)) add_fixtures(db_session, flight, john, jane, max) response = client.post('/flights/{id}'.format(id=flight.id), headers=auth_for(jane), json={ 'pilotId': john.id, 'copilotId': max.id, }) assert response.status_code == 403
def test_phases(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john()), takeoff_time=datetime(2016, 5, 4, 8, 12, 46)) add_fixtures(db_session, flight, flight_phases.example1(flight=flight), flight_phases.example2(flight=flight)) expected_flight = expected_basic_flight_json(flight) expected_flight['takeoffTime'] = '2016-05-04T08:12:46+00:00' res = client.get('/flights/{id}?extended'.format(id=flight.id)) assert res.status_code == 200 assert res.json == { u'flight': expected_flight, u'near_flights': [], u'comments': [], u'contest_legs': { u'classic': [], u'triangle': [], }, u'phases': [{ u'circlingDirection': u'right', u'type': u'circling', u'secondsOfDay': 64446, u'startTime': u'2016-05-04T17:54:06+00:00', u'duration': 300, u'altDiff': 417.0, u'distance': 7028.0, u'vario': 1.39000000000002, u'speed': 23.4293014168156, u'glideRate': -16.8556125300829 }, { u'circlingDirection': None, u'type': u'cruise', u'secondsOfDay': 64746, u'startTime': u'2016-05-04T17:59:06+00:00', u'duration': 44, u'altDiff': -93.0, u'distance': 977.0, u'vario': -2.11363636363637, u'speed': 22.2232648999519, u'glideRate': 10.5142328558912 }], u'performance': { u'circling': [], u'cruise': {}, } }
def test_data(db_session): # create test user john = users.john() db_session.add(john) # create IGC file igc_file = igcs.simple(john) igc_file.weglide_status = 1 db_session.add(igc_file) path = files.filename_to_path(igc_file.filename) copyfile(igcs.simple_path, path) db_session.flush() return (john, igc_file)
def test_phases(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john()), takeoff_time=datetime(2016, 5, 4, 8, 12, 46)) add_fixtures(db_session, flight, flight_phases.example1(flight=flight), flight_phases.example2(flight=flight)) expected_flight = expected_basic_flight_json(flight) expected_flight['takeoffTime'] = '2016-05-04T08:12:46+00:00' res = client.get('/flights/{id}?extended'.format(id=flight.id)) assert res.status_code == 200 assert res.json == { u'flight': expected_flight, u'near_flights': [], u'comments': [], u'contest_legs': { u'classic': [], u'triangle': [], }, u'phases': [{ u'circlingDirection': u'right', u'type': u'circling', u'secondsOfDay': 64446, u'startTime': u'2016-05-04T17:54:06+00:00', u'duration': 300, u'altDiff': 417.0, u'distance': 7028.0, u'vario': 1.39000000000002, u'speed': 23.4293014168156, u'glideRate': -16.8556125300829 }, { u'circlingDirection': None, u'type': u'cruise', u'secondsOfDay': 64746, u'startTime': u'2016-05-04T17:59:06+00:00', u'duration': 44, u'altDiff': -93.0, u'distance': 977.0, u'vario': -2.11363636363637, u'speed': 22.2232648999519, u'glideRate': 10.5142328558912 }], u'performance': { u'circling': [], u'cruise': {}, } }
def test_contest_legs(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) leg1 = contest_legs.first(flight=flight) leg2 = contest_legs.empty(flight=flight) leg3 = contest_legs.first(flight=flight, trace_type='triangle') add_fixtures(db_session, flight, leg1, leg2, leg3) res = client.get('/flights/{id}?extended'.format(id=flight.id)) assert res.status_code == 200 assert res.json == { u'flight': expected_basic_flight_json(flight), u'near_flights': [], u'comments': [], u'contest_legs': { u'classic': [{ u'distance': 234833.0, u'duration': 2880, u'start': 33383, u'climbDuration': 5252, u'climbHeight': 6510.0, u'cruiseDistance': 241148.0, u'cruiseHeight': -6491.0, }, { u'distance': None, u'duration': 480, u'start': 36743, u'climbDuration': None, u'climbHeight': None, u'cruiseDistance': None, u'cruiseHeight': None, }], u'triangle': [{ u'distance': 234833.0, u'duration': 2880, u'start': 33383, u'climbDuration': 5252, u'climbHeight': 6510.0, u'cruiseDistance': 241148.0, u'cruiseHeight': -6491.0, }], }, u'phases': [], u'performance': { u'circling': [], u'cruise': {}, }, }
def test_contest_legs(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) leg1 = contest_legs.first(flight=flight) leg2 = contest_legs.empty(flight=flight) leg3 = contest_legs.first(flight=flight, trace_type='triangle') add_fixtures(db_session, flight, leg1, leg2, leg3) res = client.get('/flights/{id}?extended'.format(id=flight.id)) assert res.status_code == 200 assert res.json == { u'flight': expected_basic_flight_json(flight), u'near_flights': [], u'comments': [], u'contest_legs': { u'classic': [{ u'distance': 234833.0, u'duration': 2880, u'start': 33383, u'climbDuration': 5252, u'climbHeight': 6510.0, u'cruiseDistance': 241148.0, u'cruiseHeight': -6491.0, }, { u'distance': None, u'duration': 480, u'start': 36743, u'climbDuration': None, u'climbHeight': None, u'cruiseDistance': None, u'cruiseHeight': None, }], u'triangle': [{ u'distance': 234833.0, u'duration': 2880, u'start': 33383, u'climbDuration': 5252, u'climbHeight': 6510.0, u'cruiseDistance': 241148.0, u'cruiseHeight': -6491.0, }], }, u'phases': [], u'performance': { u'circling': [], u'cruise': {}, }, }
def test_comments(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) comment1 = flight_comments.yeah(flight=flight) comment2 = flight_comments.emoji(flight=flight) comment3 = flight_comments.yeah(flight=flight, user=flight.igc_file.owner, text=u'foo') comment4 = flight_comments.yeah(flight=flight, text=u'bar') comment5 = flight_comments.yeah(flight=flight, user=users.jane(), text=u'baz') add_fixtures(db_session, flight, comment1, comment2, comment3, comment4, comment5) res = client.get('/flights/{id}?extended'.format(id=flight.id)) assert res.status_code == 200 assert res.json == { u'flight': expected_basic_flight_json(flight), u'near_flights': [], u'comments': [{ u'user': None, u'text': u'Yeah!', }, { u'user': None, u'text': u'\U0001f44d', }, { u'user': { u'id': comment3.user.id, u'name': u'John Doe' }, u'text': u'foo', }, { u'user': None, u'text': u'bar', }, { u'user': { u'id': comment5.user.id, u'name': u'Jane Doe' }, u'text': u'baz', }], u'contest_legs': { u'classic': [], u'triangle': [], }, u'phases': [], u'performance': { u'circling': [], u'cruise': {}, }, }
def test_pilot_changing_same_pilot_and_co(db_session, client): """ Pilot is trying to change copilot to the same as pilot. """ john = users.john(club=clubs.lva()) flight = flights.one(igc_file=igcs.simple(owner=john)) add_fixtures(db_session, flight, john) response = client.post( "/flights/{id}".format(id=flight.id), headers=auth_for(john), json={ "pilotId": john.id, "copilotId": john.id }, ) assert response.status_code == 422
def test_pilot_changing_pilot_and_co_null(db_session, client): """ Pilot is changing pilot and copilot to unknown user accounts. """ john = users.john(club=clubs.lva()) flight = flights.one(igc_file=igcs.simple(owner=john)) add_fixtures(db_session, flight, john) response = client.post( "/flights/{id}".format(id=flight.id), headers=auth_for(john), json={ "pilotName": "foo", "copilotName": "bar" }, ) assert response.status_code == 200
def test_pilot_changing_disallowed_copilot(db_session, client): """ Pilot is trying to change copilot to user from different club. """ john = users.john(club=clubs.lva()) max = users.max(club=clubs.sfn()) flight = flights.one(igc_file=igcs.simple(owner=john)) add_fixtures(db_session, flight, john, max) response = client.post( "/flights/{id}".format(id=flight.id), headers=auth_for(john), json={ "pilotId": john.id, "copilotId": max.id }, ) assert response.status_code == 422
def test_pilot_changing_correct_with_co(db_session, client): """ Pilot is changing copilot to user from same club. """ john = users.john(club=clubs.lva()) jane = users.jane(club=john.club) flight = flights.one(igc_file=igcs.simple(owner=john)) add_fixtures(db_session, flight, john, jane) response = client.post( "/flights/{id}".format(id=flight.id), headers=auth_for(john), json={ "pilotId": john.id, "copilotId": jane.id }, ) assert response.status_code == 200
def test_pilot_changing_clubless_pilot_and_co(db_session, client): """ Pilot without club is trying to change copilot to user without club. """ john = users.john() jane = users.jane() flight = flights.one(igc_file=igcs.simple(owner=john)) add_fixtures(db_session, flight, john, jane) response = client.post( "/flights/{id}".format(id=flight.id), headers=auth_for(john), json={ "pilotId": john.id, "copilotId": jane.id }, ) assert response.status_code == 422
def test_pilot_changing_disowned_flight(db_session, client): """ Unrelated user is trying to change pilots. """ john = users.john(club=clubs.lva()) jane = users.jane(club=john.club) max = users.max(club=clubs.sfn()) flight = flights.one(igc_file=igcs.simple(owner=john)) add_fixtures(db_session, flight, john, jane, max) response = client.post( "/flights/{id}".format(id=flight.id), headers=auth_for(jane), json={ "pilotId": john.id, "copilotId": max.id }, ) assert response.status_code == 403
def test_unauthenticated(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) comment = flight_comments.yeah(flight=flight) add_fixtures(db_session, flight, comment) res = client.get("/flights/{id}?extended".format(id=flight.id)) assert res.status_code == 200 assert res.json["comments"] == [{u"user": None, u"text": u"Yeah!"}] res = client.post("/flights/{id}/comments".format(id=flight.id), json={u"text": u"foobar"}) assert res.status_code == 401 assert res.json == { u"error": u"invalid_token", u"message": u"Bearer token not found.", } res = client.get("/flights/{id}?extended".format(id=flight.id)) assert res.status_code == 200 assert res.json["comments"] == [{u"user": None, u"text": u"Yeah!"}]
def test_user_delete_deletes_owned_igc_files(db_session): with open(igcs.simple_path, "r") as f: filename = files.add_file("simple.igc", f) assert filename is not None assert os.path.isfile(files.filename_to_path(filename)) john = users.john() igc = igcs.simple(owner=john, filename=filename) db_session.add(igc) db_session.commit() assert db_session.query(IGCFile).count() == 1 assert db_session.query(IGCFile).get(igc.id).owner_id == john.id john.delete() db_session.commit() assert db_session.query(IGCFile).count() == 0 assert not os.path.isfile(files.filename_to_path(filename))
def test_user_delete_deletes_owned_igc_files(db_session): with open(igcs.simple_path, 'r') as f: filename = files.add_file('simple.igc', f) assert filename is not None assert os.path.isfile(files.filename_to_path(filename)) john = users.john() igc = igcs.simple(owner=john, filename=filename) db_session.add(igc) db_session.commit() assert db_session.query(IGCFile).count() == 1 assert db_session.query(IGCFile).get(igc.id).owner_id == john.id john.delete() db_session.commit() assert db_session.query(IGCFile).count() == 0 assert not os.path.isfile(files.filename_to_path(filename))
def test_empty_extended(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) add_fixtures(db_session, flight) res = client.get("/flights/{id}?extended".format(id=flight.id)) assert res.status_code == 200 assert res.json == { u"flight": expected_basic_flight_json(flight), u"near_flights": [], u"comments": [], u"contest_legs": { u"classic": [], u"triangle": [] }, u"phases": [], u"performance": { u"circling": [], u"cruise": {} }, }
def test_empty_extended(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) add_fixtures(db_session, flight) res = client.get('/flights/{id}?extended'.format(id=flight.id)) assert res.status_code == 200 assert res.json == { u'flight': expected_basic_flight_json(flight), u'near_flights': [], u'comments': [], u'contest_legs': { u'classic': [], u'triangle': [], }, u'phases': [], u'performance': { u'circling': [], u'cruise': {}, }, }
def test_empty_extended(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) add_fixtures(db_session, flight) res = client.get('/flights/{id}?extended'.format(id=flight.id)) assert res.status_code == 200 assert res.json == { u'flight': expected_basic_flight_json(flight), u'near_flights': [], u'comments': [], u'contest_legs': { u'classic': [], u'triangle': [], }, u'phases': [], u'performance': { u'circling': [], u'cruise': {}, }, }
def test_unauthenticated(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) comment = flight_comments.yeah(flight=flight) add_fixtures(db_session, flight, comment) res = client.get("/flights/{id}?extended".format(id=flight.id)) assert res.status_code == 200 assert res.json["comments"] == [{u"user": None, u"text": u"Yeah!"}] res = client.post( "/flights/{id}/comments".format(id=flight.id), json={u"text": u"foobar"} ) assert res.status_code == 401 assert res.json == { u"error": u"invalid_token", u"message": u"Bearer token not found.", } res = client.get("/flights/{id}?extended".format(id=flight.id)) assert res.status_code == 200 assert res.json["comments"] == [{u"user": None, u"text": u"Yeah!"}]
def test_create(db_session, client): john = users.john() flight = flights.one(igc_file=igcs.simple(owner=john)) comment = flight_comments.yeah(flight=flight) add_fixtures(db_session, flight, comment, john) res = client.get("/flights/{id}?extended".format(id=flight.id)) assert res.status_code == 200 assert res.json["comments"] == [{u"user": None, u"text": u"Yeah!"}] res = client.post( "/flights/{id}/comments".format(id=flight.id), headers=auth_for(john), json={u"text": u"foobar"}, ) assert res.status_code == 200 assert res.json == {} res = client.get("/flights/{id}?extended".format(id=flight.id)) assert res.status_code == 200 assert res.json["comments"] == [ {u"user": None, u"text": u"Yeah!"}, {u"user": {u"id": john.id, u"name": u"John Doe"}, u"text": u"foobar"}, ]
def test_event_types(db_session, client): john = users.john() jane = users.jane() lva = clubs.lva() add_fixtures(db_session, john, jane, lva) flight = flights.one(igc_file=igcs.simple(owner=john)) flight_comment = flight_comments.emoji(flight=flight, user=john) add_fixtures(db_session, flight, flight_comment) flight_event = events.flight(flight) flight_comment_event = events.flight_comment(flight_comment) follower_event = events.follower(actor=john, user=jane) new_user_event = events.new_user(jane) club_join_event = events.club_join(actor=john, club=lva) add_fixtures(db_session, flight_event, flight_comment_event, follower_event, new_user_event, club_join_event) res = client.get('/timeline') assert res.status_code == 200 assert res.json == { 'events': [{ 'id': club_join_event.id, 'type': 'club-join', 'time': '2017-02-15T12:34:56', 'actor': { 'id': john.id, 'name': 'John Doe', }, 'club': { 'id': club_join_event.club.id, 'name': 'LV Aachen', }, }, { 'id': new_user_event.id, 'type': 'new-user', 'time': '2017-02-14T12:34:56', 'actor': { 'id': jane.id, 'name': 'Jane Doe', }, }, { 'id': follower_event.id, 'type': 'follower', 'time': '2017-02-13T12:34:56', 'actor': { 'id': john.id, 'name': 'John Doe', }, 'user': { 'id': jane.id, 'name': 'Jane Doe', }, }, { 'id': flight_event.id, 'type': 'flight-upload', 'time': '2017-02-12T12:34:56', 'actor': { 'id': john.id, 'name': 'John Doe', }, 'flight': { 'id': flight.id, 'date': '2011-06-18', 'pilot_id': john.id, 'copilot_id': None, 'distance': None, }, }, { 'id': flight_comment_event.id, 'type': 'flight-comment', 'time': '2017-02-11T12:34:56', 'actor': { 'id': john.id, 'name': 'John Doe', }, 'flightComment': { 'id': flight_comment.id, }, 'flight': { 'id': flight.id, 'date': '2011-06-18', 'pilot_id': john.id, 'copilot_id': None, 'distance': None, }, }] }
def test_performance(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) add_fixtures( db_session, flight, flight_phases.cruise(flight=flight), flight_phases.circling(flight=flight), flight_phases.circling_left(flight=flight), flight_phases.circling_right(flight=flight), flight_phases.circling_mixed(flight=flight), ) res = client.get("/flights/{id}?extended".format(id=flight.id)) assert res.status_code == 200 assert res.json == { u"flight": expected_basic_flight_json(flight), u"near_flights": [], u"comments": [], u"contest_legs": { u"classic": [], u"triangle": [] }, u"phases": [], u"performance": { u"circling": [ { u"circlingDirection": u"total", u"duration": 14472, u"altDiff": 19543.0, u"vario": 1.35046987285793, u"fraction": 37.0, u"count": 78, }, { u"circlingDirection": u"left", u"duration": 3776, u"altDiff": 5335.0, u"vario": 1.41313559322034, u"fraction": 26.0, u"count": 17, }, { u"circlingDirection": u"right", u"duration": 7900, u"altDiff": 11344.0, u"vario": 1.43607594936709, u"fraction": 55.0, u"count": 54, }, { u"circlingDirection": u"mixed", u"duration": 2796, u"altDiff": 2863.0, u"vario": 1.02396280400573, u"fraction": 19.0, u"count": 7, }, ], u"cruise": { u"duration": 24312, u"altDiff": -20647.0, u"distance": 837677.0, u"vario": -0.849292530437643, u"speed": 34.4552944491395, u"glideRate": 40.5694071410054, u"fraction": 63.0, u"count": 79, }, }, }
def test_meetings(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) flight2 = flights.one( igc_file=igcs.simple(owner=users.jane(), md5="foobar")) meeting1 = FlightMeetings( source=flight, destination=flight2, start_time=datetime(2016, 4, 3, 12, 34, 56), end_time=datetime(2016, 4, 3, 12, 38, 1), ) meeting2 = FlightMeetings( source=flight2, destination=flight, start_time=datetime(2016, 4, 3, 12, 56, 36), end_time=datetime(2016, 4, 3, 13, 1, 31), ) add_fixtures(db_session, flight, flight2, meeting1, meeting2) res = client.get("/flights/{id}?extended".format(id=flight.id)) assert res.status_code == 200 assert res.json == { u"flight": expected_basic_flight_json(flight), u"near_flights": [{ u"flight": { u"id": flight2.id, u"pilot": { u"id": flight2.pilot.id, u"name": u"Jane Doe" }, u"pilotName": None, u"copilot": None, u"copilotName": None, u"model": None, u"registration": None, u"competitionId": None, u"igcFile": { u"filename": u"simple.igc", u"date": u"2011-06-18", u"registration": None, u"owner": { u"id": flight2.igc_file.owner.id, u"name": u"Jane Doe", }, u"model": None, u"competitionId": None, }, }, u"times": [ { u"start": u"2016-04-03T12:34:56+00:00", u"end": u"2016-04-03T12:38:01+00:00", }, { u"start": u"2016-04-03T12:56:36+00:00", u"end": u"2016-04-03T13:01:31+00:00", }, ], }], u"comments": [], u"contest_legs": { u"classic": [], u"triangle": [] }, u"phases": [], u"performance": { u"circling": [], u"cruise": {} }, }
def test_meetings(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) flight2 = flights.one(igc_file=igcs.simple(owner=users.jane(), md5='foobar')) meeting1 = FlightMeetings( source=flight, destination=flight2, start_time=datetime(2016, 4, 3, 12, 34, 56), end_time=datetime(2016, 4, 3, 12, 38, 1), ) meeting2 = FlightMeetings( source=flight2, destination=flight, start_time=datetime(2016, 4, 3, 12, 56, 36), end_time=datetime(2016, 4, 3, 13, 1, 31), ) add_fixtures(db_session, flight, flight2, meeting1, meeting2) res = client.get('/flights/{id}?extended'.format(id=flight.id)) assert res.status_code == 200 assert res.json == { u'flight': expected_basic_flight_json(flight), u'near_flights': [{ u'flight': { u'id': flight2.id, u'pilot': { u'id': flight2.pilot.id, u'name': u'Jane Doe', }, u'pilotName': None, u'copilot': None, u'copilotName': None, u'model': None, u'registration': None, u'competitionId': None, u'igcFile': { u'filename': u'simple.igc', u'date': u'2011-06-18', u'registration': None, u'owner': { u'id': flight2.igc_file.owner.id, u'name': u'Jane Doe', }, u'model': None, u'competitionId': None, }, }, u'times': [{ u'start': u'2016-04-03T12:34:56+00:00', u'end': u'2016-04-03T12:38:01+00:00', }, { u'start': u'2016-04-03T12:56:36+00:00', u'end': u'2016-04-03T13:01:31+00:00', }], }], u'comments': [], u'contest_legs': { u'classic': [], u'triangle': [], }, u'phases': [], u'performance': { u'circling': [], u'cruise': {}, }, }
def test_performance(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) add_fixtures(db_session, flight, flight_phases.cruise(flight=flight), flight_phases.circling(flight=flight), flight_phases.circling_left(flight=flight), flight_phases.circling_right(flight=flight), flight_phases.circling_mixed(flight=flight)) res = client.get('/flights/{id}?extended'.format(id=flight.id)) assert res.status_code == 200 assert res.json == { u'flight': expected_basic_flight_json(flight), u'near_flights': [], u'comments': [], u'contest_legs': { u'classic': [], u'triangle': [], }, u'phases': [], u'performance': { u'circling': [{ u'circlingDirection': u'total', u'duration': 14472, u'altDiff': 19543.0, u'vario': 1.35046987285793, u'fraction': 37.0, u'count': 78, }, { u'circlingDirection': u'left', u'duration': 3776, u'altDiff': 5335.0, u'vario': 1.41313559322034, u'fraction': 26.0, u'count': 17, }, { u'circlingDirection': u'right', u'duration': 7900, u'altDiff': 11344.0, u'vario': 1.43607594936709, u'fraction': 55.0, u'count': 54, }, { u'circlingDirection': u'mixed', u'duration': 2796, u'altDiff': 2863.0, u'vario': 1.02396280400573, u'fraction': 19.0, u'count': 7, }], u'cruise': { u'duration': 24312, u'altDiff': -20647.0, u'distance': 837677.0, u'vario': -0.849292530437643, u'speed': 34.4552944491395, u'glideRate': 40.5694071410054, u'fraction': 63.0, u'count': 79 } } }
def test_performance(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) add_fixtures(db_session, flight, flight_phases.cruise(flight=flight), flight_phases.circling(flight=flight), flight_phases.circling_left(flight=flight), flight_phases.circling_right(flight=flight), flight_phases.circling_mixed(flight=flight)) res = client.get('/flights/{id}?extended'.format(id=flight.id)) assert res.status_code == 200 assert res.json == { u'flight': expected_basic_flight_json(flight), u'near_flights': [], u'comments': [], u'contest_legs': { u'classic': [], u'triangle': [], }, u'phases': [], u'performance': { u'circling': [{ u'circlingDirection': u'total', u'duration': 14472, u'altDiff': 19543.0, u'vario': 1.35046987285793, u'fraction': 37.0, u'count': 78, }, { u'circlingDirection': u'left', u'duration': 3776, u'altDiff': 5335.0, u'vario': 1.41313559322034, u'fraction': 26.0, u'count': 17, }, { u'circlingDirection': u'right', u'duration': 7900, u'altDiff': 11344.0, u'vario': 1.43607594936709, u'fraction': 55.0, u'count': 54, }, { u'circlingDirection': u'mixed', u'duration': 2796, u'altDiff': 2863.0, u'vario': 1.02396280400573, u'fraction': 19.0, u'count': 7, }], u'cruise': { u'duration': 24312, u'altDiff': -20647.0, u'distance': 837677.0, u'vario': -0.849292530437643, u'speed': 34.4552944491395, u'glideRate': 40.5694071410054, u'fraction': 63.0, u'count': 79 } } }
def test_meetings(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) flight2 = flights.one( igc_file=igcs.simple(owner=users.jane(), md5='foobar')) meeting1 = FlightMeetings( source=flight, destination=flight2, start_time=datetime(2016, 4, 3, 12, 34, 56), end_time=datetime(2016, 4, 3, 12, 38, 1), ) meeting2 = FlightMeetings( source=flight2, destination=flight, start_time=datetime(2016, 4, 3, 12, 56, 36), end_time=datetime(2016, 4, 3, 13, 1, 31), ) add_fixtures(db_session, flight, flight2, meeting1, meeting2) res = client.get('/flights/{id}?extended'.format(id=flight.id)) assert res.status_code == 200 assert res.json == { u'flight': expected_basic_flight_json(flight), u'near_flights': [{ u'flight': { u'id': flight2.id, u'pilot': { u'id': flight2.pilot.id, u'name': u'Jane Doe', }, u'pilotName': None, u'copilot': None, u'copilotName': None, u'model': None, u'registration': None, u'competitionId': None, u'igcFile': { u'filename': u'simple.igc', u'date': u'2011-06-18', u'registration': None, u'owner': { u'id': flight2.igc_file.owner.id, u'name': u'Jane Doe', }, u'model': None, u'competitionId': None, }, }, u'times': [{ u'start': u'2016-04-03T12:34:56+00:00', u'end': u'2016-04-03T12:38:01+00:00', }, { u'start': u'2016-04-03T12:56:36+00:00', u'end': u'2016-04-03T13:01:31+00:00', }], }], u'comments': [], u'contest_legs': { u'classic': [], u'triangle': [], }, u'phases': [], u'performance': { u'circling': [], u'cruise': {}, }, }
def test_event_types(db_session, client): john = users.john() jane = users.jane() lva = clubs.lva() add_fixtures(db_session, john, jane, lva) flight = flights.one(igc_file=igcs.simple(owner=john)) flight_comment = flight_comments.emoji(flight=flight, user=john) add_fixtures(db_session, flight, flight_comment) flight_event = events.flight(flight) flight_comment_event = events.flight_comment(flight_comment) follower_event = events.follower(actor=john, user=jane) new_user_event = events.new_user(jane) club_join_event = events.club_join(actor=john, club=lva) add_fixtures( db_session, flight_event, flight_comment_event, follower_event, new_user_event, club_join_event, ) res = client.get("/timeline") assert res.status_code == 200 assert res.json == { "events": [ { "id": club_join_event.id, "type": "club-join", "time": "2017-02-15T12:34:56+00:00", "actor": { "id": john.id, "name": "John Doe" }, "club": { "id": club_join_event.club.id, "name": "LV Aachen" }, }, { "id": new_user_event.id, "type": "new-user", "time": "2017-02-14T12:34:56+00:00", "actor": { "id": jane.id, "name": "Jane Doe" }, }, { "id": follower_event.id, "type": "follower", "time": "2017-02-13T12:34:56+00:00", "actor": { "id": john.id, "name": "John Doe" }, "user": { "id": jane.id, "name": "Jane Doe" }, }, { "id": flight_event.id, "type": "flight-upload", "time": "2017-02-12T12:34:56+00:00", "actor": { "id": john.id, "name": "John Doe" }, "flight": { "id": flight.id, "date": "2011-06-18", "pilot_id": john.id, "copilot_id": None, "distance": None, }, }, { "id": flight_comment_event.id, "type": "flight-comment", "time": "2017-02-11T12:34:56+00:00", "actor": { "id": john.id, "name": "John Doe" }, "flightComment": { "id": flight_comment.id }, "flight": { "id": flight.id, "date": "2011-06-18", "pilot_id": john.id, "copilot_id": None, "distance": None, }, }, ] }