def test_api_role(self): with self.app.test_request_context() as request_ctx: from croplands_api.views.api.processors import api_roles def api_roles_wrapper(role): """ Help for roles in test :param role: :return: """ api_roles(role)() # should not be authorized for any of these since current user is none self.assertRaises(Unauthorized, api_roles_wrapper, 'registered') self.assertRaises(Unauthorized, api_roles_wrapper, 'partner') self.assertRaises(Unauthorized, api_roles_wrapper, 'team') self.assertRaises(Unauthorized, api_roles_wrapper, 'admin') self.assertRaises(Unauthorized, api_roles_wrapper, ['registered', 'partner', 'team', 'admin']) request_ctx.current_user = user = User( **{ 'first': 'Justin', 'last': 'Poehnelt', 'organization': 'USGS', 'password': '******', 'email': '*****@*****.**' }) user.role = 'registered' self.assertEqual(api_roles_wrapper('registered'), None) self.assertRaises(Unauthorized, api_roles_wrapper, ['partner', 'team', 'admin']) user.role = 'partner' self.assertEqual(api_roles_wrapper('partner'), None) self.assertRaises(Unauthorized, api_roles_wrapper, ['registered', 'team', 'admin']) user.role = 'team' self.assertEqual(api_roles_wrapper('team'), None) self.assertRaises(Unauthorized, api_roles_wrapper, ['partner', 'registered', 'admin']) user.role = 'admin' self.assertEqual(api_roles_wrapper('admin'), None) self.assertRaises(Unauthorized, api_roles_wrapper, ['partner', 'team', 'registered'])
def test_user_email_case_insensitivity(self): """ Emails are by nature case insensitive. This test checks that the user model correctly handles this specification. :return: """ with self.app.app_context(): data = { 'email': '*****@*****.**', 'password': '******', 'first': 'First', 'last': 'Last' } user = User(**data) assert (user.email.islower()) user = User.create(**data) assert (user.email.islower()) user = User.from_email(data['email']) self.assertIsNotNone(user) user = User.from_login(data['email'], data['password']) self.assertIsNotNone(user)