annotate tests/test_ttw.txt @ 75:809153401986

update documentation
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 02 Mar 2012 14:57:06 -0800
parents 10f343c483ee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
60
46f5fd27ee54 stub testing TTW
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 Test Through The Web
46f5fd27ee54 stub testing TTW
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 ====================
46f5fd27ee54 stub testing TTW
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3
46f5fd27ee54 stub testing TTW
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 Test ``simpypi`` through the web with a test server.
46f5fd27ee54 stub testing TTW
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5
46f5fd27ee54 stub testing TTW
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 The obligatory imports::
46f5fd27ee54 stub testing TTW
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7
65
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
8 >>> import os
66
a2ba66be2e31 tests mysteriously fail now
Jeff Hammel <jhammel@mozilla.com>
parents: 65
diff changeset
9 >>> import shutil
a2ba66be2e31 tests mysteriously fail now
Jeff Hammel <jhammel@mozilla.com>
parents: 65
diff changeset
10 >>> import subprocess
a2ba66be2e31 tests mysteriously fail now
Jeff Hammel <jhammel@mozilla.com>
parents: 65
diff changeset
11 >>> import tempfile
62
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
12 >>> import urllib2
60
46f5fd27ee54 stub testing TTW
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 >>> from simpypi.factory import factory
46f5fd27ee54 stub testing TTW
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14
46f5fd27ee54 stub testing TTW
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 Create a WSGI app::
46f5fd27ee54 stub testing TTW
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16
46f5fd27ee54 stub testing TTW
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 >>> app = factory(directory=directory)
61
53ec5144f84f start serving PyPI
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
18
53ec5144f84f start serving PyPI
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
19 Now wrap it in a server::
53ec5144f84f start serving PyPI
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
20
62
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
21 >>> port = 64321
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
22 >>> server = testserver(app, 'localhost', port)
61
53ec5144f84f start serving PyPI
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
23 >>> server.start()
62
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
24 >>> url = 'http://localhost:%d/' % port
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
25
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
26 Get the home page::
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
27
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
28 >>> resource = urllib2.urlopen(url)
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
29 >>> contents = resource.read()
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
30 >>> 'Python Package Index' in contents
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
31 True
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
32
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
33 Get the index page::
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
34
69
10f343c483ee install and import the thing
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
35 >>> index = url + 'index/'
10f343c483ee install and import the thing
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
36 >>> resource = urllib2.urlopen(index)
62
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
37 >>> contents = resource.read()
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
38 >>> 'Simple Index' in contents
7c154953acc4 test reading the pages
Jeff Hammel <jhammel@mozilla.com>
parents: 61
diff changeset
39 True
61
53ec5144f84f start serving PyPI
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
40
65
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
41
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
42 There should be no files to start out with::
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
43
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
44 >>> os.listdir(directory)
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
45 []
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
46
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
47 Upload a file::
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
48
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
49 >>> path = os.path.join(here, 'HelloWorld-0.0.tar.gz')
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
50 >>> upload = MultiPartForm()
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
51 >>> upload.add_file('package', path)
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
52 >>> response = upload.post(url)
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
53
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
54 Let's see if its in the right place::
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
55
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
56 >>> os.listdir(directory)
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
57 ['HelloWorld']
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
58 >>> os.listdir(os.path.join(directory, 'HelloWorld'))
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
59 ['HelloWorld-0.0.tar.gz']
83327bc715be make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents: 62
diff changeset
60
66
a2ba66be2e31 tests mysteriously fail now
Jeff Hammel <jhammel@mozilla.com>
parents: 65
diff changeset
61 Make a virtualenv to install it in::
a2ba66be2e31 tests mysteriously fail now
Jeff Hammel <jhammel@mozilla.com>
parents: 65
diff changeset
62
a2ba66be2e31 tests mysteriously fail now
Jeff Hammel <jhammel@mozilla.com>
parents: 65
diff changeset
63 >>> tmpdir = tempfile.mkdtemp()
a2ba66be2e31 tests mysteriously fail now
Jeff Hammel <jhammel@mozilla.com>
parents: 65
diff changeset
64 >>> venv = create_virtualenv(tmpdir)
68
e62d2fddb275 use the actual paths i mean
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
65 >>> code = subprocess.call([venv.python, '-c', 'import helloworld'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
67
cf03c3f2f98e this one fails too; something is rotten in the state of virtualenv
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
66 >>> code
cf03c3f2f98e this one fails too; something is rotten in the state of virtualenv
Jeff Hammel <jhammel@mozilla.com>
parents: 66
diff changeset
67 1
69
10f343c483ee install and import the thing
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
68
10f343c483ee install and import the thing
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
69 Install the package and make sure you can import it::
10f343c483ee install and import the thing
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
70
10f343c483ee install and import the thing
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
71 >>> subprocess.call([venv.easy_install, '-i', index, 'HelloWorld'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
10f343c483ee install and import the thing
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
72 0
10f343c483ee install and import the thing
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
73 >>> code = subprocess.call([venv.python, '-c', 'import helloworld'])
10f343c483ee install and import the thing
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
74 >>> code
10f343c483ee install and import the thing
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
75 0
10f343c483ee install and import the thing
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
76 >>> process = subprocess.Popen([venv.python, '-c', 'import helloworld; print helloworld.hello'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
10f343c483ee install and import the thing
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
77 >>> stdout, stderr = process.communicate()
10f343c483ee install and import the thing
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
78 >>> stdout
10f343c483ee install and import the thing
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
79 'Hello, world!\n'
10f343c483ee install and import the thing
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
80 >>> process.returncode
10f343c483ee install and import the thing
Jeff Hammel <jhammel@mozilla.com>
parents: 68
diff changeset
81 0
66
a2ba66be2e31 tests mysteriously fail now
Jeff Hammel <jhammel@mozilla.com>
parents: 65
diff changeset
82 >>> shutil.rmtree(tmpdir)
a2ba66be2e31 tests mysteriously fail now
Jeff Hammel <jhammel@mozilla.com>
parents: 65
diff changeset
83
61
53ec5144f84f start serving PyPI
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
84 Shut down the server::
53ec5144f84f start serving PyPI
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
85
53ec5144f84f start serving PyPI
Jeff Hammel <jhammel@mozilla.com>
parents: 60
diff changeset
86 >>> server.stop()