473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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
Sep 20 '05 #1
6 1367
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.
http://blog.spikesource.com/pyhton_testcases.htm

matt

Sep 21 '05 #2
matt wrote:
Here's something I did recently at work.
It contains unittest code and is using
urllib2.
http://blog.spikesource.com/pyhton_testcases.htm


If you want to test web sites, you might be interested in
zope.testbrowser (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
http://svn.zope.org/*checkout*/Zope3....txt?rev=38050

If there is any interest I'll try to package up a stand-alone version in
the next few days.
--
Benji York
Sep 21 '05 #3
Benji York wrote:
If there is any interest I'll try to package up a stand-alone version in
the next few days.


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
Sep 21 '05 #4
Achim,

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

Grig

Sep 21 '05 #5
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?

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=socket.getdefaulttimeout()
socket.setdefaulttimeout(timeout)
try:
urllib2.urlopen(url)
except (urllib2.HTTPError, urllib2.URLError,
socket.error, socket.sslerror):
error['code']=-2
error['msg']="The link: \"${link}\" couldn't be validated"
except:
socket.setdefaulttimeout(defTimeOut)
raise

socket.setdefaulttimeout(defTimeOut)
return error

Sep 21 '05 #6
Achim Domma (SyynX Solutions GmbH) wrote:
Benji York wrote:
If there is any interest I'll try to package up a stand-alone version in
the next few days.


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.


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.txt 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

Sep 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Robb Shecter | last post by:
Anybody know about a Python library for testing websites? I'm thinking of something like a scriptable browser, where you could tell it to browse to a certain URL, check for the existence of...
11
by: rhat | last post by:
Hi Everyone, I've recently been reading some articles about unit-testing in Python , but I am a bit confused: where do I go to get started with this? I tried googling for "unittest" but all I've...
0
by: yonatan | last post by:
hello all. I've been working on a website (windows/PHP/APACHE/MYSQL), doing both the coding and testing/QA. for unit tests, I use jsUnit (javascript), and simpleTest (PHP). when I needed...
0
by: Matthew Fitzgibbons | last post by:
I'm by no means a testing expert, but I'll take a crack at it. Casey McGinty wrote: I've never run into this. Rule of thumb: always separate software from hardware. Write mock classes or...
3
by: Alexnb | last post by:
Okay, I already made this post, but it kinda got lost. So anyway I need to figure out how to test if the user is able to connect to a specific website. Last time I got pointed to the urllib2 page,...
0
by: Alexnb | last post by:
Timothy Grant wrote: well I can tel you it didn't work for me. In fact I didn't see the code you posted on there, I ended up figuring it out on my own with a little help from the missing manual...
2
by: Edwin.Madari | last post by:
use re module import re template = '^My name is alex' astring = 'My name is alex, and I like pie' if re.match(template, astring): print 'Found it' else: print '%s does not begin with %s' %...
21
by: =?ISO-8859-1?Q?Fad=A5?= | last post by:
Hello guys, I want to do kinda of an A/B split testing on a website I run. I just created a new version but I need to keep both version running and see which one will perform better. First, I'm...
10
by: Brendan Miller | last post by:
What would heavy python unit testers say is the best framework? I've seen a few mentions that maybe the built in unittest framework isn't that great. I've heard a couple of good things about...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.