本文整理汇总了Python中tests.api.auth_for函数的典型用法代码示例。如果您正苦于以下问题:Python auth_for函数的具体用法?Python auth_for怎么用?Python auth_for使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了auth_for函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete_user_invalidates_auth_tokens
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
示例2: test_delete_account_invalidates_auth_tokens
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
示例3: test_existing_club
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"
示例4: test_missing
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
示例5: test_delete_user_as_other_user
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: test_clear_all
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
示例7: test_create
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',
}]
示例8: test_create
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
示例9: test_non_json_data
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'
示例10: test_invalid_data
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'}
示例11: test_invalid_json
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
示例12: test_basic_flight_json
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"[email protected]@U}@[email protected]@[email protected][KIKKKI[][email protected]@[email protected]",
u"barogram_t": u"ik_A{B{@[email protected]]S]]IIIIMIIISIIISIIIIIIIIIIII",
u"contests": Unordered(
[
{
u"name": u"olc_plus triangle",
u"times": u"{y_AgBeAyAS",
u"turnpoints": u"[email protected]{[email protected]}[email protected]@|[email protected]{AnEgJ",
},
{
u"name": u"olc_plus classic",
u"times": u"[email protected]][email protected]@",
u"turnpoints": u"ypokI{[email protected]]g^[email protected][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`[email protected]`@[email protected]@fQ`[email protected]@`CsAlAsG",
u"sfid": int,
}
)
示例13: test_missing_flight
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.'}
示例14: test_correct_password
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: test_igc_owner_access_on_private_flight
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