session_example.py :  » Web-Unit » WebUnit » webunit-0.4 » examples » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Unit » WebUnit 
WebUnit » webunit 0.4 » examples » session_example.py
#
# 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"
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.