Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use context processor to retrieve information about the kinds used to…
… render the sidemenu
- Loading branch information
1 parent
51c8178
commit ccca931
Showing
7 changed files
with
41 additions
and
42 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 |
---|---|---|
@@ -1,7 +1,14 @@ | ||
from .models import Pet | ||
from .models import Kind, Pet | ||
|
||
|
||
def pets_count(request): | ||
return { | ||
'pets_count': Pet.objects.count(), | ||
} | ||
|
||
|
||
def kinds_count(request): | ||
return { | ||
'kind_lost': Kind.objects.lost_kinds(), | ||
'kind_adoption': Kind.objects.adoption_kinds(), | ||
} |
Empty file.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,16 +1,25 @@ | ||
from django.test import TestCase | ||
from model_mommy import mommy | ||
|
||
from meupet.context_processors import pets_count | ||
from meupet.context_processors import pets_count, kinds_count | ||
from meupet.models import Pet | ||
|
||
|
||
class ContextProcessorsTestCase(TestCase): | ||
def setUp(self): | ||
mommy.make(Pet) | ||
mommy.make(Pet, kind__kind='Dog', status=Pet.ADOPTED) | ||
mommy.make(Pet, active=False) | ||
|
||
def test_pets_count(self): | ||
context = pets_count({}) | ||
|
||
self.assertEqual(2, context['pets_count']) | ||
|
||
def test_kind_count(self): | ||
context = kinds_count({}) | ||
|
||
adoption_count = context['kind_adoption'].first().num_pets | ||
|
||
self.assertIn('kind_lost', context) | ||
self.assertIn('kind_adoption', context) | ||
self.assertEqual(adoption_count, 1) |
This file was deleted.
Oops, something went wrong.
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