review/tests/test_web.py @ 9030dc9517cf

web: add basic tests

This patch adds a new test module `test_web` to automate testing of web
requests. For now the tests are rather simple and only check for
expected status codes.

To set up the flask app within the tests, it has to be configured
properly. This is the reason why the app configuration part in `web.py`
has been moved into an own function - now it may also be used by the
test module.
author Oben Sonne <obensonne@googlemail.com>
date Mon, 02 Jul 2012 22:32:48 +0200
parents (none)
children 8be7ac46f0ec
import unittest

from nose.tools import eq_

import util

from .. import web

NON_EXISTENT_REV = 999999

class WebTestCase(unittest.TestCase):
    """Simple web tests. Currently only checks for correct status codes."""

    def setUp(self):
        util.setup_reviewed_sandbox()()
        ui = util.get_ui()
        repo = util.get_sandbox_repo()
        web._configure_app(ui, repo)
        web.app.config['TESTING'] = True
        self.app = web.app.test_client()

    def tearDown(self):
        util.teardown_sandbox()

    def test_index_no_rev(self):
        rv = self.app.get('/')
        eq_(rv.status_code, 200)

    def test_index_unknown_rev(self):
        rv = self.app.get('/%s/' % NON_EXISTENT_REV)
        eq_(rv.status_code, 404)

    def test_index_known_rev(self):
        rv = self.app.get('/0/')
        eq_(rv.status_code, 404)

if __name__ == '__main__':
    unittest.main()