def test_user_password_hash_fits_column(self): with self.create_storage() as storage: user = generate_user() user.password_hash = hash(user.password_hash) storage.add(user) with self.create_storage() as storage: read = storage.get_user_by_email(user.email) self.assertUser(user, read)
def test_user_authenticate_success(self): users = self.get_users_service() user = User(u'*****@*****.**', hash('pass1234'), True) self.add_user(user) request = {'email': u'*****@*****.**', 'password': u'pass1234'} user = users.authenticate(request) self.assertIsNotNone(user)
def test_user_create_existing_email(self): users = self.get_users_service() existing = User(u'*****@*****.**', hash('pass123456'), True) self.add_user(existing) request = {'email': '*****@*****.**', 'password': '******'} with self.assertRaises(ServiceException) as context: users.create_new_user(request) self.assertEquals(context.exception.status_code, 400)
def test_user_create_existing_email(self): users = self.get_users_service() existing = User(u'*****@*****.**', hash('pass123456'), True) self.add_user(existing) request = {'user_domain': 'vladimir', 'email': '*****@*****.**', 'password': '******'} with self.assertRaises(ServiceException) as context: users.create_new_user(request) self.assertEquals(context.exception.status_code, 409)
def test_user_set_subscribed_false(self): users = self.get_users_service() user = User(u'*****@*****.**', hash('pass'), True) self.add_user(user) request = {'subscribed': 'false'} users.user_set_subscribed(request, user.email) user = self.get_user(user.email) self.assertTrue(user.unsubscribed)
def test_user_authenticate_missing_password(self): users = self.get_users_service() user = User(u'*****@*****.**', hash('otherpass1234'), True) self.add_user(user) request = {'email': '*****@*****.**'} with self.assertRaises(ServiceException) as context: users.authenticate(request) self.assertEquals(context.exception.status_code, 400)
def test_user_authenticate_wrong_password(self): users = self.get_users_service() user = User(u'*****@*****.**', hash('otherpass1234'), True) self.add_user(user) request = {'email': '*****@*****.**', 'password': '******'} with self.assertRaises(ServiceException) as context: users.authenticate(request) self.assertEquals(context.exception.status_code, 400)
def test_user_authenticate_non_active(self): users = self.get_users_service() user = User(u'*****@*****.**', hash('pass1234'), active=False) user.enable_action(ActionType.ACTIVATE) self.add_user(user) request = {'email': '*****@*****.**', 'password': '******'} with self.assertRaises(ServiceException) as context: users.authenticate(request) self.assertEquals(context.exception.status_code, 403)
def test_user_authenticate_non_active(self): users = self.get_users_service() user = User(u'*****@*****.**', hash('pass1234'), active=False) user.enable_action(ActionType.ACTIVATE) self.add_user(user) request = {'email': '*****@*****.**', 'password': '******'} with self.assertRaises(ServiceException) as context: users.authenticate(request) self.assertEquals(context.exception.status_code, 400)
def test_user_authenticate_missing_password(self): users = self.get_users_service() user = User(u'*****@*****.**', hash('otherpass1234'), True) self.add_user(user) request = {'email': '*****@*****.**'} with self.assertRaises(ServiceException) as context: users.authenticate(request) exc = context.exception self.assertEquals(exc.status_code, 400) self.assertGreater(len(exc.message), 0) self.assertEquals(len(exc.parameters_errors), 1) self.assertGreater(len(exc.parameters_errors['password']), 0)
def test_not_equal_input(self): h1 = hash('some string') h2 = hash('some other string') self.assertNotEqual(h1, h2)
def test_empty(self): h = hash('non empty string') self.assertIsNotNone(h) self.assertIsNot('', h)
def generate_user(): email = unicode(create_token() + '@mail.com') user = User(email, hash('pass1234'), False) user.enable_action(ActionType.ACTIVATE) return user