[Django]-Monkey patched django auth's login, now its tests fail

5đź‘Ť

âś…

Couldn’t you simply wrap it in another view?

urls:

url(
    r'^accounts/login/$',
    'accounts.views.login',
    {"template_name":settings.LOGIN_TEMPLATE }
),

accounts.views:

from django.contrib.auth import views as auth_views   

def login(request, *args, **kwars):
    # do some stuff    
    response = auth_views.login(request, *args, **kwars)
    # more stuff
    return response

Like this, django.contrib.auth.tests will be testing the view which they were written for and you can write your own tests for the “more stuff” you need.

3đź‘Ť

I suspect this is the same underlying issue that affects django-registration in that the test runner only imports the URLs of the app being tested at the time — ie, contrib.auth and not myapp There are various tickets about things similar to this issue but a quick scan of them implies the solution is to decouple things, which isn’t going to be viable for your solution I’m guessing.

Another way around it would be to use Fabric file or Makefile to trigger a subset of tests, avoiding the two that fail because of your monkeypatch, and then add two alternate ape-friendly tests to replace them.

👤Steve Jalim

Leave a comment