From b347055bd1eee9cca9d0e64ca0b27753a4aaed16 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 21 Oct 2015 11:46:45 +0200 Subject: [PATCH] Add thorough tests for NamespacedSerializer --- api/tests.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/api/tests.py b/api/tests.py index 64acb65..83e048f 100644 --- a/api/tests.py +++ b/api/tests.py @@ -6,7 +6,7 @@ Test cases for API calls 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.test import TestCase, RequestFactory from django_webtest import WebTest import json @@ -48,6 +48,22 @@ class TestNamespacedSerializer(TestCase): with self.assertRaises(ImproperlyConfigured): serializer = EmptyNamespacedSerializer() + def test_namespacing(self): + class MySerializer(NamespacedSerializer): + class Meta: + model = Competence + fields = ('url',) + url_namespace = 'api' + + competence = Competence.objects.create( + added_by=User.objects.create()) + serializer = MySerializer(competence, + context={ + 'request': RequestFactory().get('/') + }) + + self.assertIsNotNone(serializer.data['url']) + class DuckClassTest(WebTest): """ Test case for duck related API calls