1
0
Fork 0
wuttaweb/tests/views/test_settings.py
Lance Edgar 4c467f5267 feat: add basic support for "view" part of CRUD
still no SQLAlchemy yet, view must be explicit about data/model.  but
should support simple dict records, which will be needed in a few
places anyway
2024-08-07 19:47:24 -05:00

68 lines
1.9 KiB
Python

# -*- 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')