Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing Django allauth

I am trying to test my app but not sure how to configure the django-allauth in the test environment. I am getting:

ImproperlyConfigured: No Facebook app configured: please add a SocialApp using the Django admin

My approach so far is to instantiate app objects inside tests.py with actual Facebook app parameters, an app which functions correctly locally in the browser:

from allauth.socialaccount.models import SocialApp

apper = SocialApp.objects.create(provider=u'facebook', 
    name=u'fb1', client_id=u'7874132722290502',
    secret=u'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
apper.sites.create(domain='localhost:8000', name='creyu.org')

How can I get these tests running? Thanks

like image 837
KindOfGuy Avatar asked Jul 22 '14 15:07

KindOfGuy


People also ask

How do I test my Django app?

The preferred way to write tests in Django is using the unittest module built-in to the Python standard library. This is covered in detail in the Writing and running tests document. You can also use any other Python test framework; Django provides an API and tools for that kind of integration.

What is Allauth in Django?

django-allauth is an integrated set of Django applications dealing with account authentication, registration, management, and third-party (social) account authentication. It is one of the most popular authentication modules due to its ability to handle both local and social logins.

How do I run a TestCase in Django?

Open /catalog/tests/test_models.py.TestCase , as shown: from django. test import TestCase # Create your tests here. Often you will add a test class for each model/view/form you want to test, with individual methods for testing specific functionality.


1 Answers

Where inside tests.py do you instantiate this app object? If it's inside the setUpModule() method, there shouldn't be a problem.

Personally, I would create a fixture init_facebook_app.json with the relevant information and then inside tests.py (before the test cases) define:

from django.core.management import call_command    

def setUpModule():
    call_command('loaddata', 'init_facebook_app.json', verbosity=0)

This ensures that the data in the fixture are loaded before the tests are run, and that they are loaded only once, i.e. not before each test. See this for reference regarding call_command.

Lastly, posting your Facebook app secret key anywhere on the internet is not a good idea - I would reset it if I were you.

like image 136
kreld Avatar answered Oct 09 '22 09:10

kreld