def test_user_login_missing_username(self): req, res, abort = mocks_service.generate_controller_args_mocks() req.json = {'password': config.admin_user['password']} try: user_controllers.user_login_controller(req, res, abort) except: pass finally: res.assert_not_called() abort.assert_called_once_with(400)
def test_user_login(self): req, res, abort = mocks_service.generate_controller_args_mocks() req.json = { 'username': config.admin_user['username'], 'password': config.admin_user['password'] } user_controllers.user_login_controller(req, res, abort) abort.assert_not_called() res.assert_called_once() res_body, res_status_code = mocks_service.get_parsed_res_call_args( res.call_args) self.assertEqual(res_body['success'], True) self.assertEqual(res_body['msg'], user_consts.AUTH_SUCCESS_MSG) self.assertEqual(res_status_code, 200)
def test_user_login_incorrect_password(self): req, res, abort = mocks_service.generate_controller_args_mocks() req.json = { 'username': config.admin_user['username'], 'password': '******' } user_controllers.user_login_controller(req, res, abort) abort.assert_not_called() res.assert_called_once() res_body, res_status_code = mocks_service.get_parsed_res_call_args( res.call_args) self.assertEqual(res_body['success'], False) self.assertEqual(res_body['msg'], user_consts.AUTH_FAILED_PASSWORD_MSG) self.assertEqual(res_status_code, 401)
def user_login(): return user_controllers.user_login_controller(req, res, abort)