2024-08-05 21:49:18 -05:00
|
|
|
# -*- coding: utf-8; -*-
|
|
|
|
|
|
|
|
from tests.views.utils import WebTestCase
|
|
|
|
|
2024-08-07 19:47:24 -05:00
|
|
|
from pyramid.httpexceptions import HTTPNotFound
|
|
|
|
|
2024-08-05 21:49:18 -05:00
|
|
|
from wuttaweb.views import settings
|
|
|
|
|
|
|
|
|
|
|
|
class TestAppInfoView(WebTestCase):
|
|
|
|
|
2024-08-07 14:00:53 -05:00
|
|
|
def make_view(self):
|
|
|
|
return settings.AppInfoView(self.request)
|
|
|
|
|
2024-08-05 21:49:18 -05:00
|
|
|
def test_index(self):
|
2024-08-06 19:59:30 -05:00
|
|
|
# sanity/coverage check
|
2024-08-07 14:00:53 -05:00
|
|
|
view = self.make_view()
|
2024-08-05 21:49:18 -05:00
|
|
|
response = view.index()
|
2024-08-06 18:52:54 -05:00
|
|
|
|
|
|
|
def test_configure_get_simple_settings(self):
|
2024-08-06 19:59:30 -05:00
|
|
|
# sanity/coverage check
|
2024-08-07 14:00:53 -05:00
|
|
|
view = self.make_view()
|
2024-08-06 18:52:54 -05:00
|
|
|
simple = view.configure_get_simple_settings()
|
2024-08-06 19:59:30 -05:00
|
|
|
|
|
|
|
def test_configure_get_context(self):
|
|
|
|
# sanity/coverage check
|
2024-08-07 14:00:53 -05:00
|
|
|
view = self.make_view()
|
2024-08-06 19:59:30 -05:00
|
|
|
context = view.configure_get_context()
|
2024-08-07 14:00:53 -05:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
2024-08-07 19:47:24 -05:00
|
|
|
|
|
|
|
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')
|