wheezy.web / demos / quickstart-empty / src / public / web / tests / test_views.py

""" ``test_views`` module.
"""

import unittest

try:
    import json
except ImportError:  # pragma: nocover
    json = None  # noqa


from wheezy.http.functional import WSGIClient

from app import main


class PublicTestCase(unittest.TestCase):

    def setUp(self):
        self.client = WSGIClient(main)

    def tearDown(self):
        del self.client
        self.client = None

    def test_root(self):
        """ Ensure root page is rendered.
        """
        assert 200 == self.client.get('/')
        assert '- Home</title>' in self.client.content

    def test_home(self):
        """ Ensure home page is rendered.
        """
        assert 200 == self.client.get('/home')
        assert '- Home</title>' in self.client.content

    def test_static_files(self):
        """ Ensure static content is served.
        """
        for static_file in [
            '/favicon.ico',
            '/static/css/site.css',
            '/static/js/core.js',
        ]:
            assert 200 == self.client.get(static_file)

    def test_static_file_not_found(self):
        """ Ensure 404 status code for non existing
            static content.
        """
        assert 302 == self.client.get('/static/css/unknown.css')
        assert '404' in self.client.headers['Location'][0]

    def test_static_file_forbidden(self):
        """ Ensure 403 status code for forbidden
            static content.
        """
        assert 302 == self.client.get('/static/../templates/')
        assert '403' in self.client.headers['Location'][0]


class ErrorTestCase(unittest.TestCase):

    def setUp(self):
        self.client = WSGIClient(main)

    def tearDown(self):
        del self.client
        self.client = None

    def test_error_400(self):
        """ Ensure bad request page is rendered.
        """
        assert 400 == self.client.get('/error/400')
        assert 'Code 400' in self.client.content

    def test_error_403(self):
        """ Ensure forbidden page is rendered.
        """
        assert 403 == self.client.get('/error/403')
        assert 'Code 403' in self.client.content

    def test_error_404(self):
        """ Ensure not found page is rendered.
        """
        assert 404 == self.client.get('/error/404')
        assert 'Code 404' in self.client.content

    def test_route_not_found(self):
        """ Ensure not found page is rendered.
        """
        self.client.get('/test-not-found')
        assert 404 == self.client.follow()
        assert 'Code 404' in self.client.content

    def test_error_500(self):
        """ Ensure internal error page is rendered.
        """
        assert 500 == self.client.get('/error/500')
        assert 'Code 500' in self.client.content
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.