#14543 closed (fixed)
ContentTypes tests fails if auth app is not installed
Reported by: | Sayane | Owned by: | crayz_train |
---|---|---|---|
Component: | contrib.contenttypes | Version: | dev |
Severity: | Keywords: | ||
Cc: | paulegan@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
One of tests uses Auth app without checking, if it's installed.
Attachments (4)
Change History (22)
by , 14 years ago
Attachment: | patch.diff added |
---|
comment:1 by , 14 years ago
milestone: | → 1.3 |
---|
comment:2 by , 14 years ago
Owner: | changed from | to
---|
comment:3 by , 14 years ago
sayane, I ran tests with INSTALLED_APPS=()
and everything went ok. Can you describe what are you doing to run the content types tests and making this fail?
comment:4 by , 14 years ago
Well, tests for django.contrib.contenttypes won't run, if you don't have this app in INSTALLED_APPS, right? One of tests is using User model to create new record. Obviously, if auth app is not installed, it will fail.
====================================================================== ERROR: test_shortcut_view (django.contrib.contenttypes.tests.ContentTypesTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/sayane/Programowanie/virtenv/dj13/lib/python2.6/site-packages/django/contrib/contenttypes/tests.py", line 63, in test_shortcut_view obj = User.objects.create(username="john") File "/home/sayane/Programowanie/virtenv/dj13/lib/python2.6/site-packages/django/db/models/manager.py", line 138, in create return self.get_query_set().create(**kwargs) File "/home/sayane/Programowanie/virtenv/dj13/lib/python2.6/site-packages/django/db/models/query.py", line 353, in create obj.save(force_insert=True, using=self.db) File "/home/sayane/Programowanie/virtenv/dj13/lib/python2.6/site-packages/django/db/models/base.py", line 454, in save self.save_base(using=using, force_insert=force_insert, force_update=force_update) File "/home/sayane/Programowanie/virtenv/dj13/lib/python2.6/site-packages/django/db/models/base.py", line 547, in save_base result = manager._insert(values, return_id=update_pk, using=using) File "/home/sayane/Programowanie/virtenv/dj13/lib/python2.6/site-packages/django/db/models/manager.py", line 195, in _insert return insert_query(self.model, values, **kwargs) File "/home/sayane/Programowanie/virtenv/dj13/lib/python2.6/site-packages/django/db/models/query.py", line 1401, in insert_query return query.get_compiler(using=using).execute_sql(return_id) File "/home/sayane/Programowanie/virtenv/dj13/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql cursor = super(SQLInsertCompiler, self).execute_sql(None) File "/home/sayane/Programowanie/virtenv/dj13/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 730, in execute_sql cursor.execute(sql, params) File "/home/sayane/Programowanie/virtenv/dj13/lib/python2.6/site-packages/django/db/backends/util.py", line 18, in execute return self.cursor.execute(sql, params) File "/home/sayane/Programowanie/virtenv/dj13/lib/python2.6/site-packages/django/db/backends/sqlite3/base.py", line 221, in execute return Database.Cursor.execute(self, query, params) DatabaseError: no such table: auth_user
comment:5 by , 14 years ago
I don't think that existing patch is correct. ContentType framework should work without Auth framework, and the shortcut view should be tested independently from presence of Auth.
comment:6 by , 14 years ago
Do you have any idea how to test it? It needs model synced with db, with get_absolute_url
method (ContentType model doesn't have this method). Creating new test in django/tests with dedicated model doesn't make any sense, because auth app is always installed when using django/tests/runtests.py, so test_shortcut_view will be executed properly.
comment:7 by , 14 years ago
Still, I don't think there should be a link between these two apps, because they are independent per se. Creating a dummy model for the test seems a better solution for me. But that's only mine opinion. I think we need someone else to vote.
comment:8 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:9 by , 14 years ago
Cc: | added |
---|
Looks like this issue made it into 1.2.4 as well. It's real easy to recreate:
django-admin.py startproject djangotest cd djangotest sed -e '/ENGINE/s/backends./&sqlite3/' -e '/contrib.auth/d' -i settings.py python manage.py test
The attached patch - or any other which removes test_shortcut_view - works fine.
comment:10 by , 14 years ago
Patch needs improvement: | set |
---|
I'm not convinced the approach taken by the patch is correct. auth is being used here because we need a model on which to invoke shortcut(), and auth is a generally reliable option.
However, auth isn't always available, so we just need to find a substitute. Turns out you can actually define a model in tests.py, and that model will be available during testing, but not in production. This avoids the need to create a second test module for contenttype tests. It also provides an opportunity to test aspects of shortcut() that aren't currently tested -- testing models that *don't* have get_absolute_url defined.
comment:11 by , 14 years ago
Patch needs improvement: | unset |
---|
This patch implements a bogus User model for the test_shortcut_view to use during the test run. Done @ PyCon 2011.
comment:12 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I got home, reread the last comment from russellm, and added a negative test.
comment:13 by , 14 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:15 by , 14 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
Triage Stage: | Accepted → Ready for checkin |
comment:16 by , 14 years ago
Component: | Contrib apps → contrib.contenttypes |
---|
triaging...