def test_cache_invalidated_by_save(simple_content): if SKIP_CACHE_TESTS: return with mock.patch('tinycontent.models.cache', FakeCache()): with QueryCounter() as q: obj = TinyContent.get_content_by_name(simple_content.name) assert obj == simple_content assert q.num_queries() == 1 with QueryCounter() as q: simple_content.content = 'hello' simple_content.save() q.num_queries() == 1 with QueryCounter() as q: obj = TinyContent.get_content_by_name(simple_content.name) assert obj.name == simple_content.name assert obj.content == 'hello' assert q.num_queries() == 1 with QueryCounter() as q: obj = TinyContent.get_content_by_name(simple_content.name) assert obj.name == simple_content.name assert obj.content == 'hello' assert q.num_queries() == 0
def test_cache_hit_on_second_time(simple_content): if SKIP_CACHE_TESTS: return with mock.patch('tinycontent.models.cache', FakeCache()): with QueryCounter() as q: obj = TinyContent.get_content_by_name(simple_content.name) assert obj == simple_content assert q.num_queries() == 1 with QueryCounter() as q: obj = TinyContent.get_content_by_name(simple_content.name) assert obj == simple_content assert q.num_queries() == 0
def __init__(self, *args, **kwargs): super(GIODOMixin, self).__init__(*args, **kwargs) self.fields['giodo'] = forms.BooleanField(required=True) try: self.fields['giodo'].label = TinyContent.get_content_by_name('giodo').content except TinyContent.DoesNotExist: self.fields['giodo'].label = 'Lorem ipsum'
def test_cache_invalidated_by_delete(simple_content): if SKIP_CACHE_TESTS: return with mock.patch('tinycontent.models.cache', FakeCache()): with QueryCounter() as q: obj = TinyContent.get_content_by_name(simple_content.name) assert obj == simple_content assert q.num_queries() == 1 with QueryCounter() as q: simple_content.delete() assert q.num_queries() == 1 with QueryCounter() as q: with pytest.raises(TinyContent.DoesNotExist): obj = TinyContent.get_content_by_name(simple_content.name) assert q.num_queries() == 1
def render(self, context): try: name = self.get_name(context) obj = TinyContent.get_content_by_name(name) context.update({'obj': obj}) return render_to_string('tinycontent/tinycontent.html', context) except TinyContent.DoesNotExist: rval = self.nodelist.render(context) context.update({'name': name}) rval += render_to_string('tinycontent/tinycontent_add.html', context) return rval
def render(self, context): try: name = self.get_name(context) obj = TinyContent.get_content_by_name(name) return render_to_string('tinycontent/tinycontent.html', {'obj': obj}, context) except TinyContent.DoesNotExist: rval = self.nodelist.render(context) rval += render_to_string('tinycontent/tinycontent_add.html', {'name': name}, context) return rval
def tinycontent_simple(context, *args): if not args: raise TemplateSyntaxError("'tinycontent' tag takes arguments.") content_name = u':'.join(map(force_text, args)) try: obj = TinyContent.get_content_by_name(content_name) context.update({'obj': obj}) return render_to_string('tinycontent/tinycontent.html', context) except TinyContent.DoesNotExist: context.update({'name': content_name}) return render_to_string('tinycontent/tinycontent_add.html', context)
def tinycontent_simple(context, *args): if not args: raise TemplateSyntaxError("'tinycontent' tag takes arguments.") content_name = u':'.join(map(force_text, args)) try: obj = TinyContent.get_content_by_name(content_name) return render_to_string('tinycontent/tinycontent.html', {'obj': obj}, context) except TinyContent.DoesNotExist: return render_to_string('tinycontent/tinycontent_add.html', {'name': content_name}, context)