Пример #1
0
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": {}},
    }
Пример #2
0
def test_repr_is_str(db_session):
    john = users.john(last_name=u'Müller')
    db_session.add(john)
    db_session.commit()

    assert isinstance(repr(john), str)
    assert repr(john) == '<User: [email protected], display=John Müller>'
Пример #3
0
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',
    }]
Пример #4
0
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!',
    }]
Пример #5
0
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
Пример #6
0
def test_search(db_session, client):
    edka = airports.merzbrueck()
    lva = clubs.lva()

    add_fixtures(
        db_session,
        users.john(),
        users.jane(),
        lva,
        clubs.sfn(),
        edka,
        airports.meiersberg(),
    )

    res = client.get("/search?text=aachen")
    assert res.status_code == 200
    assert res.json == {
        "results": [
            {
                "id": edka.id,
                "type": "airport",
                "name": "Aachen Merzbruck",
                "icao": "EDKA",
                "frequency": "122.875",
            },
            {
                "id": lva.id,
                "type": "club",
                "name": "LV Aachen",
                "website": "http://www.lv-aachen.de",
            },
        ]
    }
Пример #7
0
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
Пример #8
0
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)}
Пример #9
0
def test_paging(db_session, client):
    john = users.john()
    for _ in range(75):
        event = events.new_user(actor=john)
        db_session.add(event)

    db_session.commit()

    res = client.get("/timeline")
    assert res.status_code == 200
    assert len(res.json["events"]) == 50

    res = client.get("/timeline?page=2")
    assert res.status_code == 200
    assert len(res.json["events"]) == 25

    res = client.get("/timeline?page=3")
    assert res.status_code == 200
    assert len(res.json["events"]) == 0

    res = client.get("/timeline?per_page=40")
    assert res.status_code == 200
    assert len(res.json["events"]) == 40

    res = client.get("/timeline?per_page=40&page=2")
    assert res.status_code == 200
    assert len(res.json["events"]) == 35
Пример #10
0
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
Пример #11
0
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_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
Пример #13
0
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 == {}
Пример #14
0
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}
Пример #15
0
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.'}
Пример #16
0
def test_list_users(db_session, client):
    john = users.john()
    add_fixtures(db_session, john)

    res = client.get("/users/")
    assert res.status_code == 200
    assert res.json == {
        u"users": [{u"id": john.id, u"name": u"John Doe", u"club": None}]
    }
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}
Пример #18
0
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
Пример #19
0
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
Пример #20
0
def test_search_with_umlauts(db_session, client):
    john = users.john(last_name=u"Müller")

    add_fixtures(db_session, john)

    res = client.get(u"/search?text=M%C3%BCll")
    assert res.status_code == 200
    assert res.json == {
        "results": [{"id": john.id, "type": "user", "name": u"John Müller"}]
    }
Пример #21
0
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_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
Пример #23
0
def test_with_club_parameter(db_session, client):
    john = users.john(club=clubs.lva())
    add_fixtures(db_session, john, users.jane(), users.max())

    res = client.get("/users")
    assert res.status_code == 200
    assert len(res.json["users"]) == 3

    res = client.get("/users?club={club}".format(club=john.club.id))
    assert res.status_code == 200
    assert len(res.json["users"]) == 1
    assert res.json == {u"users": [{u"id": john.id, u"name": u"John Doe"}]}
Пример #24
0
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='foo')
    comment4 = flight_comments.yeah(flight=flight, text='bar')
    comment5 = flight_comments.yeah(flight=flight,
                                    user=users.jane(),
                                    text='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': {},
        },
    }
Пример #25
0
def test_missing_pilot_fields(db_session, client):
    john = users.john()
    db_session.add(john)
    db_session.commit()

    data = dict(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"validation-failed",
        u"fields": {u"_schema": [u"Either pilotName or pilotId must be set"]},
    }
Пример #26
0
def test_invalid_pilot_id(db_session, client):
    john = users.john()
    db_session.add(john)
    db_session.commit()

    data = dict(pilotId="abc", 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"validation-failed",
        u"fields": {u"pilotId": [u"Not a valid integer."]},
    }
Пример #27
0
def test_list_users(db_session, client):
    john = users.john()
    add_fixtures(db_session, john)

    res = client.get('/users/')
    assert res.status_code == 200
    assert res.json == {
        u'users': [{
            u'id': john.id,
            u'name': u'John Doe',
            u'club': None,
        }]
    }
Пример #28
0
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
Пример #29
0
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
Пример #30
0
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.'],
        },
    }
Пример #31
0
def test_list_users(db_session, client):
    john = users.john()
    add_fixtures(db_session, john)

    res = client.get("/users/")
    assert res.status_code == 200
    assert res.json == {
        u"users": [{
            u"id": john.id,
            u"name": u"John Doe",
            u"club": None
        }]
    }
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."]},
    }
Пример #33
0
def test_pilot_access_on_private_flight(db_session, client):
    jane = users.jane()
    flight = flights.one(
        pilot=jane,
        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_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."
    }
Пример #35
0
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,
    })
Пример #36
0
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."
    }
Пример #37
0
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.'
    }
Пример #38
0
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
Пример #39
0
def test_user_delete_deletes_user(db_session):
    john = users.john()
    db_session.add(john)
    db_session.commit()

    john_id = john.id
    assert john_id is not None

    assert db_session.query(User).get(john_id) is not None

    john.delete()
    db_session.commit()

    assert db_session.query(User).get(john_id) is None
Пример #40
0
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": {}
        },
    }
Пример #41
0
def test_search_with_umlauts(db_session, client):
    john = users.john(last_name=u'Müller')

    add_fixtures(db_session, john)

    res = client.get(u'/search?text=M%C3%BCll')
    assert res.status_code == 200
    assert res.json == {
        'results': [{
            'id': john.id,
            'type': 'user',
            'name': u'John Müller',
        }],
    }
Пример #42
0
def test_user_delete_deletes_user(db_session):
    john = users.john()
    db_session.add(john)
    db_session.commit()

    john_id = john.id
    assert john_id is not None

    assert db_session.query(User).get(john_id) is not None

    john.delete()
    db_session.commit()

    assert db_session.query(User).get(john_id) is None
Пример #43
0
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
Пример #44
0
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
Пример #45
0
def test_lva(db_session, client):
    lva = clubs.lva(owner=users.john())
    add_fixtures(db_session, lva)

    res = client.get("/clubs/{id}".format(id=lva.id))
    assert res.status_code == 200
    assert res.json == {
        "id": lva.id,
        "name": "LV Aachen",
        "timeCreated": "2015-12-24T12:34:56+00:00",
        "website": "http://www.lv-aachen.de",
        "isWritable": False,
        "owner": {"id": lva.owner.id, "name": lva.owner.name},
    }
Пример #46
0
def test_refresh_token_is_deleted_when_user_is_deleted(db_session):
    john = users.john()
    token = RefreshToken(refresh_token='secret123', user=john)
    db_session.add(token)
    db_session.commit()

    john_id = john.id

    assert db_session.query(User).filter_by(id=john_id).count() == 1
    assert db_session.query(RefreshToken).filter_by(user_id=john_id).count() == 1

    db_session.delete(john)

    assert db_session.query(User).filter_by(id=john_id).count() == 0
    assert db_session.query(RefreshToken).filter_by(user_id=john_id).count() == 0
Пример #47
0
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.'],
        },
    }
Пример #48
0
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."]
        },
    }
Пример #49
0
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
Пример #50
0
def test_writable(db_session, client):
    lva = clubs.lva()
    john = users.john(club=lva)
    add_fixtures(db_session, lva, john)

    res = client.get('/clubs/{id}'.format(id=lva.id), headers=auth_for(john))
    assert res.status_code == 200
    assert res.json == {
        'id': lva.id,
        'name': 'LV Aachen',
        'timeCreated': '2015-12-24T12:34:56+00:00',
        'website': 'http://www.lv-aachen.de',
        'isWritable': True,
        'owner': None,
    }
Пример #51
0
def test_writable(db_session, client):
    lva = clubs.lva()
    john = users.john(club=lva)
    add_fixtures(db_session, lva, john)

    res = client.get("/clubs/{id}".format(id=lva.id), headers=auth_for(john))
    assert res.status_code == 200
    assert res.json == {
        "id": lva.id,
        "name": "LV Aachen",
        "timeCreated": "2015-12-24T12:34:56+00:00",
        "website": "http://www.lv-aachen.de",
        "isWritable": True,
        "owner": None,
    }
Пример #52
0
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': {},
        }
    }
Пример #53
0
def test_with_club(db_session, client):
    john = users.john(club=clubs.lva())
    add_fixtures(db_session, john)

    res = client.get("/users")
    assert res.status_code == 200
    assert res.json == {
        u"users": [{
            u"id": john.id,
            u"name": u"John Doe",
            u"club": {
                u"id": john.club.id,
                u"name": u"LV Aachen"
            },
        }]
    }
Пример #54
0
def test_with_club(db_session, client):
    john = users.john(club=clubs.lva())
    add_fixtures(db_session, john)

    res = client.get('/users')
    assert res.status_code == 200
    assert res.json == {
        u'users': [{
            u'id': john.id,
            u'name': u'John Doe',
            u'club': {
                u'id': john.club.id,
                u'name': u'LV Aachen',
            },
        }]
    }
Пример #55
0
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)
Пример #56
0
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': {},
        },
    }
Пример #57
0
def test_read_user(db_session, client):
    john = users.john()
    add_fixtures(db_session, john)

    res = client.get("/users/{id}".format(id=john.id))
    assert res.status_code == 200
    assert res.json == {
        u"id": john.id,
        u"firstName": u"John",
        u"lastName": u"Doe",
        u"name": u"John Doe",
        u"club": None,
        u"trackingCallsign": None,
        u"trackingDelay": 0,
        u"followers": 0,
        u"following": 0,
    }