Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
pyramid.pdf
Скачиваний:
10
Добавлен:
24.03.2015
Размер:
3.82 Mб
Скачать

37.8. ADDING TESTS

219 self.assertTrue(b’Login’ in res.body)

220

221def test_anonymous_user_cannot_add(self):

222res = self.testapp.get(’/add_page/NewPage’, status=200)

223self.assertTrue(b’Login’ in res.body)

224

225def test_viewer_user_cannot_edit(self):

226self.testapp.get(self.viewer_login, status=302)

227res = self.testapp.get(’/FrontPage/edit_page’, status=200)

228self.assertTrue(b’Login’ in res.body)

229

230def test_viewer_user_cannot_add(self):

231self.testapp.get(self.viewer_login, status=302)

232res = self.testapp.get(’/add_page/NewPage’, status=200)

233self.assertTrue(b’Login’ in res.body)

234

235def test_editors_member_user_can_edit(self):

236self.testapp.get(self.editor_login, status=302)

237res = self.testapp.get(’/FrontPage/edit_page’, status=200)

238self.assertTrue(b’Editing’ in res.body)

239

240def test_editors_member_user_can_add(self):

241self.testapp.get(self.editor_login, status=302)

242res = self.testapp.get(’/add_page/NewPage’, status=200)

243self.assertTrue(b’Editing’ in res.body)

244

245def test_editors_member_user_can_view(self):

246self.testapp.get(self.editor_login, status=302)

247res = self.testapp.get(’/FrontPage’, status=200)

248self.assertTrue(b’FrontPage’ in res.body)

37.8.5Running the Tests

We can run these tests by using setup.py test in the same way we did in Run the Tests. However, first we must edit our setup.py to include a dependency on WebTest, which we’ve used in our tests.py. Change the requires list in setup.py to include WebTest.

1

2

3

4

5

6

requires = [ ’pyramid’, ’SQLAlchemy’, ’transaction’, ’pyramid_tm’,

’pyramid_debugtoolbar’,

493

37. SQLALCHEMY + URL DISPATCH WIKI TUTORIAL

7

8

9

10

11

’zope.sqlalchemy’, ’waitress’, ’docutils’, ’WebTest’, # add this

]

After we’ve added a dependency on WebTest in setup.py, we need to rerun setup.py develop to get WebTest installed into our virtualenv. Assuming our shell’s current working directory is the “tutorial” distribution directory:

On UNIX:

$ ../bin/python setup.py develop

On Windows:

c:\pyramidtut\tutorial> ..\Scripts\python setup.py develop

Once that command has completed successfully, we can run the tests themselves:

On UNIX:

$ ../bin/python setup.py test -q

On Windows:

c:\pyramidtut\tutorial> ..\Scripts\python setup.py test -q

The expected result ends something like:

......................

----------------------------------------------------------------------

Ran 21 tests in 2.700s

OK

494

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]