def test_delete_user_invalidates_auth_tokens(client, test_user, test_admin): res = client.get('/settings'.format(id=test_user.id), headers=auth_for(test_user)) assert res.status_code == 200 res = client.delete('/users/{id}'.format(id=test_user.id), headers=auth_for(test_admin)) assert res.status_code == 200 assert res.json == {} res = client.get('/settings'.format(id=test_user.id), headers=auth_for(test_user)) assert res.status_code == 401
def test_delete_account_invalidates_auth_tokens(client, test_user): res = client.get('/settings'.format(id=test_user.id), headers=auth_for(test_user)) assert res.status_code == 200 res = client.delete('/account', headers=auth_for(test_user), json={ 'password': test_user.original_password, }) assert res.status_code == 200 assert res.json == {} res = client.get('/settings'.format(id=test_user.id), headers=auth_for(test_user)) assert res.status_code == 401
def test_basic_flight_json(db_session, client): # add user john = users.john() db_session.add(john) db_session.commit() # upload flight data = dict(files=(igcs.simple_path, )) res = client.post("/flights/upload", headers=auth_for(john), data=data) assert res.status_code == 200 flight_id = res.json["results"][0]["flight"]["id"] res = client.get("/flights/{id}/json".format(id=flight_id), headers=auth_for(john)) assert res.status_code == 200 assert res.json == S({ u"additional": { u"competition_id": None, u"model": None, u"registration": u"LY-KDR", }, u"barogram_h": u"cH??D?EKOk@o@U}@k@OGUIEg@c@S[KIKKKI[]_@a@WSGYQk@", u"barogram_t": u"ik_A{B{@gASISSg@]S]]IIIIMIIISIIISIIIIIIIIIIII", u"contests": Unordered([ { u"name": u"olc_plus triangle", u"times": u"{y_AgBeAyAS", u"turnpoints": u"mejkIyljwC~_@{y@}~@dp@|j@t{AnEgJ", }, { u"name": u"olc_plus classic", u"times": u"ur_AeHg@]g@eAg@", u"turnpoints": u"ypokI{wowCdsEhzDyFcjAu_@]g^bq@v[d{AtTwI", }, ]), u"elevations_h": u"", u"elevations_t": u"", u"enl": u"", u"geoid": Approx(25.15502072293512), u"points": u"syokIm|owC????lYxKbQrIrGlBlPjH|N`Kn[l[tRjZ~LrPpRz^tP|`@lFnHrG`CvGz@xDYjCiI`@cQq@mVgBmQgFwVcNjAkMhDuHrGwNrWyDzOOzPh@fQ`B~OpCfMxDbJxEtGtF~CrFz@pFk@`CsAlAsG", u"sfid": int, })
def test_existing_club(db_session, client, test_user): lva = clubs.lva() add_fixtures(db_session, lva) res = client.put("/clubs", headers=auth_for(test_user), json={"name": "LV Aachen"}) assert res.status_code == 422 assert res.json["error"] == "duplicate-club-name"
def test_create(db_session, client, test_user): res = client.put("/clubs", headers=auth_for(test_user), json={"name": "LV Aachen"}) assert res.status_code == 200 club = Club.get(res.json["id"]) assert club assert club.owner_id == test_user.id
def test_delete_account_with_wrong_password(client, test_user): res = client.delete('/account', headers=auth_for(test_user), json={ 'password': '******', }) assert res.status_code == 403
def test_clear_all(db_session, client): john = users.john() jane = users.jane() max = users.max() create_follower_notification(john, jane) create_follower_notification(john, max) create_follower_notification(jane, max) db_session.commit() res = client.post('/notifications/clear', headers=auth_for(john)) assert res.status_code == 200 assert res.json == {} johns_notifications = db_session.query(Notification).filter_by( recipient=john).all() assert len(johns_notifications) == 2 assert johns_notifications[0].event.actor_id == jane.id assert johns_notifications[0].time_read is not None assert johns_notifications[1].event.actor_id == max.id assert johns_notifications[1].time_read is not None janes_notifications = db_session.query(Notification).filter_by( recipient=jane).all() assert len(janes_notifications) == 1 assert janes_notifications[0].event.actor_id == max.id assert janes_notifications[0].time_read is None
def test_clear_all(db_session, client): john = users.john() jane = users.jane() max = users.max() create_follower_notification(john, jane) create_follower_notification(john, max) create_follower_notification(jane, max) db_session.commit() res = client.post("/notifications/clear", headers=auth_for(john)) assert res.status_code == 200 assert res.json == {} johns_notifications = db_session.query(Notification).filter_by(recipient=john).all() assert len(johns_notifications) == 2 assert johns_notifications[0].event.actor_id == jane.id assert johns_notifications[0].time_read is not None assert johns_notifications[1].event.actor_id == max.id assert johns_notifications[1].time_read is not None janes_notifications = db_session.query(Notification).filter_by(recipient=jane).all() assert len(janes_notifications) == 1 assert janes_notifications[0].event.actor_id == max.id assert janes_notifications[0].time_read is None
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_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_delete_user_as_other_user(db_session, client, test_user): john = users.john() db_session.add(john) db_session.commit() res = client.delete('/users/{id}'.format(id=test_user.id), headers=auth_for(john)) assert res.status_code == 403
def test_missing(db_session, client, test_user): res = client.post( "/clubs/1000000000", headers=auth_for(test_user), json={"name": "foobar", "website": "https://foobar.de"}, ) assert res.status_code == 404
def test_non_json_data(db_session, client, test_user): sfn = clubs.sfn() test_user.club = sfn add_fixtures(db_session, sfn) res = client.post('/clubs/{id}'.format(id=sfn.id), headers=auth_for(test_user), data='foobar?') assert res.status_code == 400 assert res.json['error'] == 'invalid-request'
def test_invalid_json(db_session, client): john = users.john() add_fixtures(db_session, john) res = client.post( "/settings/password/check", headers=auth_for(john), data="foobar?" ) assert res.status_code == 400
def test_invalid_json(db_session, client): john = users.john() add_fixtures(db_session, john) res = client.post("/settings/password/check", headers=auth_for(john), data="foobar?") assert res.status_code == 400
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_missing(db_session, client, test_user): res = client.post('/clubs/1000000000', headers=auth_for(test_user), json={ 'name': 'foobar', 'website': 'https://foobar.de', }) assert res.status_code == 404
def test_upload_multiple(db_session, client): john = users.john() db_session.add(john) db_session.commit() data = MultiDict() data.add("pilotName", "JD ") data.add("files", (igcs.simple_path,)) data.add("files", (igcs.hornet_path,)) res = client.post("/flights/upload", headers=auth_for(john), data=data) assert res.status_code == 200 assert res.json == S( { u"club_members": [], u"aircraft_models": [], u"results": ExactSequence( [ { u"status": 0, u"cacheKey": text_type, u"flight": Partial( { u"club": None, u"copilot": None, u"copilotName": None, u"distance": 7872, u"igcFile": dict, u"pilot": None, u"pilotName": "JD", } ), u"name": Match(r".*simple\.igc"), u"trace": dict, u"airspaces": [], }, { u"status": 0, u"cacheKey": text_type, u"flight": Partial( { u"club": None, u"copilot": None, u"copilotName": None, u"distance": 171246, u"igcFile": dict, u"pilot": None, u"pilotName": "JD", } ), u"name": Match(r".*2018-04-14-fla-6ng-01\.igc"), u"trace": dict, u"airspaces": [], }, ] ), } )
def test_basic_flight_json(db_session, client): # add user john = users.john() db_session.add(john) db_session.commit() # upload flight data = dict(files=(igcs.simple_path,)) res = client.post("/flights/upload", headers=auth_for(john), data=data) assert res.status_code == 200 flight_id = res.json["results"][0]["flight"]["id"] res = client.get("/flights/{id}/json".format(id=flight_id), headers=auth_for(john)) assert res.status_code == 200 assert res.json == S( { u"additional": { u"competition_id": None, u"model": None, u"registration": u"LY-KDR", }, u"barogram_h": u"cH??D?EKOk@o@U}@k@OGUIEg@c@S[KIKKKI[]_@a@WSGYQk@", u"barogram_t": u"ik_A{B{@gASISSg@]S]]IIIIMIIISIIISIIIIIIIIIIII", u"contests": Unordered( [ { u"name": u"olc_plus triangle", u"times": u"{y_AgBeAyAS", u"turnpoints": u"mejkIyljwC~_@{y@}~@dp@|j@t{AnEgJ", }, { u"name": u"olc_plus classic", u"times": u"ur_AeHg@]g@eAg@", u"turnpoints": u"ypokI{wowCdsEhzDyFcjAu_@]g^bq@v[d{AtTwI", }, ] ), u"elevations_h": u"", u"elevations_t": u"", u"enl": u"", u"geoid": Approx(25.15502072293512), u"points": u"syokIm|owC????lYxKbQrIrGlBlPjH|N`Kn[l[tRjZ~LrPpRz^tP|`@lFnHrG`CvGz@xDYjCiI`@cQq@mVgBmQgFwVcNjAkMhDuHrGwNrWyDzOOzPh@fQ`B~OpCfMxDbJxEtGtF~CrFz@pFk@`CsAlAsG", u"sfid": int, } )
def test_incorrect_password(db_session, client): john = users.john() add_fixtures(db_session, john) res = client.post( "/settings/password/check", headers=auth_for(john), json={"password": "******"} ) assert res.status_code == 200 assert res.json == {"result": False}
def test_correct_password(db_session, client): john = users.john() add_fixtures(db_session, john) res = client.post('/settings/password/check', headers=auth_for(john), json={ 'password': john.original_password, }) assert res.status_code == 200 assert res.json == {'result': True}
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_existing_club(db_session, client, test_user): lva = clubs.lva() add_fixtures(db_session, lva) res = client.put('/clubs', headers=auth_for(test_user), json={ 'name': 'LV Aachen', }) assert res.status_code == 422 assert res.json['error'] == 'duplicate-club-name'
def test_missing_flight(db_session, client): john = users.john() add_fixtures(db_session, john) res = client.post('/flights/{id}/comments'.format(id=1000000), headers=auth_for(john), json={ u'text': u'foobar', }) assert res.status_code == 404 assert res.json == {u'message': u'Sorry, there is no such record (1000000) in our database.'}
def test_upload_with_weglide(db_session, client): john = users.john() db_session.add(john) db_session.commit() data = dict( pilotId=john.id, weglideUserId="123", weglideBirthday="2020-01-07", files=(igcs.simple_path,), ) with patch.object(tasks.upload_to_weglide, "delay", return_value=None) as mock: res = client.post("/flights/upload", headers=auth_for(john), data=data) mock.assert_called_once() assert len(mock.call_args.args) == 3 assert mock.call_args.args[1] == 123 assert mock.call_args.args[2] == "2020-01-07" assert res.status_code == 200 assert res.json == S( { u"club_members": list, u"aircraft_models": list, u"results": ExactSequence( [ { u"status": 0, u"cacheKey": IsTrue(), u"flight": Partial( { u"club": None, u"copilot": None, u"copilotName": None, u"distance": 7872, u"igcFile": Partial( { u"weglideStatus": 1, u"weglideData": None, } ), u"pilotName": None, u"pilot": { u"id": john.id, u"name": john.name, }, } ), u"name": Match(r".*simple.igc"), u"trace": dict, u"airspaces": [], } ] ), } )
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_incorrect_password(db_session, client): john = users.john() add_fixtures(db_session, john) res = client.post("/settings/password/check", headers=auth_for(john), json={"password": "******"}) assert res.status_code == 200 assert res.json == {"result": False}
def test_create(db_session, client, test_user): res = client.put('/clubs', headers=auth_for(test_user), json={ 'name': 'LV Aachen', }) assert res.status_code == 200 club = Club.get(res.json['id']) assert club assert club.owner_id == test_user.id
def test_delete_user_as_admin(client, test_user, test_admin): res = client.get('/users/{id}'.format(id=test_user.id)) assert res.status_code == 200 res = client.delete('/users/{id}'.format(id=test_user.id), headers=auth_for(test_admin)) assert res.status_code == 200 assert res.json == {} res = client.get('/users/{id}'.format(id=test_user.id)) assert res.status_code == 404
def test_invalid_data(db_session, client, test_user): sfn = clubs.sfn() test_user.club = sfn add_fixtures(db_session, sfn) res = client.post("/clubs/{id}".format(id=sfn.id), headers=auth_for(test_user), json={"name": ""}) assert res.status_code == 422 assert res.json["error"] == "validation-failed"
def test_invalid_id(db_session, client, test_user): res = client.post( "/clubs/abc", headers=auth_for(test_user), json={ "name": "foobar", "website": "https://foobar.de" }, ) assert res.status_code == 404
def test_non_json_data(db_session, client, test_user): sfn = clubs.sfn() test_user.club = sfn add_fixtures(db_session, sfn) res = client.post("/clubs/{id}".format(id=sfn.id), headers=auth_for(test_user), data="foobar?") assert res.status_code == 400 assert res.json["error"] == "invalid-request"
def test_invalid_data(db_session, client, test_user): sfn = clubs.sfn() test_user.club = sfn add_fixtures(db_session, sfn) res = client.post( "/clubs/{id}".format(id=sfn.id), headers=auth_for(test_user), json={"name": ""} ) assert res.status_code == 422 assert res.json["error"] == "validation-failed"
def test_invalid_data(db_session, client, test_user): sfn = clubs.sfn() test_user.club = sfn add_fixtures(db_session, sfn) res = client.post('/clubs/{id}'.format(id=sfn.id), headers=auth_for(test_user), json={ 'name': '', }) assert res.status_code == 422 assert res.json['error'] == 'validation-failed'
def test_unknown_pilot_id(db_session, client): john = users.john() db_session.add(john) db_session.commit() data = dict(pilotId=42, files=(igcs.simple_path,)) res = client.post("/flights/upload", headers=auth_for(john), data=data) assert res.status_code == 422 assert res.json == {u"error": u"unknown-pilot"}
def test_correct_password(db_session, client): john = users.john() add_fixtures(db_session, john) res = client.post( "/settings/password/check", headers=auth_for(john), json={"password": john.original_password}, ) assert res.status_code == 200 assert res.json == {"result": True}
def test_incorrect_password(db_session, client): john = users.john() add_fixtures(db_session, john) res = client.post('/settings/password/check', headers=auth_for(john), json={ 'password': '******', }) assert res.status_code == 200 assert res.json == {'result': False}
def test_existing_club(db_session, client, test_user): lva = clubs.lva() sfn = clubs.sfn() test_user.club = sfn add_fixtures(db_session, lva) res = client.post('/clubs/{id}'.format(id=sfn.id), headers=auth_for(test_user), json={ 'name': 'LV Aachen', }) assert res.status_code == 422 assert res.json['error'] == 'duplicate-club-name'
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_delete_account(client, test_user): res = client.get('/users/{id}'.format(id=test_user.id)) assert res.status_code == 200 res = client.delete('/account', headers=auth_for(test_user), json={ 'password': test_user.original_password, }) assert res.status_code == 200 assert res.json == {} res = client.get('/users/{id}'.format(id=test_user.id)) assert res.status_code == 404
def test_generate(db_session, client): john = users.john() add_fixtures(db_session, john) old_key = john.tracking_key_hex res = client.post("/settings/tracking/key", headers=auth_for(john)) assert res.status_code == 200 new_key = res.json["key"] assert new_key != old_key assert User.get(john.id).tracking_key_hex == new_key
def test_update_without_permission(db_session, client, test_user): sfn = clubs.sfn() add_fixtures(db_session, sfn) res = client.post('/clubs/{id}'.format(id=sfn.id), headers=auth_for(test_user), json={ 'name': 'foobar', 'website': 'https://foobar.de', }) assert res.status_code == 403 club = Club.get(sfn.id) assert club.name == 'Sportflug Niederberg' assert club.website == None
def test_existing_club(db_session, client, test_user): lva = clubs.lva() sfn = clubs.sfn() test_user.club = sfn add_fixtures(db_session, lva) res = client.post( "/clubs/{id}".format(id=sfn.id), headers=auth_for(test_user), json={"name": "LV Aachen"}, ) assert res.status_code == 422 assert res.json["error"] == "duplicate-club-name"
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_missing_flight(db_session, client): john = users.john() add_fixtures(db_session, john) res = client.post( "/flights/{id}/comments".format(id=1000000), headers=auth_for(john), json={u"text": u"foobar"}, ) assert res.status_code == 404 assert res.json == { u"message": u"Sorry, there is no such record (1000000) in our database." }