Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#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)

patch.diff (1.3 KB ) - added by Sayane 14 years ago.
14543.patch (3.8 KB ) - added by Sayane 14 years ago.
New patch, removed Auth app depency
14543.2.patch (1.5 KB ) - added by crayz_train 14 years ago.
diff works against r15821
14543.3.patch (3.3 KB ) - added by crayz_train 14 years ago.
works against r15864

Download all attachments as: .zip

Change History (22)

by Sayane, 14 years ago

Attachment: patch.diff added

comment:1 by anonymous, 14 years ago

milestone: 1.3

comment:2 by Daniel F Moisset, 14 years ago

Owner: changed from nobody to Daniel F Moisset

triaging...

comment:3 by Daniel F Moisset, 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 anonymous, 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 dmedvinsky, 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 Sayane, 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 dmedvinsky, 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.

by Sayane, 14 years ago

Attachment: 14543.patch added

New patch, removed Auth app depency

comment:8 by Gabriel Hurley, 14 years ago

Triage Stage: UnreviewedAccepted

in reply to:  description comment:9 by Paul Egan, 14 years ago

Cc: paulegan@… 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 Russell Keith-Magee, 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 crayz_train, 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.

by crayz_train, 14 years ago

Attachment: 14543.2.patch added

diff works against r15821

by crayz_train, 14 years ago

Attachment: 14543.3.patch added

works against r15864

comment:12 by crayz_train, 14 years ago

Resolution: fixed
Status: newclosed

I got home, reread the last comment from russellm, and added a negative test.

comment:13 by crayz_train, 14 years ago

Resolution: fixed
Status: closedreopened

comment:14 by crayz_train, 14 years ago

oops - I'm a noob to django-trac

comment:15 by Andrew Godwin, 14 years ago

Owner: changed from Daniel F Moisset to crayz_train
Status: reopenednew
Triage Stage: AcceptedReady for checkin

comment:16 by Gabriel Hurley, 14 years ago

Component: Contrib appscontrib.contenttypes

comment:17 by Chris Beaven, 14 years ago

Resolution: fixed
Status: newclosed

In [16101]:

Fixes #14543 -- ContentTypes tests failing if auth app is not installed. Thanks for the work on the patch, sayane and crayz_train.

comment:18 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top