Mercurial > hg > simpypi
annotate tests/test_ttw.txt @ 66:a2ba66be2e31
tests mysteriously fail now
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 01 Mar 2012 19:36:02 -0800 |
parents | 83327bc715be |
children | cf03c3f2f98e |
rev | line source |
---|---|
60 | 1 Test Through The Web |
2 ==================== | |
3 | |
4 Test ``simpypi`` through the web with a test server. | |
5 | |
6 The obligatory imports:: | |
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 | 12 >>> import urllib2 |
60 | 13 >>> from simpypi.factory import factory |
14 | |
15 Create a WSGI app:: | |
16 | |
17 >>> app = factory(directory=directory) | |
61 | 18 |
19 Now wrap it in a server:: | |
20 | |
62 | 21 >>> port = 64321 |
22 >>> server = testserver(app, 'localhost', port) | |
61 | 23 >>> server.start() |
62 | 24 >>> url = 'http://localhost:%d/' % port |
25 | |
26 Get the home page:: | |
27 | |
28 >>> resource = urllib2.urlopen(url) | |
29 >>> contents = resource.read() | |
30 >>> 'Python Package Index' in contents | |
31 True | |
32 | |
33 Get the index page:: | |
34 | |
35 >>> resource = urllib2.urlopen(url + 'index') | |
36 >>> contents = resource.read() | |
37 >>> 'Simple Index' in contents | |
38 True | |
61 | 39 |
65
83327bc715be
make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
40 |
83327bc715be
make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
41 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
|
42 |
83327bc715be
make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
43 >>> os.listdir(directory) |
83327bc715be
make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
44 [] |
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 Upload a file:: |
83327bc715be
make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
47 |
83327bc715be
make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
48 >>> 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
|
49 >>> upload = MultiPartForm() |
83327bc715be
make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
50 >>> upload.add_file('package', path) |
83327bc715be
make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
51 >>> response = upload.post(url) |
83327bc715be
make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
52 |
83327bc715be
make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
53 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
|
54 |
83327bc715be
make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
55 >>> os.listdir(directory) |
83327bc715be
make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
56 ['HelloWorld'] |
83327bc715be
make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
57 >>> 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
|
58 ['HelloWorld-0.0.tar.gz'] |
83327bc715be
make the virtualenv convenience method return more stuff
Jeff Hammel <jhammel@mozilla.com>
parents:
62
diff
changeset
|
59 |
66
a2ba66be2e31
tests mysteriously fail now
Jeff Hammel <jhammel@mozilla.com>
parents:
65
diff
changeset
|
60 Make a virtualenv to install it in:: |
a2ba66be2e31
tests mysteriously fail now
Jeff Hammel <jhammel@mozilla.com>
parents:
65
diff
changeset
|
61 |
a2ba66be2e31
tests mysteriously fail now
Jeff Hammel <jhammel@mozilla.com>
parents:
65
diff
changeset
|
62 >>> tmpdir = tempfile.mkdtemp() |
a2ba66be2e31
tests mysteriously fail now
Jeff Hammel <jhammel@mozilla.com>
parents:
65
diff
changeset
|
63 >>> venv = create_virtualenv(tmpdir) |
a2ba66be2e31
tests mysteriously fail now
Jeff Hammel <jhammel@mozilla.com>
parents:
65
diff
changeset
|
64 >>> shutil.rmtree(tmpdir) |
a2ba66be2e31
tests mysteriously fail now
Jeff Hammel <jhammel@mozilla.com>
parents:
65
diff
changeset
|
65 |
61 | 66 Shut down the server:: |
67 | |
68 >>> server.stop() |