Set is_admin of user based on ADMINS list.

This commit is contained in:
Arik Fraimovich
2014-03-03 11:53:49 +02:00
parent dd4c3f152a
commit af1b1c0edb
2 changed files with 22 additions and 5 deletions

View File

@@ -34,13 +34,29 @@ class TestCreateAndLoginUser(BaseTestCase):
login_user_mock.assert_called_once_with(user, remember=True)
def test_creates_vaild_new_user(self):
user = ObjectDict({'email': 'test@example.com', 'name': 'Test User'})
openid_user = ObjectDict({'email': 'test@example.com', 'name': 'Test User'})
with patch.object(settings, 'GOOGLE_APPS_DOMAIN', 'example.com'), patch('redash.authentication.login_user') as login_user_mock:
create_and_login_user(None, user)
with patch.multiple(settings, GOOGLE_APPS_DOMAIN='example.com', ADMINS=['admin@example.com']), \
patch('redash.authentication.login_user') as login_user_mock:
create_and_login_user(None, openid_user)
self.assertEqual(models.User.select().count(), 1)
self.assertTrue(login_user_mock.called)
user = models.User.get(models.User.email == openid_user.email)
self.assertFalse(user.is_admin)
def test_creates_vaild_new_user_and_sets_is_admin(self):
openid_user = ObjectDict({'email': 'admin@example.com', 'name': 'Test User'})
with patch.multiple(settings, GOOGLE_APPS_DOMAIN='example.com', ADMINS=['admin@example.com']), \
patch('redash.authentication.login_user') as login_user_mock:
create_and_login_user(None, openid_user)
self.assertTrue(login_user_mock.called)
user = models.User.get(models.User.email == openid_user.email)
self.assertTrue(user.is_admin)
def test_ignores_invliad_user(self):
user = ObjectDict({'email': 'test@whatever.com'})