class TestBaseView(TestCase): def setUp(self): self.base = BaseWidget() self.base.template = 'some_template' self.base.uncacheable = mock.Mock() def tearDown(self): pass def test_base_no_use_cache(self): # when cache is not used, we still call both cacheable and uncacheable; # cacheable is what sets the template into the context self.base.cache_key = lambda *a, **kw: None self.base('request', 'arg', kwarg='kwval') self.base.uncacheable.assert_called_with('request', {'context':dict(), 'template': 'some_template'}, 'arg', kwarg='kwval') @mock.patch('marimo.views.base.cache') def test_base_cache_miss(self, mock_cache): # On a cache miss, both cacheable and uncacheable will be called, and # the cache will be set. self.base.cacheable = mock.Mock() self.base.cache_key = lambda *a, **kw: 'key' mock_cache.get.return_value = None self.base('request', 'arg', kwarg='kwval') self.assertTrue(mock_cache.set.called) self.assertTrue(self.base.cacheable.called) self.assertTrue(self.base.uncacheable.called) @mock.patch('marimo.views.base.cache') def test_base_cache_hit(self, mock_cache): # On a cache hit, only uncacheable will be called. self.base.cacheable = mock.Mock() self.base.cache_key = lambda *a, **kw: 'key' mock_cache.get.return_value = 'something' self.base('request', 'arg', kwarg='kwval') self.assertFalse(self.base.cacheable.called) self.assertTrue(self.base.uncacheable.called) def test_nocache_override(self): response = dict() self.base.nocache_override(response) self.assertTrue('__nocache_override' in response) self.assertEqual(response['__nocache_override'], 'no-cache,max-age=0')
def setUp(self): self.base = BaseWidget() self.base.template = 'some_template' self.base.uncacheable = mock.Mock()