57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
# -*- coding: utf-8; -*-
|
|
|
|
from pyramid.httpexceptions import HTTPFound, HTTPForbidden, HTTPNotFound
|
|
|
|
from wuttaweb.views import base as mod
|
|
from wuttaweb.forms import Form
|
|
from wuttaweb.grids import Grid, GridAction
|
|
from tests.util import WebTestCase
|
|
|
|
|
|
class TestView(WebTestCase):
|
|
|
|
def make_view(self):
|
|
return mod.View(self.request)
|
|
|
|
def test_basic(self):
|
|
view = self.make_view()
|
|
self.assertIs(view.request, self.request)
|
|
self.assertIs(view.config, self.config)
|
|
self.assertIs(view.app, self.app)
|
|
|
|
def test_forbidden(self):
|
|
view = self.make_view()
|
|
error = view.forbidden()
|
|
self.assertIsInstance(error, HTTPForbidden)
|
|
|
|
def test_make_form(self):
|
|
view = self.make_view()
|
|
form = view.make_form()
|
|
self.assertIsInstance(form, Form)
|
|
|
|
def test_make_grid(self):
|
|
view = self.make_view()
|
|
grid = view.make_grid()
|
|
self.assertIsInstance(grid, Grid)
|
|
|
|
def test_make_grid_action(self):
|
|
view = self.make_view()
|
|
action = view.make_grid_action('view')
|
|
self.assertIsInstance(action, GridAction)
|
|
|
|
def test_notfound(self):
|
|
view = self.make_view()
|
|
error = view.notfound()
|
|
self.assertIsInstance(error, HTTPNotFound)
|
|
|
|
def test_redirect(self):
|
|
view = self.make_view()
|
|
error = view.redirect('/')
|
|
self.assertIsInstance(error, HTTPFound)
|
|
self.assertEqual(error.location, '/')
|
|
|
|
def test_json_response(self):
|
|
view = self.make_view()
|
|
response = view.json_response({'foo': 'bar'})
|
|
self.assertEqual(response.status_code, 200)
|