mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-11 12:17:24 +03:00
f88d8193a8
models.py is needed if we want to put tests in tests.py (see first line of models.py)
41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
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)
|
|
|
|
|
|
|