This repository has been archived by the owner on Nov 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
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
778c33e
commit f4e2502
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,8 @@ | ||
from django.test import TestCase | ||
|
||
from ..apps import ApiConfig | ||
|
||
|
||
class APIAppTest(TestCase): | ||
def test_config(self): | ||
self.assertEqual('api', ApiConfig.name) |
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,13 @@ | ||
from django.test import TestCase | ||
|
||
from ..urls import urlpatterns | ||
|
||
|
||
class APIUrlsTest(TestCase): | ||
def test_urls(self): | ||
pattern_names = [p.name for p in urlpatterns[0].url_patterns] | ||
self.assertIn('api-root', pattern_names) | ||
self.assertIn('domainauthorization-list', pattern_names) | ||
self.assertIn('domainauthorization-detail', pattern_names) | ||
self.assertIn('pushapplication-list', pattern_names) | ||
self.assertIn('pushapplication-detail', pattern_names) |
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,78 @@ | ||
from django.contrib.auth.models import User | ||
from django.test import TestCase | ||
|
||
import fudge | ||
from model_mommy import mommy | ||
|
||
from domains.models import DomainAuthorization | ||
from push.models import PushApplication | ||
|
||
from .. import serializers, views | ||
|
||
|
||
class DomainAuthorizationViewSetTest(TestCase): | ||
def setUp(self): | ||
self.view = views.DomainAuthorizationViewSet() | ||
|
||
def test_attrs(self): | ||
self.assertIsInstance(self.view, views.ModelViewSet) | ||
self.assertEqual(DomainAuthorization, self.view.queryset.model) | ||
self.assertEqual(self.view.serializer_class, | ||
serializers.DomainAuthorizationSerializer) | ||
|
||
def test_queryset_filters_to_users_own_objects(self): | ||
user1 = mommy.make(User) | ||
user2 = mommy.make(User) | ||
mommy.make(DomainAuthorization, user=user1) | ||
mommy.make(DomainAuthorization, user=user2) | ||
self.view.request = fudge.Fake().has_attr(user=user1) | ||
|
||
domain_auths = self.view.get_queryset() | ||
for domain_auth in domain_auths: | ||
self.assertEqual(domain_auth.user, user1) | ||
|
||
self.view.request = fudge.Fake().has_attr(user=user2) | ||
|
||
domain_auths = self.view.get_queryset() | ||
for domain_auth in domain_auths: | ||
self.assertEqual(domain_auth.user, user2) | ||
|
||
@fudge.patch('api.views.messages.success') | ||
def test_add_message_calls_messages_success(self, success): | ||
success.expects_call() | ||
self.view.request = fudge.Fake().has_attr(_request=None) | ||
self.view.add_message() | ||
|
||
|
||
class PushApplicationViewSetTest(TestCase): | ||
def setUp(self): | ||
self.view = views.PushApplicationViewSet() | ||
|
||
def test_attrs(self): | ||
self.assertIsInstance(self.view, views.ModelViewSet) | ||
self.assertEqual(PushApplication, self.view.queryset.model) | ||
self.assertEqual(self.view.serializer_class, | ||
serializers.PushApplicationSerializer) | ||
|
||
def test_queryset_filters_to_users_own_objects(self): | ||
user1 = mommy.make(User) | ||
user2 = mommy.make(User) | ||
mommy.make(PushApplication, user=user1) | ||
mommy.make(PushApplication, user=user2) | ||
self.view.request = fudge.Fake().has_attr(user=user1) | ||
|
||
push_apps = self.view.get_queryset() | ||
for push_app in push_apps: | ||
self.assertEqual(push_app.user, user1) | ||
|
||
self.view.request = fudge.Fake().has_attr(user=user2) | ||
|
||
push_apps = self.view.get_queryset() | ||
for push_app in push_apps: | ||
self.assertEqual(push_app.user, user2) | ||
|
||
@fudge.patch('api.views.messages.success') | ||
def test_add_message_calls_messages_success(self, success): | ||
success.expects_call() | ||
self.view.request = fudge.Fake().has_attr(_request=None) | ||
self.view.add_message() |