Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 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 3 years ago.
14543.patch (3.8 KB) - added by sayane 3 years ago.
New patch, removed Auth app depency
14543.2.patch (1.5 KB) - added by crayz_train 3 years ago.
diff works against r15821
14543.3.patch (3.3 KB) - added by crayz_train 3 years ago.
works against r15864

Download all attachments as: .zip

Change History (22)

Changed 3 years ago by sayane

comment:1 Changed 3 years ago by anonymous

  • milestone set to 1.3
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 3 years ago by dmoisset

  • Owner changed from nobody to dmoisset

triaging...

comment:3 Changed 3 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 3 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 3 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 3 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 3 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 3 years ago by sayane

New patch, removed Auth app depency

comment:8 Changed 3 years ago by gabrielhurley

  • Triage Stage changed from Unreviewed to Accepted

comment:9 in reply to: ↑ description Changed 3 years ago by paulegan

  • 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 3 years ago by russellm

  • 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 3 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 3 years ago by crayz_train

diff works against r15821

Changed 3 years ago by crayz_train

works against r15864

comment:12 Changed 3 years ago by crayz_train

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:13 Changed 3 years ago by crayz_train

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:14 Changed 3 years ago by crayz_train

oops - I'm a noob to django-trac

comment:15 Changed 3 years ago by andrewgodwin

  • Owner changed from dmoisset to crayz_train
  • Status changed from reopened to new
  • Triage Stage changed from Accepted to Ready for checkin

comment:16 Changed 3 years ago by gabrielhurley

  • Component changed from Contrib apps to contrib.contenttypes

comment:17 Changed 3 years ago by SmileyChris

  • Resolution set to fixed
  • Status changed from new to closed

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 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.