silentsokolov / django-admin-rangefilter

A Django app that lets you filter data by date range and numeric range in the admin UI
MIT License
713 stars 106 forks source link

Tests do not run due to missing database relations #46

Closed mpeuss closed 4 years ago

mpeuss commented 4 years ago

When the app is included in INSTALLED_APPS tests from rangefilter/tests.py are executed but fail due to missing model relations in the database.


  File "/home/testapp/lib/python2.7/site-packages/rangefilter/tests.py", line 96, in setUp
    self.django_book = MyModel.objects.create(created_at=timezone.now())
  File "/home/testapp/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/testapp/lib/python2.7/site-packages/django/db/models/query.py", line 394, in create
    obj.save(force_insert=True, using=self.db)
  File "/home/testapp/lib/python2.7/site-packages/django/db/models/base.py", line 808, in save
    force_update=force_update, update_fields=update_fields)
  File "/home/testapp/lib/python2.7/site-packages/django/db/models/base.py", line 838, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/home/testapp/lib/python2.7/site-packages/django/db/models/base.py", line 924, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/home/testapp/lib/python2.7/site-packages/django/db/models/base.py", line 963, in _do_insert
    using=using, raw=raw)
  File "/home/testapp/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/testapp/lib/python2.7/site-packages/django/db/models/query.py", line 1079, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/home/testapp/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1112, in execute_sql
    cursor.execute(sql, params)
  File "/home/testapp/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/testapp/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/testapp/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/testapp/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
ProgrammingError: relation "rangefilter_mymodel" does not exist
LINE 1: INSERT INTO "rangefilter_mymodel" ("created_at") VALUES ('20..```
silentsokolov commented 4 years ago

How do you run tests?

For example, there is simple project with rangefilter in INSTALLED_APPS. Tests from rangefilter/tests.py are not executed.

$ python manage.py test                                                                                                                                           
System check identified no issues (0 silenced).

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
mpeuss commented 4 years ago

Thank you for your quick response. In our projects tests are executed with py.test which finds all "test" packages. However, how are these tests supposed to be working? Migrations are missing in every case.

silentsokolov commented 4 years ago

It is django magic ))

Ok, later I will see how to fix the tests in your case

silentsokolov commented 4 years ago

@mpeuss Could you test the master branch in your system?

mpeuss commented 4 years ago

It works! The tests do not run anymore since you extracted them to a new app. The final package will only include the rangefilter app and not the tests app, correct?

silentsokolov commented 4 years ago

No, the final package will include the tests app. It is common for packages of python and sometime the tests are answer for many questions

mpeuss commented 4 years ago

Ok, but nonetheless it should be working. When will you release a new version? Thanks so far for your help.

silentsokolov commented 4 years ago

Today or tomorrow.