Skip to content

Instantly share code, notes, and snippets.

@reorx
Last active June 5, 2016 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reorx/dc6998569c6ec85d300804852ad796a7 to your computer and use it in GitHub Desktop.
Save reorx/dc6998569c6ec85d300804852ad796a7 to your computer and use it in GitHub Desktop.
# coding: utf-8
import requests
from deptest import depend_on
sessionid = '12345'
login_form = {
'username': 'foo',
'password': 'bar'
}
def test_login():
# session will keep cookie in request context
s = requests.Session()
resp = s.post('http://example.com/login', data=login_form)
print resp.status_code, resp.content, resp.headers
assert resp.status_code == 200
assert 'Set-Cookie' in resp.headers
assert 'sessionid=' in resp.headers['Set-Cookie']
return s
@depend_on('test_login', with_return=True)
def test_get_menu(s):
resp = s.get('http://example.com/menu')
data = resp.json()
print resp.status_code, resp.content, resp.headers
assert resp.status_code == 200
assert len(data) >= 1
# get the first item of menu, return a tuple
return s, data[0] # equal to (s, data[0])
@depend_on('test_get_menu', with_return=True)
def test_post_order(args):
# args is a tuple
s, item = args
resp = s.post('http://example.com/menu/order', data={
'item_id': item['id']
})
data = resp.json()
print resp.status_code, resp.content, resp.headers
assert resp.status_code == 200
assert item['name'] == data['name']
# execute sequence: test_login, test_get_menu, test_post_order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment