Merge lp:~rvb/maas/dj16-bug-1257269 into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 1758
Proposed branch: lp:~rvb/maas/dj16-bug-1257269
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 41 lines (+7/-4)
2 files modified
src/apiclient/testing/django.py (+5/-1)
src/maasserver/tests/test_middleware.py (+2/-3)
To merge this branch: bzr merge lp:~rvb/maas/dj16-bug-1257269
Reviewer Review Type Date Requested Status
Julian Edwards (community) Approve
Review via email: mp+197513@code.launchpad.net

Commit message

Define DJANGO_SETTINGS_MODULE before using django.core.handlers.wsgi.WSGIRequest.

Description of the change

The change to test_returns_ValidationError_message_dict_as_json is a drive-by fix.

To post a comment you must log in.
Revision history for this message
Julian Edwards (julian-edwards) wrote :

 review: approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/apiclient/testing/django.py'
2--- src/apiclient/testing/django.py 2013-10-07 09:12:40 +0000
3+++ src/apiclient/testing/django.py 2013-12-03 13:00:42 +0000
4@@ -15,9 +15,9 @@
5 __all__ = []
6
7 from io import BytesIO
8+import os
9
10 from django.core.files.uploadhandler import MemoryFileUploadHandler
11-from django.core.handlers.wsgi import WSGIRequest
12 from django.http.multipartparser import MultiPartParser
13 from maasserver.utils import ignore_unused
14
15@@ -73,6 +73,10 @@
16 environ['REQUEST_METHOD'] = 'POST'
17 environ['SCRIPT_NAME'] = ''
18 environ['PATH_INFO'] = ''
19+ # Django 1.6 needs DJANGO_SETTINGS_MODULE to be defined
20+ # when importing WSGIRequest.
21+ os.environ['DJANGO_SETTINGS_MODULE'] = 'maas.development'
22+ from django.core.handlers.wsgi import WSGIRequest
23 request = WSGIRequest(environ)
24 translate_mime(request)
25 return request.data
26
27=== modified file 'src/maasserver/tests/test_middleware.py'
28--- src/maasserver/tests/test_middleware.py 2013-10-11 09:08:34 +0000
29+++ src/maasserver/tests/test_middleware.py 2013-12-03 13:00:42 +0000
30@@ -148,9 +148,8 @@
31 (response.status_code, response.content))
32
33 def test_returns_ValidationError_message_dict_as_json(self):
34- exception = ValidationError(factory.getRandomString())
35- exception_dict = {'hostname': 'invalid'}
36- setattr(exception, 'message_dict', exception_dict)
37+ exception_dict = {'hostname': ['invalid']}
38+ exception = ValidationError(exception_dict)
39 response = self.process_exception(exception)
40 self.assertEqual(exception_dict, json.loads(response.content))
41 self.assertIn('application/json', response['Content-Type'])