david / django-modelviews

Backup of an old repository with useful ideas. Initial goal: integrating REST to django admin (class-based views).

Clone this repository (size: 85.8 KB): HTTPS / SSH
$ hg clone http://code.welldev.org/django-modelviews
commit 54: 6d70110cd775
parent 53: 45d3937d57aa
branch: default
All tests are now passing. Several tests were failing (the ones using PUT), which turned out to be because the parameters were not being sent to the server (it was using the testclient.post method, which was not sending them). I switched it to using the testclient.get method, and it is now properly sending them, but they are being sent as GET parameters (in request.GET), which is a bit awkward. As a result, I changed the `update command to use the request.REQUEST dict (searches POST and then GET) instead of request.POST. You may want to revert this change, but it seems necessary to perform these tests using the Django test client. At some point, I think this will be imperfect regards of what we do, because of Django's marginal support for PUT and DELETE.
Will Larson
2 years ago

Changed (Δ7 bytes):

raw changeset »

generic/rest_views.py (1 lines added, 1 lines removed)

tests/test_modelview/tests.py (4 lines added, 4 lines removed)

Up to file-list generic/rest_views.py:

@@ -221,7 +221,7 @@ class ModelView(BaseView):
221
221
        Update an existing resource (there is no PUT creation for now), idempotent.
222
222
        """
223
223
        Form = self.get_form(request)
224
        form = Form(request.POST, request.FILES, instance=obj)
224
        form = Form(request.REQUEST, request.FILES, instance=obj)
225
225
        if form.is_valid():
226
226
            new_obj = self.save_form(request, form)
227
227
            return responder.update_success(request, obj, new_obj, self.post_save_redirect)

Up to file-list tests/test_modelview/tests.py:

@@ -65,7 +65,7 @@ class ModelViewTest(TestCase):
65
65
        self.assertEqual(Article.objects.count(), 2)
66
66
        a2 = Article.objects.all()[1]
67
67
        response = self.client.login(username='david', password='baz')
68
        response = self.client.post('/auth-articles/%s/' % a2.slug, {'name': "Yet another article",
68
        response = self.client.get('/auth-articles/%s/' % a2.slug, {'name': "Yet another article",
69
69
                                                                     'slug': "yet-another-article",
70
70
                                                                     'body': "some other text"},
71
71
                                                                     REQUEST_METHOD='PUT')
@@ -73,7 +73,7 @@ class ModelViewTest(TestCase):
73
73
        a2 = Article.objects.all()[1]
74
74
        self.assertEqual(a2.name, u'Another article')
75
75
        response = self.client.login(username='will', password='baz')
76
        response = self.client.post('/auth-articles/%s/' % a2.slug, {'name': "Yet another article again",
76
        response = self.client.get('/auth-articles/%s/' % a2.slug, {'name': "Yet another article again",
77
77
                                                                     'slug': "yet-another-article-again",
78
78
                                                                     'body': "some other text"},
79
79
                                                                     REQUEST_METHOD='PUT')
@@ -114,11 +114,11 @@ class ModelViewTest(TestCase):
114
114
115
115
    def test_html_responder_update(self):
116
116
        a = Article.objects.all()[0]
117
        response = self.client.post('/rw-articles/%s/' % a.slug,
117
        response = self.client.get('/rw-articles/%s/' % a.slug,
118
118
                                    {'name': "An updated article",
119
119
                                     'slug': "an-article",
120
120
                                     'body': "some text"},
121
                                     REQUEST_METHOD='PUT')
121
                                    REQUEST_METHOD='PUT')
122
122
        self.assertEqual(response.status_code, 302)
123
123
        self.assertEqual(Article.objects.count(), 1)
124
124
        self.assertEqual(Article.objects.all()[0].name, u'An updated article')