Opened 6 years ago

Closed 6 years ago

Last modified 5 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: master
Severity: Keywords:
Cc: paulegan@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

One of tests uses Auth app without checking, if it's installed.

Attachments (4)

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

Download all attachments as: .zip

Change History (22)

Changed 6 years ago by Sayane

Attachment: patch.diff added

comment:1 Changed 6 years ago by anonymous

milestone: 1.3

comment:2 Changed 6 years ago by dmoisset

Owner: changed from nobody to dmoisset

triaging...

comment:3 Changed 6 years ago by dmoisset

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 Changed 6 years ago by anonymous

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 Changed 6 years ago by dmedvinsky

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 Changed 6 years ago by Sayane

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 Changed 6 years ago by dmedvinsky

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.

Changed 6 years ago by Sayane

Attachment: 14543.patch added

New patch, removed Auth app depency

comment:8 Changed 6 years ago by Gabriel Hurley

Triage Stage: UnreviewedAccepted

comment:9 in reply to:  description Changed 6 years ago by Paul Egan

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 Changed 6 years ago by Russell Keith-Magee

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 Changed 6 years ago by crayz_train

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.

Changed 6 years ago by crayz_train

Attachment: 14543.2.patch added

diff works against r15821

Changed 6 years ago by crayz_train

Attachment: 14543.3.patch added

works against r15864

comment:12 Changed 6 years ago by crayz_train

Resolution: fixed
Status: newclosed

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

comment:13 Changed 6 years ago by crayz_train

Resolution: fixed
Status: closedreopened

comment:14 Changed 6 years ago by crayz_train

oops - I'm a noob to django-trac

comment:15 Changed 6 years ago by Andrew Godwin

Owner: changed from dmoisset to crayz_train
Status: reopenednew
Triage Stage: AcceptedReady for checkin

comment:16 Changed 6 years ago by Gabriel Hurley

Component: Contrib appscontrib.contenttypes

comment:17 Changed 6 years ago by Chris Beaven

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 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

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