This repository has been archived by the owner on Jan 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add template context processor to list all communities in the navbar …
…+ unittest
- Loading branch information
1 parent
c9689d1
commit 9d1f16c
Showing
4 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from community.models import Community | ||
|
||
|
||
def communities_processor(request): | ||
"""Custom template context preprocessor that allows to inject into every | ||
request the list of all communities. This is necessary in order to display | ||
the list of communities in the navigation bar.""" | ||
communities = Community.objects.all().order_by("order") | ||
return {'communities': communities} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django.contrib.auth.models import User | ||
from django.core.urlresolvers import reverse | ||
from django.test import TestCase, Client | ||
|
||
from users.models import SystersUser | ||
from community.models import Community | ||
|
||
|
||
class CommunitiesProcessorTestCase(TestCase): | ||
def setUp(self): | ||
User.objects.create(username='foo', password='foobar') | ||
self.systers_user = SystersUser.objects.get() | ||
self.client = Client() | ||
|
||
def test_communities_processor(self): | ||
"""Test the rendering of all communities in the templates""" | ||
Community.objects.create(name="Foo", slug="foo", order=1, | ||
community_admin=self.systers_user) | ||
Community.objects.create(name="Boo", slug="boo", order=2, | ||
community_admin=self.systers_user) | ||
index_url = reverse('index') | ||
response = self.client.get(index_url) | ||
self.assertContains(response, '<a href="/community/foo/">Foo</a>') | ||
self.assertContains(response, '<a href="/community/boo/">Boo</a>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters