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',
    }]
Example #2
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!',
    }]
Example #3
0
def test_get_live_default_max_age(db_session, client):
    """The default max_age is 12 hours"""
    utcnow = datetime(year=2020, month=12, day=20, hour=20)

    john = users.john()
    fixes = []
    for age_hour in range(14, 0, -1):
        time = utcnow - timedelta(hours=age_hour)
        fixes.append(live_fix.create(john, time, 10, 20))

    add_fixtures(db_session, john, *fixes)

    with patch("skylines.model.tracking.datetime") as datetime_mock:
        datetime_mock.utcnow.return_value = utcnow

        res = client.get("/live/{id}/json".format(id=john.id))

        assert res.status_code == 200
        json = res.json

        assert json == {
            u"barogram_h": u"eE???????????",
            u"barogram_t": u"_gw@_`F_`F_`F_`F_`F_`F_`F_`F_`F_`F_`F",
            u"elevations": u"????????????",
            u"enl": u"",
            u"geoid": 26.504,
            u"points": u"_gayB_c`|@??????????????????????",
            u"sfid": john.id,
        }

        expected_fixes = list(
            filter(lambda f: f.time >= utcnow - timedelta(hours=12), fixes))
        assert decode_time(
            json[u"barogram_t"]) == get_fixes_times_seconds(expected_fixes)
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!',
    }]
Example #5
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)}
Example #6
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',
    }]
Example #7
0
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"
Example #8
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"
        },
    ]
Example #9
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": {}},
    }
Example #10
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",
            },
        ]
    }
Example #11
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)}
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
Example #14
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
Example #15
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
Example #16
0
def test_request_all_my_posts(db_session, client):
    user, pwd = users.sketch()
    add_fixture(db_session, user)
    post_instances = posts.create_posts(user, 10)
    add_fixtures(db_session, *post_instances)

    res = client.get('/api/v1/posts', user=user, password=pwd)
    assert res.status_code == 200
Example #17
0
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'
Example #18
0
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
Example #19
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 == {}
Example #20
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 == {}
Example #21
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": {}
        },
    }
Example #22
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}
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}
Example #25
0
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}
Example #26
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
Example #27
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
Example #28
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": {}
        },
    }
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.'}
Example #30
0
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'
Example #31
0
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"
Example #32
0
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"
Example #33
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'}
Example #34
0
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'
Example #35
0
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"
Example #36
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"}]
    }
Example #37
0
def test_name_filter(db_session, client):
    add_fixtures(db_session, clubs.sfn(), clubs.lva())

    res = client.get("/clubs?name=LV%20Aachen")
    assert res.status_code == 200
    assert res.json == S(
        {"clubs": ExactSequence([{
            "id": int,
            "name": "LV Aachen"
        }])})
Example #38
0
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}
Example #39
0
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'
Example #40
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}
Example #41
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 == {}
Example #42
0
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
Example #43
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"}]}
Example #44
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"}]}
Example #45
0
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'
Example #46
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 == {}
Example #47
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': {},
        },
    }
Example #48
0
def test_update_without_authentication(db_session, client):
    sfn = clubs.sfn()
    add_fixtures(db_session, sfn)

    res = client.post('/clubs/{id}'.format(id=sfn.id), json={
        'name': 'foobar',
        'website': 'https://foobar.de',
    })
    assert res.status_code == 401

    club = Club.get(sfn.id)
    assert club.name == 'Sportflug Niederberg'
    assert club.website == None
Example #49
0
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"
Example #50
0
def test_name_filter(db_session, client):
    sfn = clubs.sfn()
    lva = clubs.lva()
    add_fixtures(db_session, sfn, lva)

    res = client.get('/clubs?name=LV%20Aachen')
    assert res.status_code == 200
    assert res.json == {
        'clubs': [{
            'id': lva.id,
            'name': 'LV Aachen',
        }]
    }
Example #51
0
def test_name_filter(db_session, client):
    sfn = clubs.sfn()
    lva = clubs.lva()
    add_fixtures(db_session, sfn, lva)

    res = client.get('/clubs?name=LV%20Aachen')
    assert res.status_code == 200
    assert res.json == {
        'clubs': [{
            'id': lva.id,
            'name': 'LV Aachen',
        }]
    }
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."
    }