  #             def post(self, request, *args, **kwargs):
  #                 return Response({'FILE_NAME': self.CONTENT['file'].name,
  #                         'FILE_CONTENT': self.CONTENT['file'].read()})
  
 
</s> remove         file = StringIO.StringIO('stuff')
        file.name = 'stuff.txt'
        request = self.factory.post('/', {'file': file})
        view = MockView.as_view()
        response = view(request)
        self.assertEquals(response.raw_content, {"FILE_CONTENT": "stuff", "FILE_NAME": "stuff.txt"})
 </s> add #             def post(self, request, *args, **kwargs):
#                 return Response({'FILE_NAME': self.CONTENT['file'].name,
#                         'FILE_CONTENT': self.CONTENT['file'].read()}) </s> remove         class MockView(View):
            permissions = ()
            form = FileForm
 </s> add #         class FileForm(forms.Form):
#             file = forms.FileField() </s> remove             def post(self, request, *args, **kwargs):
                return Response({'FILE_NAME': self.CONTENT['file'].name,
                        'FILE_CONTENT': self.CONTENT['file'].read()})
 </s> add #         class MockView(View):
#             permissions = ()
#             form = FileForm </s> remove from django.core.urlresolvers import reverse
from django.conf.urls.defaults import patterns, url, include
from django.http import HttpResponse
from django.test import TestCase
from django import forms
from django.db import models
from django.utils import simplejson as json

from djangorestframework.resources import ModelResource
from djangorestframework.views import (
    View,
    ListOrCreateModelView,
    InstanceModelView
)


class MockView(View):
    """This is a basic mock view"""
    pass


class MockViewFinal(View):
    """View with final() override"""

    def final(self, request, response, *args, **kwargs):
        return HttpResponse('{"test": "passed"}', content_type="application/json")


class ResourceMockView(View):
    """This is a resource-based mock view"""

    class MockForm(forms.Form):
        foo = forms.BooleanField(required=False)
        bar = forms.IntegerField(help_text='Must be an integer.')
        baz = forms.CharField(max_length=32)

    form = MockForm


class MockResource(ModelResource):
    """This is a mock model-based resource"""

    class MockResourceModel(models.Model):
        foo = models.BooleanField()
        bar = models.IntegerField(help_text='Must be an integer.')
        baz = models.CharField(max_length=32, help_text='Free text.  Max length 32 chars.')

    model = MockResourceModel
    fields = ('foo', 'bar', 'baz')

urlpatterns = patterns('',
    url(r'^mock/$', MockView.as_view()),
    url(r'^mock/final/$', MockViewFinal.as_view()),
    url(r'^resourcemock/$', ResourceMockView.as_view()),
    url(r'^model/$', ListOrCreateModelView.as_view(resource=MockResource)),
    url(r'^model/(?P<pk>[^/]+)/$', InstanceModelView.as_view(resource=MockResource)),
    url(r'^restframework/', include('djangorestframework.urls', namespace='djangorestframework')),
)


class BaseViewTests(TestCase):
    """Test the base view class of djangorestframework"""
    urls = 'djangorestframework.tests.views'

    def test_view_call_final(self):
        response = self.client.options('/mock/final/')
        self.assertEqual(response['Content-Type'].split(';')[0], "application/json")
        data = json.loads(response.content)
        self.assertEqual(data['test'], 'passed')

    def test_options_method_simple_view(self):
        response = self.client.options('/mock/')
        self._verify_options_response(response,
                                      name='Mock',
                                      description='This is a basic mock view')

    def test_options_method_resource_view(self):
        response = self.client.options('/resourcemock/')
        self._verify_options_response(response,
                                      name='Resource Mock',
                                      description='This is a resource-based mock view',
                                      fields={'foo': 'BooleanField',
                                              'bar': 'IntegerField',
                                              'baz': 'CharField',
                                              })

    def test_options_method_model_resource_list_view(self):
        response = self.client.options('/model/')
        self._verify_options_response(response,
                                      name='Mock List',
                                      description='This is a mock model-based resource',
                                      fields={'foo': 'BooleanField',
                                              'bar': 'IntegerField',
                                              'baz': 'CharField',
                                              })

    def test_options_method_model_resource_detail_view(self):
        response = self.client.options('/model/0/')
        self._verify_options_response(response,
                                      name='Mock Instance',
                                      description='This is a mock model-based resource',
                                      fields={'foo': 'BooleanField',
                                              'bar': 'IntegerField',
                                              'baz': 'CharField',
                                              })

    def _verify_options_response(self, response, name, description, fields=None, status=200,
                                 mime_type='application/json'):
        self.assertEqual(response.status_code, status)
        self.assertEqual(response['Content-Type'].split(';')[0], mime_type)
        data = json.loads(response.content)
        self.assertTrue('application/json' in data['renders'])
        self.assertEqual(name, data['name'])
        self.assertEqual(description, data['description'])
        if fields is None:
            self.assertFalse(hasattr(data, 'fields'))
        else:
            self.assertEqual(data['fields'], fields)


class ExtraViewsTests(TestCase):
    """Test the extra views djangorestframework provides"""
    urls = 'djangorestframework.tests.views'

    def test_login_view(self):
        """Ensure the login view exists"""
        response = self.client.get(reverse('djangorestframework:login'))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-Type'].split(';')[0], 'text/html')

    def test_logout_view(self):
        """Ensure the logout view exists"""
        response = self.client.get(reverse('djangorestframework:logout'))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-Type'].split(';')[0], 'text/html')
 </s> add # from django.core.urlresolvers import reverse
# from django.conf.urls.defaults import patterns, url, include
# from django.http import HttpResponse
# from django.test import TestCase
# from django.utils import simplejson as json

# from djangorestframework.views import View


# class MockView(View):
#     """This is a basic mock view"""
#     pass


# class MockViewFinal(View):
#     """View with final() override"""

#     def final(self, request, response, *args, **kwargs):
#         return HttpResponse('{"test": "passed"}', content_type="application/json")


# # class ResourceMockView(View):
# #     """This is a resource-based mock view"""

# #     class MockForm(forms.Form):
# #         foo = forms.BooleanField(required=False)
# #         bar = forms.IntegerField(help_text='Must be an integer.')
# #         baz = forms.CharField(max_length=32)

# #     form = MockForm


# # class MockResource(ModelResource):
# #     """This is a mock model-based resource"""

# #     class MockResourceModel(models.Model):
# #         foo = models.BooleanField()
# #         bar = models.IntegerField(help_text='Must be an integer.')
# #         baz = models.CharField(max_length=32, help_text='Free text.  Max length 32 chars.')

# #     model = MockResourceModel
# #     fields = ('foo', 'bar', 'baz')

# urlpatterns = patterns('',
#     url(r'^mock/$', MockView.as_view()),
#     url(r'^mock/final/$', MockViewFinal.as_view()),
#     # url(r'^resourcemock/$', ResourceMockView.as_view()),
#     # url(r'^model/$', ListOrCreateModelView.as_view(resource=MockResource)),
#     # url(r'^model/(?P<pk>[^/]+)/$', InstanceModelView.as_view(resource=MockResource)),
#     url(r'^restframework/', include('djangorestframework.urls', namespace='djangorestframework')),
# )


# class BaseViewTests(TestCase):
#     """Test the base view class of djangorestframework"""
#     urls = 'djangorestframework.tests.views'

#     def test_view_call_final(self):
#         response = self.client.options('/mock/final/')
#         self.assertEqual(response['Content-Type'].split(';')[0], "application/json")
#         data = json.loads(response.content)
#         self.assertEqual(data['test'], 'passed')

#     def test_options_method_simple_view(self):
#         response = self.client.options('/mock/')
#         self._verify_options_response(response,
#                                       name='Mock',
#                                       description='This is a basic mock view')

#     def test_options_method_resource_view(self):
#         response = self.client.options('/resourcemock/')
#         self._verify_options_response(response,
#                                       name='Resource Mock',
#                                       description='This is a resource-based mock view',
#                                       fields={'foo': 'BooleanField',
#                                               'bar': 'IntegerField',
#                                               'baz': 'CharField',
#                                               })

#     def test_options_method_model_resource_list_view(self):
#         response = self.client.options('/model/')
#         self._verify_options_response(response,
#                                       name='Mock List',
#                                       description='This is a mock model-based resource',
#                                       fields={'foo': 'BooleanField',
#                                               'bar': 'IntegerField',
#                                               'baz': 'CharField',
#                                               })

#     def test_options_method_model_resource_detail_view(self):
#         response = self.client.options('/model/0/')
#         self._verify_options_response(response,
#                                       name='Mock Instance',
#                                       description='This is a mock model-based resource',
#                                       fields={'foo': 'BooleanField',
#                                               'bar': 'IntegerField',
#                                               'baz': 'CharField',
#                                               })

#     def _verify_options_response(self, response, name, description, fields=None, status=200,
#                                  mime_type='application/json'):
#         self.assertEqual(response.status_code, status)
#         self.assertEqual(response['Content-Type'].split(';')[0], mime_type)
#         data = json.loads(response.content)
#         self.assertTrue('application/json' in data['renders'])
#         self.assertEqual(name, data['name'])
#         self.assertEqual(description, data['description'])
#         if fields is None:
#             self.assertFalse(hasattr(data, 'fields'))
#         else:
#             self.assertEqual(data['fields'], fields)


# class ExtraViewsTests(TestCase):
#     """Test the extra views djangorestframework provides"""
#     urls = 'djangorestframework.tests.views'

#     def test_login_view(self):
#         """Ensure the login view exists"""
#         response = self.client.get(reverse('djangorestframework:login'))
#         self.assertEqual(response.status_code, 200)
#         self.assertEqual(response['Content-Type'].split(';')[0], 'text/html')

#     def test_logout_view(self):
#         """Ensure the logout view exists"""
#         response = self.client.get(reverse('djangorestframework:logout'))
#         self.assertEqual(response.status_code, 200)
#         self.assertEqual(response['Content-Type'].split(';')[0], 'text/html') </s> remove """Tests for the mixin module"""
from django.test import TestCase
from django.utils import simplejson as json
from djangorestframework import status
from djangorestframework.compat import RequestFactory
from django.contrib.auth.models import Group, User
from djangorestframework.mixins import CreateModelMixin, PaginatorMixin, ReadModelMixin
from djangorestframework.resources import ModelResource
from djangorestframework.response import Response, ImmediateResponse
from djangorestframework.tests.models import CustomUser
from djangorestframework.tests.testcases import TestModelsTestCase
from djangorestframework.views import View


class TestModelRead(TestModelsTestCase):
    """Tests on ReadModelMixin"""

    def setUp(self):
        super(TestModelRead, self).setUp()
        self.req = RequestFactory()

    def test_read(self):
        Group.objects.create(name='other group')
        group = Group.objects.create(name='my group')

        class GroupResource(ModelResource):
            model = Group

        request = self.req.get('/groups')
        mixin = ReadModelMixin()
        mixin.resource = GroupResource

        response = mixin.get(request, id=group.id)
        self.assertEquals(group.name, response.raw_content.name)

    def test_read_404(self):
        class GroupResource(ModelResource):
            model = Group

        request = self.req.get('/groups')
        mixin = ReadModelMixin()
        mixin.resource = GroupResource

        self.assertRaises(ImmediateResponse, mixin.get, request, id=12345)


class TestModelCreation(TestModelsTestCase):
    """Tests on CreateModelMixin"""

    def setUp(self):
        super(TestModelsTestCase, self).setUp()
        self.req = RequestFactory()

    def test_creation(self):
        self.assertEquals(0, Group.objects.count())

        class GroupResource(ModelResource):
            model = Group

        form_data = {'name': 'foo'}
        request = self.req.post('/groups', data=form_data)
        mixin = CreateModelMixin()
        mixin.resource = GroupResource
        mixin.CONTENT = form_data

        response = mixin.post(request)
        self.assertEquals(1, Group.objects.count())
        self.assertEquals('foo', response.raw_content.name)

    def test_creation_with_m2m_relation(self):
        class UserResource(ModelResource):
            model = User

            def url(self, instance):
                return "/users/%i" % instance.id

        group = Group(name='foo')
        group.save()

        form_data = {
            'username': 'bar',
            'password': 'baz',
            'groups': [group.id]
        }
        request = self.req.post('/groups', data=form_data)
        cleaned_data = dict(form_data)
        cleaned_data['groups'] = [group]
        mixin = CreateModelMixin()
        mixin.resource = UserResource
        mixin.CONTENT = cleaned_data

        response = mixin.post(request)
        self.assertEquals(1, User.objects.count())
        self.assertEquals(1, response.raw_content.groups.count())
        self.assertEquals('foo', response.raw_content.groups.all()[0].name)

    def test_creation_with_m2m_relation_through(self):
        """
        Tests creation where the m2m relation uses a through table
        """
        class UserResource(ModelResource):
            model = CustomUser

            def url(self, instance):
                return "/customusers/%i" % instance.id

        form_data = {'username': 'bar0', 'groups': []}
        request = self.req.post('/groups', data=form_data)
        cleaned_data = dict(form_data)
        cleaned_data['groups'] = []
        mixin = CreateModelMixin()
        mixin.resource = UserResource
        mixin.CONTENT = cleaned_data
 </s> add # """Tests for the mixin module"""
# from django.test import TestCase
# from djangorestframework import status
# from djangorestframework.compat import RequestFactory
# from django.contrib.auth.models import Group, User
# from djangorestframework.mixins import CreateModelMixin, PaginatorMixin, ReadModelMixin
# from djangorestframework.resources import ModelResource
# from djangorestframework.response import Response, ImmediateResponse
# from djangorestframework.tests.models import CustomUser
# from djangorestframework.tests.testcases import TestModelsTestCase
# from djangorestframework.views import View


# class TestModelRead(TestModelsTestCase):
#     """Tests on ReadModelMixin"""

#     def setUp(self):
#         super(TestModelRead, self).setUp()
#         self.req = RequestFactory()

#     def test_read(self):
#         Group.objects.create(name='other group')
#         group = Group.objects.create(name='my group')

#         class GroupResource(ModelResource):
#             model = Group

#         request = self.req.get('/groups')
#         mixin = ReadModelMixin()
#         mixin.resource = GroupResource

#         response = mixin.get(request, id=group.id)
#         self.assertEquals(group.name, response.raw_content.name)

#     def test_read_404(self):
#         class GroupResource(ModelResource):
#             model = Group

#         request = self.req.get('/groups')
#         mixin = ReadModelMixin()
#         mixin.resource = GroupResource

#         self.assertRaises(ImmediateResponse, mixin.get, request, id=12345)


# class TestModelCreation(TestModelsTestCase):
#     """Tests on CreateModelMixin"""

#     def setUp(self):
#         super(TestModelsTestCase, self).setUp()
#         self.req = RequestFactory()

#     def test_creation(self):
#         self.assertEquals(0, Group.objects.count())

#         class GroupResource(ModelResource):
#             model = Group

#         form_data = {'name': 'foo'}
#         request = self.req.post('/groups', data=form_data)
#         mixin = CreateModelMixin()
#         mixin.resource = GroupResource
#         mixin.CONTENT = form_data

#         response = mixin.post(request)
#         self.assertEquals(1, Group.objects.count())
#         self.assertEquals('foo', response.raw_content.name)

#     def test_creation_with_m2m_relation(self):
#         class UserResource(ModelResource):
#             model = User

#             def url(self, instance):
#                 return "/users/%i" % instance.id

#         group = Group(name='foo')
#         group.save()

#         form_data = {
#             'username': 'bar',
#             'password': 'baz',
#             'groups': [group.id]
#         }
#         request = self.req.post('/groups', data=form_data)
#         cleaned_data = dict(form_data)
#         cleaned_data['groups'] = [group]
#         mixin = CreateModelMixin()
#         mixin.resource = UserResource
#         mixin.CONTENT = cleaned_data

#         response = mixin.post(request)
#         self.assertEquals(1, User.objects.count())
#         self.assertEquals(1, response.raw_content.groups.count())
#         self.assertEquals('foo', response.raw_content.groups.all()[0].name)

#     def test_creation_with_m2m_relation_through(self):
#         """
#         Tests creation where the m2m relation uses a through table
#         """
#         class UserResource(ModelResource):
#             model = CustomUser

#             def url(self, instance):
#                 return "/customusers/%i" % instance.id

#         form_data = {'username': 'bar0', 'groups': []}
#         request = self.req.post('/groups', data=form_data)
#         cleaned_data = dict(form_data)
#         cleaned_data['groups'] = []
#         mixin = CreateModelMixin()
#         mixin.resource = UserResource
#         mixin.CONTENT = cleaned_data
#         file = StringIO.StringIO('stuff')
#         file.name = 'stuff.txt'
#         request = self.factory.post('/', {'file': file})
#         view = MockView.as_view()
#         response = view(request)
#         self.assertEquals(response.raw_content, {"FILE_CONTENT": "stuff", "FILE_NAME": "stuff.txt"})
  #             def post(self, request, *args, **kwargs):
  #                 return Response({'FILE_NAME': self.CONTENT['file'].name,
  #                         'FILE_CONTENT': self.CONTENT['file'].read()})
  
#         file = StringIO.StringIO('stuff')
#         file.name = 'stuff.txt'
#         request = self.factory.post('/', {'file': file})
#         view = MockView.as_view()
#         response = view(request)
#         self.assertEquals(response.raw_content, {"FILE_CONTENT": "stuff", "FILE_NAME": "stuff.txt"})
keep keep keep add
 Drop out resources & mixins 
djangorestframework/tests/files.py