-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
addc504
commit c0e6cd4
Showing
6 changed files
with
83 additions
and
3 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
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,19 @@ | ||
from django.db import models | ||
|
||
|
||
class KindQuerySet(models.QuerySet): | ||
def emails(self): | ||
return self.filter(kind=self.model.EMAIL) | ||
|
||
def phones(self): | ||
return self.filter(kind=self.model.PHONE) | ||
|
||
|
||
class PeriodManager(models.Manager): | ||
MIDDAY = '12:00' | ||
|
||
def at_morning(self): | ||
return self.filter(start__lt=self.MIDDAY) | ||
|
||
def at_afternoon(self): | ||
return self.filter(start__gte=self.MIDDAY) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,25 @@ def test_str(self): | |
value='[email protected]' | ||
) | ||
self.assertEqual('[email protected]', str(contact)) | ||
|
||
|
||
class ContactManagerTest(TestCase): | ||
def setUp(self): | ||
s = Speaker.objects.create( | ||
name='Henrique Bastos', | ||
slug='henrique-bastos', | ||
photo='http://hbn.link/hb-pic' | ||
) | ||
|
||
s.contact_set.create(kind=Contact.EMAIL, value='[email protected]') | ||
s.contact_set.create(kind=Contact.PHONE, value='21-996186180') | ||
|
||
def test_email(self): | ||
qs = Contact.objects.emails() | ||
expected = ['[email protected]'] | ||
self.assertQuerysetEqual(qs, expected, lambda o: o.value) | ||
|
||
def test_phones(self): | ||
qs = Contact.objects.phones() | ||
expected = ['21-996186180'] | ||
self.assertQuerysetEqual(qs, expected, lambda o: o.value) |
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