aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authormarkotibold2011-03-09 00:26:20 +0100
committermarkotibold2011-03-09 00:26:20 +0100
commitf88d8193a8757ce00b91ba81377216559977b519 (patch)
tree87d35a04f0ebfc5dab34c2dc236797e7011e04bf /examples
parent32be0581953a7e29ab1d3e1c580ae95a35935e41 (diff)
downloaddjango-rest-framework-f88d8193a8757ce00b91ba81377216559977b519.tar.bz2
Test implemented for #28 Pygments examples should be datetime sorted
models.py is needed if we want to put tests in tests.py (see first line of models.py)
Diffstat (limited to 'examples')
-rw-r--r--examples/pygments_api/models.py1
-rw-r--r--examples/pygments_api/tests.py41
2 files changed, 42 insertions, 0 deletions
diff --git a/examples/pygments_api/models.py b/examples/pygments_api/models.py
new file mode 100644
index 00000000..402a813e
--- /dev/null
+++ b/examples/pygments_api/models.py
@@ -0,0 +1 @@
+#We need models.py otherwise the test framework complains (http://code.djangoproject.com/ticket/7198)
diff --git a/examples/pygments_api/tests.py b/examples/pygments_api/tests.py
new file mode 100644
index 00000000..f70eff0e
--- /dev/null
+++ b/examples/pygments_api/tests.py
@@ -0,0 +1,41 @@
+from django.test import TestCase
+from djangorestframework.compat import RequestFactory
+from pygments_api import views
+import os, tempfile, shutil
+
+class TestPygmentsExample(TestCase):
+
+ def setUp(self):
+ self.factory = RequestFactory()
+ self.temp_dir = tempfile.mkdtemp()
+ views.HIGHLIGHTED_CODE_DIR = self.temp_dir
+
+ def tearDown(self):
+ try:
+ shutil.rmtree(self.temp_dir)
+ except:
+ pass
+
+ def test_get_to_root(self):
+ '''Just do a get on the base url'''
+ request = self.factory.get('/pygments')
+ view = views.PygmentsRoot.as_view()
+ response = view(request)
+ self.assertEqual(response.status_code, 200)
+
+ def test_snippets_datetime_sorted(self):
+ '''Pygments examples should be datetime sorted'''
+ locations = []
+ for snippet in 'abcdefghijk':
+ form_data = {'code': '%s' % snippet, 'style':'friendly', 'lexer':'python'}
+ request = self.factory.post('/pygments', data=form_data)
+ view = views.PygmentsRoot.as_view()
+ response = view(request)
+ locations.append(response.items()[2][1])
+ request = self.factory.get('/pygments')
+ view = views.PygmentsRoot.as_view()
+ response = view(request)
+ self.assertEquals(locations, response.content)
+
+
+ \ No newline at end of file