testing a website from python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • M.N.A.Smadi

    #1

    testing a website from python

    hi;

    I just want to test that a given website is up or not from a python
    script. I thought of using wget as an os command. Any better ideas?

    thanks
    moe smadi
  • matt

    #2
    Re: testing a website from python

    Here's something I did recently at work. (Thought it's testing http
    digest authentication, the idea would the same (testNoAuth() is
    probably doing what you want)). It contains unittest code and is using
    urllib2.


    matt

    Comment

    • Benji York

      #3
      Re: testing a website from python

      matt wrote:[color=blue]
      > Here's something I did recently at work.
      > It contains unittest code and is using
      > urllib2.
      > http://blog.spikesource.com/pyhton_testcases.htm[/color]

      If you want to test web sites, you might be interested in
      zope.testbrowse r (currently Zope 3 only, but fixing that is on my to do
      list).

      You can see an example testbrowser test (which is also both its README
      and its unit tests) at


      If there is any interest I'll try to package up a stand-alone version in
      the next few days.
      --
      Benji York

      Comment

      • Achim Domma (SyynX Solutions GmbH)

        #4
        Re: testing a website from python

        Benji York wrote:
        [color=blue]
        > If there is any interest I'll try to package up a stand-alone version in
        > the next few days.[/color]

        I think that would be a very usefull tool. Currently I'm using httpunit
        with Jython but a python only tool would be much nicer.

        regards,
        Achim

        Comment

        • Grig Gheorghiu

          #5
          Re: testing a website from python

          Achim,

          Have you looked into twill? It's available at
          <http://www.python.org/pypi/twill/0.7.2>

          Grig

          Comment

          • Josef Meile

            #6
            Re: testing a website from python

            Hi,
            [color=blue]
            > I just want to test that a given website is up or not from a python
            > script. I thought of using wget as an os command. Any better ideas?[/color]
            Here is how I did it:

            import urllib2
            import socket
            def checkUrl(url, timeout=1):
            """Checks an url for a python version greater
            than 2.3.3.

            Note: For me isn't important the kind of
            HTTP Error. If you want to know it,
            then take a look at the existent
            solutions like CMFLinkChecker and
            see how they extract the code from
            the error message.
            """
            error={'code':1 , 'msg':'Success' }
            defTimeOut=sock et.getdefaultti meout()
            socket.setdefau lttimeout(timeo ut)
            try:
            urllib2.urlopen (url)
            except (urllib2.HTTPEr ror, urllib2.URLErro r,
            socket.error, socket.sslerror ):
            error['code']=-2
            error['msg']="The link: \"${link}\" couldn't be validated"
            except:
            socket.setdefau lttimeout(defTi meOut)
            raise

            socket.setdefau lttimeout(defTi meOut)
            return error

            Comment

            • Benji York

              #7
              Re: testing a website from python

              Achim Domma (SyynX Solutions GmbH) wrote:[color=blue]
              > Benji York wrote:[color=green]
              >>If there is any interest I'll try to package up a stand-alone version in
              >>the next few days.[/color]
              >
              > I think that would be a very usefull tool. Currently I'm using httpunit
              > with Jython but a python only tool would be much nicer.[/color]

              I put a first cut at http://benjiyork.com/zope.testbrowser-0.1.tgz).
              See the README.txt for general info and over_the_wire.t xt for how to use
              it to access web sites. It requires the zope.interface package from
              http://www.zope.org/Products/ZopeInterface (version 3.0.1 should work).
              --
              Benji York

              Comment

              Working...