2
0
Fork 0
wuttaweb/tests/views/test_settings.py

68 lines
1.9 KiB
Python
Raw Normal View History

# -*- coding: utf-8; -*-
from tests.views.utils import WebTestCase
from pyramid.httpexceptions import HTTPNotFound
from wuttaweb.views import settings
class TestAppInfoView(WebTestCase):
def make_view(self):
return settings.AppInfoView(self.request)
def test_index(self):
# sanity/coverage check
view = self.make_view()
response = view.index()
def test_configure_get_simple_settings(self):
# sanity/coverage check
view = self.make_view()
simple = view.configure_get_simple_settings()
def test_configure_get_context(self):
# sanity/coverage check
view = self.make_view()
context = view.configure_get_context()
class TestSettingView(WebTestCase):
def make_view(self):
return settings.SettingView(self.request)
def test_index_get_grid_data(self):
# empty data by default
view = self.make_view()
data = view.index_get_grid_data(session=self.session)
self.assertEqual(len(data), 0)
# unless we save some settings
self.app.save_setting(self.session, 'foo', 'bar')
self.session.commit()
data = view.index_get_grid_data(session=self.session)
self.assertEqual(len(data), 1)
def test_get_instance(self):
view = self.make_view()
self.request.matchdict = {'name': 'foo'}
# setting not found
setting = view.get_instance(session=self.session)
self.assertIsInstance(setting, HTTPNotFound)
# setting is returned
self.app.save_setting(self.session, 'foo', 'bar')
self.session.commit()
setting = view.get_instance(session=self.session)
self.assertEqual(setting, {'name': 'foo', 'value': 'bar'})
def test_get_instance_title(self):
setting = {'name': 'foo', 'value': 'bar'}
view = self.make_view()
title = view.get_instance_title(setting)
self.assertEqual(title, 'foo')