Mercurial > hg > simpypi
annotate tests/test_wsgi.txt @ 60:46f5fd27ee54
stub testing TTW
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 01 Mar 2012 15:45:39 -0800 |
parents | 26139fb1de98 |
children | 83327bc715be |
rev | line source |
---|---|
7 | 1 Test simpypi |
2 ============ | |
6 | 3 |
57
6bfe6c59b64a
add documentation and correct capitalization
Jeff Hammel <jhammel@mozilla.com>
parents:
55
diff
changeset
|
4 Test the WSGI app with mock requests from ``paste.fixture.TestApp``. |
6bfe6c59b64a
add documentation and correct capitalization
Jeff Hammel <jhammel@mozilla.com>
parents:
55
diff
changeset
|
5 |
6 | 6 The obligatory imports:: |
7 | |
33
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
8 >>> import os |
51
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
9 >>> import pkginfo |
44 | 10 >>> import shutil |
6 | 11 >>> import simpypi |
55
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
12 >>> import subprocess |
52 | 13 >>> import tarfile |
50
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
14 >>> import tempfile |
33
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
15 >>> from paste.fixture import TestApp |
6 | 16 |
33
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
17 The directory is initially empty:: |
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
18 |
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
19 >>> os.listdir(directory) |
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
20 [] |
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
21 |
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
22 Make a test application:: |
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
23 |
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
24 >>> app = simpypi.SimPyPI(directory) |
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
25 >>> testapp = TestApp(app) |
36
a02d08627d9c
stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
26 |
a02d08627d9c
stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
27 Upload a package:: |
a02d08627d9c
stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
28 |
a02d08627d9c
stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
29 >>> field = 'package' |
a02d08627d9c
stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
30 >>> filename = 'HelloWorld-0.0.tar.gz' |
a02d08627d9c
stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
31 >>> contents = file(os.path.join(here, filename)).read() |
37
1bdece293671
* fix calling signature in test
Jeff Hammel <jhammel@mozilla.com>
parents:
36
diff
changeset
|
32 >>> response = testapp.post('/', upload_files=[(field, filename, contents)]) |
43
089d5650d7e2
check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
33 |
089d5650d7e2
check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
34 Ensure that package is in the right place:: |
089d5650d7e2
check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
35 |
089d5650d7e2
check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
36 >>> os.listdir(directory) |
089d5650d7e2
check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
37 ['HelloWorld'] |
089d5650d7e2
check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
38 >>> os.listdir(os.path.join(directory, 'HelloWorld')) |
089d5650d7e2
check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
39 ['HelloWorld-0.0.tar.gz'] |
47 | 40 |
50
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
41 Ensure the package is what you expect it to be:: |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
42 |
51
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
43 >>> path = os.path.join(directory, 'HelloWorld', 'HelloWorld-0.0.tar.gz') |
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
44 >>> sdist = pkginfo.sdist.SDist(path) |
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
45 >>> sdist.name |
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
46 'HelloWorld' |
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
47 >>> sdist.version |
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
48 '0.0' |
52 | 49 >>> sdist.home_page |
50 'http://helloworld.example.com/' | |
51 >>> sdist.author | |
52 'Jeff Hammel' | |
51
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
53 |
55
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
54 Unpack the archive and ensure the files are there:: |
51
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
55 |
50
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
56 >>> tmpdir = tempfile.mkdtemp() |
52 | 57 >>> archive = tarfile.TarFile.open(path) |
53
a40f050812cb
start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents:
52
diff
changeset
|
58 >>> for member in archive.getmembers(): |
a40f050812cb
start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents:
52
diff
changeset
|
59 ... archive.extract(member, path=tmpdir) |
a40f050812cb
start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents:
52
diff
changeset
|
60 >>> os.listdir(tmpdir) |
a40f050812cb
start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents:
52
diff
changeset
|
61 ['HelloWorld-0.0'] |
a40f050812cb
start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents:
52
diff
changeset
|
62 >>> srcdir = os.path.join(tmpdir, 'HelloWorld-0.0') |
a40f050812cb
start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents:
52
diff
changeset
|
63 >>> os.path.exists(os.path.join(srcdir, 'setup.py')) |
a40f050812cb
start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents:
52
diff
changeset
|
64 True |
54
73e6956c670a
ensure all the files are in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
53
diff
changeset
|
65 >>> 'helloworld' in os.listdir(srcdir) |
73e6956c670a
ensure all the files are in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
53
diff
changeset
|
66 True |
73e6956c670a
ensure all the files are in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
53
diff
changeset
|
67 >>> os.listdir(os.path.join(srcdir, 'helloworld')) |
73e6956c670a
ensure all the files are in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
53
diff
changeset
|
68 ['__init__.py'] |
55
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
69 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
70 Install the package and inspect the installation:: |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
71 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
72 >>> python = create_virtualenv(tmpdir) |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
73 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
74 You should not be able to import ``helloworld`` yet:: |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
75 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
76 >>> code = subprocess.call([python, '-c', 'import helloworld'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
77 >>> code |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
78 1 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
79 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
80 But after installation you should:: |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
81 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
82 >>> subprocess.call([python, 'setup.py', 'install'], cwd=srcdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
83 0 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
84 >>> code = subprocess.call([python, '-c', 'import helloworld'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
85 >>> code |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
86 0 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
87 >>> process = subprocess.Popen([python, '-c', 'import helloworld; print helloworld.hello'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
88 >>> stdout, stderr = process.communicate() |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
89 >>> process.returncode |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
90 0 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
91 >>> stdout |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
92 'Hello, world!\n' |
50
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
93 >>> shutil.rmtree(tmpdir) |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
94 |
47 | 95 Upload the same package but with the wrong name:: |
96 | |
97 >>> shutil.rmtree(os.path.join(directory, 'HelloWorld')) | |
98 >>> os.listdir(directory) | |
99 [] | |
49
ca456e08924f
add a test for misnamed files
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
100 >>> response = testapp.post('/', upload_files=[(field, 'MisleadingName.tar.gz', contents)]) |
ca456e08924f
add a test for misnamed files
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
101 >>> os.listdir(directory) |
ca456e08924f
add a test for misnamed files
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
102 ['HelloWorld'] |
ca456e08924f
add a test for misnamed files
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
103 >>> os.listdir(os.path.join(directory, 'HelloWorld')) |
ca456e08924f
add a test for misnamed files
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
104 ['HelloWorld-0.0.tar.gz'] |
50
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
105 >>> shutil.rmtree(os.path.join(directory, 'HelloWorld')) |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
106 >>> os.listdir(directory) |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
107 [] |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
108 >>> filename = 'MisleadingFilename.tar.gz' |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
109 >>> contents = file(os.path.join(here, filename)).read() |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
110 >>> response = testapp.post('/', upload_files=[(field, filename, contents)]) |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
111 >>> os.listdir(directory) |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
112 ['HelloWorld'] |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
113 >>> os.listdir(os.path.join(directory, 'HelloWorld')) |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
114 ['HelloWorld-0.0.tar.gz'] |