Increase test coverage
This commit is contained in:
@@ -14,7 +14,10 @@ class NamespacedSerializer(serializers.HyperlinkedModelSerializer):
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
if not hasattr(self.Meta, 'url_namespace') or self.Meta.url_namespace is None:
|
||||
if not hasattr(self, 'Meta') \
|
||||
or not hasattr(self.Meta, 'url_namespace') \
|
||||
or self.Meta.url_namespace is None \
|
||||
or self.Meta.url_namespace == '':
|
||||
raise ImproperlyConfigured("namespace must be set!")
|
||||
|
||||
self.url_namespace = self.Meta.url_namespace
|
||||
|
38
api/tests.py
38
api/tests.py
@@ -3,15 +3,51 @@
|
||||
Test cases for API calls
|
||||
"""
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.test import TestCase
|
||||
from django_webtest import WebTest
|
||||
|
||||
import json
|
||||
|
||||
from .serializers import NamespacedSerializer
|
||||
from booking.ducklevel import level_to_up_minutes
|
||||
from booking.models import Species, Location, Duck, Competence, DuckCompetence
|
||||
|
||||
class MetalessNamespacedSerializer(NamespacedSerializer):
|
||||
pass
|
||||
|
||||
class MissingNamespacedSerializer(NamespacedSerializer):
|
||||
class Meta:
|
||||
pass
|
||||
|
||||
class NoneNamespacedSerializer(NamespacedSerializer):
|
||||
class Meta:
|
||||
url_namespace = None
|
||||
|
||||
class EmptyNamespacedSerializer(NamespacedSerializer):
|
||||
class Meta:
|
||||
url_namespace = ''
|
||||
|
||||
class TestNamespacedSerializer(TestCase):
|
||||
"""
|
||||
Test namespaced Serializer
|
||||
"""
|
||||
|
||||
def test_no_namespace(self):
|
||||
with self.assertRaises(ImproperlyConfigured):
|
||||
serializer = MetalessNamespacedSerializer()
|
||||
|
||||
with self.assertRaises(ImproperlyConfigured):
|
||||
serializer = MissingNamespacedSerializer()
|
||||
|
||||
with self.assertRaises(ImproperlyConfigured):
|
||||
serializer = NoneNamespacedSerializer()
|
||||
|
||||
with self.assertRaises(ImproperlyConfigured):
|
||||
serializer = EmptyNamespacedSerializer()
|
||||
|
||||
class DuckClassTest(WebTest):
|
||||
"""
|
||||
Test case for duck related API calls
|
||||
|
Reference in New Issue
Block a user