comparison tests/test_wsgi.txt @ 59:26139fb1de98

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