comparison tests/test_ttw.txt @ 62:7c154953acc4

test reading the pages
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 01 Mar 2012 16:20:44 -0800
parents 53ec5144f84f
children 83327bc715be
comparison
equal deleted inserted replaced
61:53ec5144f84f 62:7c154953acc4
3 3
4 Test ``simpypi`` through the web with a test server. 4 Test ``simpypi`` through the web with a test server.
5 5
6 The obligatory imports:: 6 The obligatory imports::
7 7
8 >>> import urllib2
8 >>> from simpypi.factory import factory 9 >>> from simpypi.factory import factory
9 10
10 Create a WSGI app:: 11 Create a WSGI app::
11 12
12 >>> app = factory(directory=directory) 13 >>> app = factory(directory=directory)
13 14
14 Now wrap it in a server:: 15 Now wrap it in a server::
15 16
16 >>> server = testserver(app, 'localhost', 64321) 17 >>> port = 64321
18 >>> server = testserver(app, 'localhost', port)
17 >>> server.start() 19 >>> server.start()
20 >>> url = 'http://localhost:%d/' % port
21
22 Get the home page::
23
24 >>> resource = urllib2.urlopen(url)
25 >>> contents = resource.read()
26 >>> 'Python Package Index' in contents
27 True
28
29 Get the index page::
30
31 >>> resource = urllib2.urlopen(url + 'index')
32 >>> contents = resource.read()
33 >>> 'Simple Index' in contents
34 True
18 35
19 Shut down the server:: 36 Shut down the server::
20 37
21 >>> server.stop() 38 >>> server.stop()