#
# Example of how to use the http session module
#
import sys
sys.path.insert(0, '../lib') # adjust library path
import httpsession
if __name__ == '__main__':
session = httpsession.HTTPSession(debug_level=1, use_cookies=1)
session.add_header('user-agent', 'foobar [compatible; linux 2.2.18pre21]')
print '-' * 78
print '-- Going to front page'
print '-' * 78
req = session.get('http://localhost:9000/')
req.getreply()
assert (req.redirects == 2), req.redirects
assert (req.path == '/Login'), req.path
print "ok"
print '-' * 78
print 'Logging in...'
print '-' * 78
next_url = req.resolve_href(req.path)
req = session.post(next_url)
req.add_param('event', 'login')
req.add_param('login', 'mylogin')
req.add_param('password', 'mypassword')
req.getreply()
assert req.replycode == 302
req = session.get(req.redirect())
req.getreply()
assert req.replycode == 200
assert req.path == '/Menu'
print "ok"
print '-' * 78
print 'Viewing SendSubmission'
print '-' * 78
req = session.get(req.resolve_href('SendSubmission'))
assert req.getreply()[0] == 200
assert req.redirects == 0
print "ok"
print '-' * 78
print 'Making a submission'
print '-' * 78
req = session.post_multipart(req.resolve_href('SubmitFile'))
req.add_param('item', '123')
req.add_file('file', '.bashrc', 'text/plain', open('/home/steve/.bashrc'))
req.getreply()
assert req.redirect()
req = session.get(req.redirect())
req.getreply()
assert req.replycode == 200
assert req.path == '/SendSubmission'
print "ok"
|