Skip to content

Commit

Permalink
Quick Fix Social Auth Module Path.
Browse files Browse the repository at this point in the history
This is a quick fix for social auth module path.

Signed-off-by: David Brown <dmlb2000@gmail.com>
  • Loading branch information
dmlb2000 committed Nov 24, 2020
1 parent ff60e09 commit a40b896
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions pacifica/auth/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def session_commit():
cherrypy.session.save()


def check_sa_module_class(sa_module, sa_class):
def check_sa_module_class(sa_path, sa_module, sa_class):
"""Check the combination of module and class."""
try:
sa_module = importlib.import_module('social_core.backends.{}'.format(sa_module))
sa_module = importlib.import_module('{}.{}'.format(sa_path, sa_module))
except ImportError as ex:
raise ValueError('Module {} is not a social core backend'.format(sa_module)) from ex
if not getattr(sa_module, sa_class, None):
Expand Down Expand Up @@ -74,6 +74,7 @@ def load_user():
'SOCIAL_AUTH_{}'.format(key.upper()): configparser.get('social_settings', key)
})
check_sa_module_class(
configparser.get('cherrypy', 'social_path'),
configparser.get('cherrypy', 'social_module'),
configparser.get('cherrypy', 'social_class')
)
Expand Down
10 changes: 7 additions & 3 deletions tests/check_sa_module_class_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ class SAModuleClassTest(TestCase):

def test_happy(self):
"""Test the happy path."""
self.assertEqual(check_sa_module_class('github', 'GithubOAuth2'), None, 'Happy path must not return anything')
self.assertEqual(
check_sa_module_class('social_core.backends', 'github', 'GithubOAuth2'),
None,
'Happy path must not return anything'
)

def test_module_error(self):
"""Test a bad module name."""
with self.assertRaises(ValueError):
check_sa_module_class('module_not_there', 'blah')
check_sa_module_class('social_core.backends', 'module_not_there', 'blah')
with self.assertRaises(ValueError):
check_sa_module_class('github', 'class_not_there')
check_sa_module_class('social_core.backends', 'github', 'class_not_there')

0 comments on commit a40b896

Please sign in to comment.