kumar303 / hawkrest

Hawk HTTP Authorization for Django Rest Framework
BSD 3-Clause "New" or "Revised" License
19 stars 8 forks source link

Add support for Django 1.9 #21

Closed edmorley closed 8 years ago

edmorley commented 8 years ago

20 will shortly add Django 1.9 to the Travis run, but marked as allowed to fail, since the tests are currently failing, eg:

https://travis-ci.org/kumar303/hawkrest/jobs/101117531

py27-django1.9-drf3.3 runtests: commands[0] | /home/travis/build/kumar303/hawkrest/.tox/py27-django1.9-drf3.3/bin/python runtests.py

nosetests --logging-clear-handlers --with-nicedots --verbosity=1

Traceback (most recent call last):
  File "runtests.py", line 19, in <module>
    main()
  File "runtests.py", line 15, in main
    failures = test_runner.run_tests(sys.argv[1:])
  File "/home/travis/build/kumar303/hawkrest/.tox/py27-django1.9-drf3.3/lib/python2.7/site-packages/django_nose/runner.py", line 403, in run_tests
    result = self.run_suite(nose_argv)
  File "/home/travis/build/kumar303/hawkrest/.tox/py27-django1.9-drf3.3/lib/python2.7/site-packages/django_nose/runner.py", line 329, in run_suite
    django.setup()
  File "/home/travis/build/kumar303/hawkrest/.tox/py27-django1.9-drf3.3/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/travis/build/kumar303/hawkrest/.tox/py27-django1.9-drf3.3/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/home/travis/build/kumar303/hawkrest/.tox/py27-django1.9-drf3.3/lib/python2.7/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/opt/python/2.7.9/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/travis/build/kumar303/hawkrest/hawkrest/__init__.py", line 17, in <module>
    from rest_framework.authentication import BaseAuthentication
  File "/home/travis/build/kumar303/hawkrest/.tox/py27-django1.9-drf3.3/lib/python2.7/site-packages/rest_framework/authentication.py", line 13, in <module>
    from rest_framework.authtoken.models import Token
  File "/home/travis/build/kumar303/hawkrest/.tox/py27-django1.9-drf3.3/lib/python2.7/site-packages/rest_framework/authtoken/models.py", line 16, in <module>
    class Token(models.Model):
  File "/home/travis/build/kumar303/hawkrest/.tox/py27-django1.9-drf3.3/lib/python2.7/site-packages/django/db/models/base.py", line 94, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/home/travis/build/kumar303/hawkrest/.tox/py27-django1.9-drf3.3/lib/python2.7/site-packages/django/apps/registry.py", line 239, in get_containing_app_config
    self.check_apps_ready()
  File "/home/travis/build/kumar303/hawkrest/.tox/py27-django1.9-drf3.3/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

This appears to be due to Django 1.9 now not allowing models to be imported in __init__.py, per: https://docs.djangoproject.com/en/1.7/internals/deprecation/#deprecation-removed-in-1-9

All models will need to be defined inside an installed application or declare an explicit app_label. Furthermore, it won’t be possible to import them before their application is loaded. In particular, it won’t be possible to import models inside the root package of their application.

However due to a bug, the deprecation warning for this wasn't shown when using previous versions of Django, otherwise the failure mode would have been more clear: https://code.djangoproject.com/ticket/25477

Whilst hawkrest doesn't have any models itself, it imports several rest_framework classes which do import some of the rest_framework's models.

Once support for Django 1.9 is added, the allow_failure lines in .travis.yml can be removed.

edmorley commented 8 years ago

So the issue above was fixed by tomchristie/django-rest-framework#3785, which is in django-rest-framework 3.3.3+.

However running the tests still fails with exceptions like:

ERROR: tests/test_authentication.py
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/Ed/.virtualenvs/hawkrest/lib/python2.7/site-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/home/Ed/.virtualenvs/hawkrest/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/home/Ed/.virtualenvs/hawkrest/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/home/Ed/src/hawkrest/tests/test_authentication.py", line 5, in <module>
    from django.contrib.auth.models import AbstractBaseUser
  File "/home/Ed/.virtualenvs/hawkrest/lib/python2.7/site-packages/django/contrib/auth/models.py", line 6, in <module>
    from django.contrib.contenttypes.models import ContentType
  File "/home/Ed/.virtualenvs/hawkrest/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 161, in <module>
    class ContentType(models.Model):
  File "/home/Ed/.virtualenvs/hawkrest/lib/python2.7/site-packages/django/db/models/base.py", line 102, in __new__
    "INSTALLED_APPS." % (module, name)
RuntimeError: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

And then after adding django.contrib.contenttypes to INSTALLED_APPS:

...
RuntimeError: Model class django.contrib.auth.models.Permission doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

And then after also adding django.contrib.auth to INSTALLED_APPS:

FAIL: tests/test_authentication.py:TestHawkAuthenticatedUser.test_method_compliance
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/Ed/src/hawkrest/tests/test_authentication.py", line 208, in test_method_compliance
    .format(name))
AssertionError: HawkAuthenticatedUser is missing method: save