Join Club ShowMeDo to Learn Python!

This series is a part of Club ShowMeDo. Click to learn why you should join our club with a simple monthly subscription.

  • We teach Python and all the cool modules
  • Topics include beginner Python, GUIs, Web and Desktop Apps
  • Long, specially crafted video tutorials just for you
  • Club video tutorials extend our normal Free content
  • Save your time - we've done the research for you
  • Keep your skills up-to-date
  • Learn at your own pace, everything you need is shown to you
  • Over 12 hours of archived material are waiting for you in the club

Name: [002] Ian Ozsvald
Member: 128 months
Authored: 181 videos
Description: I am the co-founder of ShowMeDo (see, author of `The Screencasting Handbook <>`_ and the founder of the professional screencast production company `ProCasts <>`_: .. image:: ...

Test Logins using Form Manipulation [ID:602] (5/5)

in series: Robust and Reliable Web Sites with twill and nosetests

(Showmedo is undergoing major changes. To report any problems viewing the videos please email us and include browser and OS specifics. Cheers - Kyran.)

Finally we look at manipulating the form so that our session can login. We use this to both confirm that our login process works and to check that the logged-in user's page contains the html that we expect.

We use the 'fv' command to fill in form values using a dummy ShowMeDo user account and then 'submit' to act as though we pressed the login button.

You can extend this technique to use 'formfile' (see twill language reference) to upload a file using a form field - useful to test e.g. picture uploads.

from twill.commands import *

# usage examples:
# nosetests - try all tests that nosetests can find
# nosetests - call all tests in the file
# nosetests
# nosetests

# twill API reference

def test_homepage_OK():
    "test we can get to the homepage"
    # 200
    http_code = b.result.get_http_code()    
    print "http_code", http_code
    assert http_code == 200
def test_404():
    "test that a bad url generates a 404 error"
    # 404 OK
    http_code = b.result.get_http_code()    
    print http_code
    assert http_code == 404

class Tests(object):
    def setUp(self):
        print "setUp"
        self.b = get_browser()
    def tearDown(self):
        print "tearDown"
    def test_title(self):
        "test that our title contains the right text"
        http_code = self.b.result.get_http_code()    
        assert http_code == 200
        title = self.b.get_title()
        print title
        assert "Learning Python" in title

    def test_link(self):
        "test we can find an expected link and that we follow it to the right destination"
        # find the first link to
        link = self.b.find_link('/videos/python')
        print link
        #Link(base_url='', url='/videos/python', 
        #text='Python', ta [('href', '/videos/python')])
        # follow the link
        current_url = self.b.get_url()
        print current_url
        assert current_url == ""
    def test_login(self):
        "test that we can login"
        # first - make sure we logout
        #>>> b.showforms()        
        #Form #1
        ### ## __Name__________________ __Type___ __ID________ __Value________________
        #1     user_name                text      user_name
        #2     password                 password  password
        #3  1  login                    submit    (None)       Login
        #Form #2
        ### ## __Name__________________ __Type___ __ID________ __Value________________
        #1     cx                       hidden    (None)       002884903177541871589:c
        #2     cof                      hidden    (None)       FORID:9
        #3     q                        text      (None)
        #4  1  sa                       submit    (None)       Search        
        user_name = ''
        password = 'lkBs8y0'        
        fv("1", "user_name", user_name)
        fv("1", "password", password)
        print self.b.get_url()
        html = self.b.get_html()
        print html
        assert """logged in as
      <b>twilltest</b>""" in html

Got any questions?

Get answers in the ShowMeDo Learners Google Group.

Video statistics:

  • Video's rank shown in the most popular listing
  • Video plays: 0 (since July 30th)
  • Plays in last week: 0
  • Published: 101 months ago

Thank-yous, questions and comments

If this video tutorial was helpful please take some time to say thank-you to the authors for their hard work. Feel free to ask questions. Let the author know why their video tutorial was useful - what are you learning about? Did the video tutorial save you time? Would you like to see more?

You may also want to see our ShowMeDo Google Group to speak to our active users and authors.

Your email address will not be published.

Show some quick comments >>

All comments excluding tick-boxed quick-comments

10. anonymous Tue, 19 May 2009 13:07

Da nu Nah+

9. anonymous Mon, 04 May 2009 14:35

hochu vodki!t

8. anonymous Sat, 02 May 2009 00:37

hochu vodki!w

I am unable to download the video

6. anonymous Mon, 23 Feb 2009 23:19

Review of Test Logins using Form Manipulation

keep up the good work!

5. anonymous Wed, 18 Feb 2009 04:06

Review of Test Logins using Form Manipulation

Very good web site, great work and thank you for your service.

4. anonymous Thu, 22 Jan 2009 20:42

Review of Test Logins using Form Manipulation



3. anonymous Wed, 15 Oct 2008 17:13

Review of Test Logins using Form Manipulation

Very good web site, great work and thank you for your service.i

2. anonymous Wed, 28 May 2008 11:24

Review of Test Logins using Form Manipulation

I enjoy your site very much! THANK YOU

Video published, thanks for contributing to ShowMeDo

Showmedo is a peer-produced video-tutorials and screencasts site for free and open-source software (FOSS)- with the exception of some club videos, the large majority are free to watch and download.

how to help » about » faq »

Educating the Open-source Community With Showmedo

Although as important as the software it supports, education and documentation are relatively neglected in the Open-source world. Coders love to code, and explaining how best to use or improve the software tends to be deferred or even sidelined.

At Showmedo we believe the community can play a vital role here and also say thanks for the tools and software that make our lives easier. If you have a piece of software you love or a programming langugage you are enthusiastic about, why not make a screencast showing others how to use it? All the stuff you wish you'd been told, the tips, tricks, insights that would have saved you time and frustration.

Screencasting is easier than you think, and we're happy to help you. You can emailus for advice or just use some of the how-to screencasts on the site. This screencasting learning-pathis a good place to start.

Kudos and Thanks for Ian

3 Minute Oveview (What Does Python Look Like?)

simple and informative. you draw me in
70 months ago


Showmedo's development is fairly rapid and bugs will inevitably creep in. If you have any problems please drop us a line using the contact address below. Likewise, any suggestions for improvements to the site are gratefully received.