Skip to content

Commit

Permalink
Fix templatetag tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mvantellingen committed May 31, 2017
1 parent 82f2dd4 commit e6fac5f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, nodelist, name):
def render(self, context):
# Check if segment exists
name = self.name.resolve(context)
segment = Segment.objects.filter(name=name).first()
segment = Segment.objects.enabled().filter(name=name).first()
if not segment:
return ""

Expand Down
13 changes: 4 additions & 9 deletions tests/unit/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,22 @@

import pytest
from django.template import TemplateSyntaxError
from wagtail_factories import SiteFactory

from tests.factories.segment import SegmentFactory
from tests.factories.rule import TimeRuleFactory
from tests.utils import render_template, add_session_to_request
from tests.utils import render_template


@pytest.mark.django_db
def test_segment_template_block(rf):
site = SiteFactory(is_default_site=True)
segment = SegmentFactory(name='test')
def test_segment_template_block(rf, site):
SegmentFactory(name='test', persistent=True)

request = rf.get('/')

add_session_to_request(request)

request.session['segments'] = [{
"encoded_name": 'test',
"id": 1,
"timestamp": int(time.time()),
"persistent": False
"persistent": True
}]

content = render_template("""
Expand Down
7 changes: 0 additions & 7 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
from django.template import engines
from django.contrib.sessions.middleware import SessionMiddleware


def render_template(value, **context):
template = engines['django'].from_string(value)
request = context.pop('request', None)
return template.render(context, request)


def add_session_to_request(request):
middleware = SessionMiddleware()
middleware.process_request(request)
request.session.save()

0 comments on commit e6fac5f

Please sign in to comment.