60
|
1 Test Through The Web
|
|
2 ====================
|
|
3
|
|
4 Test ``simpypi`` through the web with a test server.
|
|
5
|
|
6 The obligatory imports::
|
|
7
|
62
|
8 >>> import urllib2
|
60
|
9 >>> from simpypi.factory import factory
|
|
10
|
|
11 Create a WSGI app::
|
|
12
|
|
13 >>> app = factory(directory=directory)
|
61
|
14
|
|
15 Now wrap it in a server::
|
|
16
|
62
|
17 >>> port = 64321
|
|
18 >>> server = testserver(app, 'localhost', port)
|
61
|
19 >>> server.start()
|
62
|
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
|
61
|
35
|
|
36 Shut down the server::
|
|
37
|
|
38 >>> server.stop()
|