Repository: encode/django-rest-framework

Issue:
Tests should not rely on error messages being in English
djangorestframework.tests.validators.TestFormValidation.test_modelform_validation_failed_due_to_field_error_returns_appropriate_message
djangorestframework.tests.validators.TestFormValidation.test_modelform_validation_failed_due_to_multiple_errors_returns_appropriate_message
djangorestframework.tests.validators.TestFormValidation.test_modelform_validation_failed_due_to_no_content_returns_appropriate_message
djangorestframework.tests.validators.TestFormValidation.test_validation_failed_due_to_field_error_returns_appropriate_message
djangorestframework.tests.validators.TestFormValidation.test_validation_failed_due_to_multiple_errors_returns_appropriate_message
djangorestframework.tests.validators.TestFormValidation.test_validation_failed_due_to_no_content_returns_appropriate_message

Traceback (most recent call last):
  File "/var/lib/jenkins/jobs/S3G/workspace/venv/lib/python2.6/site-packages/djangorestframework/tests/validators.py", line 263, in test_modelform_validation_failed_due_to_field_error_returns_appropriate_message
    self.validation_failed_due_to_field_error_returns_appropriate_message(validator)
  File "/var/lib/jenkins/jobs/S3G/workspace/venv/lib/python2.6/site-packages/djangorestframework/tests/validators.py", line 168, in validation_failed_due_to_field_error_returns_appropriate_message
    self.assertEqual(exc.response.raw_content, {'field_errors': {'qwerty': ['This field is required.']}})
AssertionError: {u'field_errors': {'qwerty': [u'Ce champ est obligatoire.']}} != {'field_errors': {'qwerty': ['This field is required.']}}
- {u'field_errors': {'qwerty': [u'Ce champ est obligatoire.']}}
- {'field_errors': {'qwerty': ['This field is required.']}}

Please pardon my French ;)



Discussion:
I think the deal here is that all test cases inside REST framework ought to inherit from a single base test case which ensures that any test settings are setup appropriately.

Any pull requests towards this aim would be much appreciated.

Same root cause as #185.

In the meantime I guess that the fix would be to make sure your test settings are appropriate for testing REST framework.

Note that even eg. some Django contrib apps include similar tests-not-fully-sandboxed issues, so this is a bit of a awkward area.


Resolving patch:
diff --git a/rest_framework/runtests/runtests.py b/rest_framework/runtests/runtests.py
--- a/rest_framework/runtests/runtests.py
+++ b/rest_framework/runtests/runtests.py
@@ -32,7 +32,7 @@ def main():
     else:
         print usage()
         sys.exit(1)
-    failures = test_runner.run_tests(['rest_framework' + test_case])
+    failures = test_runner.run_tests(['tests' + test_case])
 
     sys.exit(failures)
 
diff --git a/rest_framework/runtests/settings.py b/rest_framework/runtests/settings.py
--- a/rest_framework/runtests/settings.py
+++ b/rest_framework/runtests/settings.py
@@ -91,6 +91,7 @@
     # 'django.contrib.admindocs',
     'rest_framework',
     'rest_framework.authtoken',
+    'rest_framework.tests'
 )
 
 STATIC_URL = '/static/'
@@ -100,14 +101,6 @@
 if django.VERSION < (1, 3):
     INSTALLED_APPS += ('staticfiles',)
 
-# OAuth support is optional, so we only test oauth if it's installed.
-try:
-    import oauth_provider
-except ImportError:
-    pass
-else:
-    INSTALLED_APPS += ('oauth_provider',)
-
 # If we're running on the Jenkins server we want to archive the coverage reports as XML.
 import os
 if os.environ.get('HUDSON_URL', None):


Test patch:
diff --git a/rest_framework/tests/__init__.py b/rest_framework/tests/__init__.py
--- a/rest_framework/tests/__init__.py
+++ b/rest_framework/tests/__init__.py
@@ -1,13 +0,0 @@
-"""
-Force import of all modules in this package in order to get the standard test
-runner to pick up the tests.  Yowzers.
-"""
-import os
-
-modules = [filename.rsplit('.', 1)[0]
-           for filename in os.listdir(os.path.dirname(__file__))
-           if filename.endswith('.py') and not filename.startswith('_')]
-__test__ = dict()
-
-for module in modules:
-    exec("from rest_framework.tests.%s import *" % module)
diff --git a/rest_framework/tests/models.py b/rest_framework/tests/models.py
--- a/rest_framework/tests/models.py
+++ b/rest_framework/tests/models.py
@@ -40,7 +40,7 @@ class RESTFrameworkModel(models.Model):
     Base for test models that sets app_label, so they play nicely.
     """
     class Meta:
-        app_label = 'rest_framework'
+        app_label = 'tests'
         abstract = True
 
 
diff --git a/rest_framework/tests/tests.py b/rest_framework/tests/tests.py
new file mode 100644
--- /dev/null
+++ b/rest_framework/tests/tests.py
@@ -0,0 +1,13 @@
+"""
+Force import of all modules in this package in order to get the standard test
+runner to pick up the tests.  Yowzers.
+"""
+import os
+
+modules = [filename.rsplit('.', 1)[0]
+           for filename in os.listdir(os.path.dirname(__file__))
+           if filename.endswith('.py') and not filename.startswith('_')]
+__test__ = dict()
+
+for module in modules:
+    exec("from rest_framework.tests.%s import *" % module)