Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Testing utils.serilize_to_response more thoroughly.

  • Loading branch information...
commit 69356808a63462d559c39ed6c452d1c2f8c6f3be 1 parent 8ea0968
Jaap Roes authored
View
1  setup.py
@@ -43,4 +43,5 @@
packages = find_packages(),
include_package_data = True,
zip_safe = False,
+ tests_require=['unittest2'],
)
View
38 tests/test_app/tests.py
@@ -1,12 +1,42 @@
+import re
import StringIO
+
+from django.contrib.flatpages.models import FlatPage
+from django.core.management import CommandError
from django.test import TestCase
+from unittest2 import TestCase as TestCase2
from smuggler import utils
-class BasicDumpTestCase(TestCase):
+class BasicDumpTestCase(TestCase, TestCase2):
+ SITE_DUMP = '{ "pk": 1, "model": "sites.site", "fields": { "domain": "example.com", "name": "example.com" } }'
+ FLATPAGE_DUMP = '{ "pk": 1, "model": "flatpages.flatpage", "fields": { "registration_required": false, "title": "test", "url": "/", "template_name": "", "sites": [], "content": "", "enable_comments": false } }'
+ BASIC_DUMP = '[ %s, %s ]' % (SITE_DUMP, FLATPAGE_DUMP)
+
+ def setUp(self):
+ f = FlatPage(url='/', title='test')
+ f.save()
+
+ def normalize(self, out):
+ return re.sub(r'\s\s*', ' ', out)
+
def test_serialize_to_response(self):
- response = StringIO.StringIO()
- utils.serialize_to_response(response=response)
- self.assertEqual('[]', response.getvalue())
+ stream = StringIO.StringIO()
+ utils.serialize_to_response(response=stream)
+ out = self.normalize(stream.getvalue())
+ self.assertEquals(out, self.BASIC_DUMP)
+
+ def test_serialize_exclude(self):
+ stream = StringIO.StringIO()
+ utils.serialize_to_response(exclude=['sites'], response=stream)
+ out = self.normalize(stream.getvalue())
+ self.assertEquals(out, '[ %s ]' % self.FLATPAGE_DUMP)
+ def test_serialize_include(self):
+ stream = StringIO.StringIO()
+ utils.serialize_to_response(app_labels=['sites'], response=stream)
+ out = self.normalize(stream.getvalue())
+ self.assertEquals(out, '[ %s ]' % self.SITE_DUMP)
+ def test_serialize_unknown_app_fail(self):
+ self.assertRaises(CommandError, utils.serialize_to_response, 'auth')
View
2  tests/test_settings.py
@@ -12,6 +12,8 @@
SECRET_KEY = 'mAtTzVPOV9JY4eJQfqgW8eAS9DWKnt3MkvvpQI2MzkhAz7z3'
INSTALLED_APPS = [
+ 'django.contrib.sites',
+ 'django.contrib.flatpages',
'smuggler',
'test_app',
]
View
9 tox.ini
@@ -5,35 +5,44 @@ envlist = py25-1.2, py25-1.3,
[testenv]
commands = python tests/run_tests.py
+deps = unittest2
[testenv:py25-1.2]
basepython = python2.5
deps = django>=1.2,<1.3
+ {[testenv]deps}
[testenv:py25-1.3]
basepython = python2.5
deps = django>=1.3,<1.4
+ {[testenv]deps}
[testenv:py26-1.3]
basepython = python2.6
deps = django>=1.3,<1.4
+ {[testenv]deps}
[testenv:py26-1.4]
basepython = python2.6
deps = django>=1.4,<1.5
+ {[testenv]deps}
[testenv:py26-1.5]
basepython = python2.6
deps = https://github.com/django/django/tarball/stable/1.5.x
+ {[testenv]deps}
[testenv:py27-1.3]
basepython = python2.7
deps = django>=1.3,<1.4
+ {[testenv]deps}
[testenv:py27-1.4]
basepython = python2.7
deps = django>=1.4,<1.5
+ {[testenv]deps}
[testenv:py27-1.5]
basepython = python2.7
deps = https://github.com/django/django/tarball/stable/1.5.x
+ {[testenv]deps}
Please sign in to comment.
Something went wrong with that request. Please try again.