Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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"}]}
Exemplo n.º 4
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"}]}
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
0
def test_list_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.get("/notifications", headers=auth_for(john))
    assert res.status_code == 200
    assert res.json == S({
        u"events":
        ExactSequence([
            {
                u"actor": {
                    u"id": int,
                    u"name": u"Max Mustermann"
                },
                u"id": int,
                u"time": Datetime("%Y-%m-%dT%H:%M:%S.%f+00:00"),
                u"type": u"follower",
                u"unread": True,
                u"user": {
                    u"id": int,
                    u"name": u"John Doe"
                },
            },
            {
                u"actor": {
                    u"id": int,
                    u"name": u"Jane Doe"
                },
                u"id": int,
                u"time": Datetime("%Y-%m-%dT%H:%M:%S.%f+00:00"),
                u"type": u"follower",
                u"unread": True,
                u"user": {
                    u"id": int,
                    u"name": u"John Doe"
                },
            },
        ])
    })
Exemplo n.º 8
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',
        }]
    }
Exemplo n.º 9
0
def test_list_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.get("/notifications", headers=auth_for(john))
    assert res.status_code == 200
    assert res.json == S(
        {
            u"events": ExactSequence(
                [
                    {
                        u"actor": {u"id": int, u"name": u"Max Mustermann"},
                        u"id": int,
                        u"time": Datetime("%Y-%m-%dT%H:%M:%S.%f+00:00"),
                        u"type": u"follower",
                        u"unread": True,
                        u"user": {u"id": int, u"name": u"John Doe"},
                    },
                    {
                        u"actor": {u"id": int, u"name": u"Jane Doe"},
                        u"id": int,
                        u"time": Datetime("%Y-%m-%dT%H:%M:%S.%f+00:00"),
                        u"type": u"follower",
                        u"unread": True,
                        u"user": {u"id": int, u"name": u"John Doe"},
                    },
                ]
            )
        }
    )