Skip to content

Commit

Permalink
Integration tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
ellmetha committed Mar 23, 2015
1 parent 168303d commit 333aefd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions machina/templatetags/forum_member_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ def is_anonymous(user):
{% if topic.poster|is_anonymous %}...{% endif %}
"""
return user.id == settings.ANONYMOUS_USER_ID if hasattr(settings, 'ANONYMOUS_USER_ID') \
else user.is_authenticated()
return (user.id == settings.ANONYMOUS_USER_ID if hasattr(settings, 'ANONYMOUS_USER_ID') else False) \
or not user.is_authenticated()
43 changes: 43 additions & 0 deletions tests/integration/templatetags/test_member_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-

# Standard library imports
# Third party imports
from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.contrib.auth.models import User
from django.template import Context
from django.template.base import Template
from django.test import TestCase
from django.test.client import RequestFactory

# Local application / specific library imports
from machina.test.factories import UserFactory


class TestIsAnonymousTag(TestCase):
def setUp(self):
self.loadstatement = '{% load url from future %}{% load forum_member_tags %}'
self.request_factory = RequestFactory()
self.user = UserFactory.create()

def get_rendered(self, user):
request = self.request_factory.get('/')
t = Template(self.loadstatement + '{% if user|is_anonymous %}OK{% else %}NOK{% endif %}')
c = Context({'user': user, 'request': request})
rendered = t.render(c)

return rendered

def test_can_tell_that_a_registered_user_is_not_anonymous(self):
# Run & check
self.assertEqual(self.get_rendered(self.user), 'NOK')

def test_can_tell_that_a_django_anonymous_user_is_anonymous(self):
# Run & check
self.assertEqual(self.get_rendered(AnonymousUser()), 'OK')

def test_can_tell_that_a_guardian_anonymous_user_is_anonymous(self):
# Setup
user = User.objects.get(id=settings.ANONYMOUS_USER_ID)
# Run & check
self.assertEqual(self.get_rendered(user), 'OK')

0 comments on commit 333aefd

Please sign in to comment.