def populate_user(self): """Populates the current authenticated user from session state.""" current_app.logger.info( "Method called, getting session user from session api") response = SessionAPIService.get_session_state( self.session_key, Session.session_user_key) if response is not None: current_app.logger.info("User data returned from session state") self.user = User.from_dict(response)
def test_get_session_state_none_on_exception(self): with app.test_request_context(): g.requests = MagicMock() g.trace_id = '123' response = MagicMock() response.status_code = 500 response.json.return_value = {"test": '123'} g.requests.get.side_effect = Exception('test exception') result = SessionAPIService.get_session_state('abc', 'def') self.assertIsNone(result)
def test_get_session_state_successful(self): with app.test_request_context(): g.requests = MagicMock() g.trace_id = '123' response = MagicMock() response.status_code = 200 response.json.return_value = {"test": '123'} g.requests.get.return_value = response result = SessionAPIService.get_session_state('abc', 'def') self.assertIsNotNone(result) self.assertEqual({"test": '123'}, result)
def populate_2fa_state(self): response = SessionAPIService.get_session_state( self.session_key, Session.session_2fa_state_key) if response is not None: if 'two_factor_authentication_passed' in response: self.two_factor_authentication_passed = response[ 'two_factor_authentication_passed'] else: self.two_factor_authentication_passed = False if 'two_factor_authentication_code' in response: self.two_factor_authentication_code = response[ 'two_factor_authentication_code'] if 'two_factor_authentication_redirect_url' in response: self.two_factor_authentication_redirect_url = response[ 'two_factor_authentication_redirect_url'] if 'two_factor_authentication_generation_time' in response: self.two_factor_authentication_generation_time = response[ 'two_factor_authentication_generation_time'] if 'two_factor_authentication_invalid_attempts' in response: self.two_factor_authentication_invalid_attempts = \ response['two_factor_authentication_invalid_attempts']
def populate_state(self): """Populates the add charge from session state.""" current_app.logger.info( "Method called, getting session state from session api") response = SessionAPIService.get_session_state( self.session_key, Session.session_state_key) if response is not None: current_app.logger.info("Non-empty session state contents") if 'add_charge_state' in response: current_app.logger.info("add_charge_state in session state") self.add_charge_state = LocalLandChargeItem.from_json( response['add_charge_state']) if 'add_lon_charge_state' in response: current_app.logger.info( "add_lon_charge_state in session state") self.add_lon_charge_state = LightObstructionNoticeItem.from_json( response['add_lon_charge_state']) if 'last_created_charge' in response: current_app.logger.info("last_created_charge in session state") self.last_created_charge = LastCreatedCharge.from_dict( response['last_created_charge']) if 'statutory_provision_list' in response: current_app.logger.info( "statutory_provision_list in session state") self.statutory_provision_list = response[ 'statutory_provision_list'] if 'edited_fields' in response: current_app.logger.info("edited_fields in session state") self.edited_fields = response['edited_fields'] if 'llc1_state' in response: current_app.logger.info("llc1_state in session state") self.llc1_state = LLC1Search.from_json(response['llc1_state']) if 'redirect_route' in response: current_app.logger.info('redirect_route in session state') self.redirect_route = response['redirect_route'] if 'search_extent' in response: current_app.logger.info('search_extent in session state') self.search_extent = response['search_extent'] if 'filenames' in response: current_app.logger.info('filenames in session state') self.filenames = response['filenames'] if 'previously_selected_address' in response: current_app.logger.info( 'previously_selected_address in session state') self.previously_selected_address = response[ 'previously_selected_address'] if 'adding_charge_for_other_authority' in response: current_app.logger.info( 'adding_charge_for_other_authority in session state') self.adding_charge_for_other_authority = response[ 'adding_charge_for_other_authority'] if 'submit_token' in response: current_app.logger.info('submit token in session state') self.submit_token = response['submit_token'] if 'upload_shapefile_processed' in response: current_app.logger.info( 'upload_shapefile_processed in session state') self.upload_shapefile_processed = response[ 'upload_shapefile_processed'] if 'category_details' in response: self.category_details = Category.from_dict( response['category_details']) if 'category_confirmation' in response: self.category_confirmation = response['category_confirmation'] if 'charge_added_outside_users_authority' in response: self.charge_added_outside_users_authority = response[ 'charge_added_outside_users_authority'] if 'other_authority_update_permission' in response: self.other_authority_update_permission = response[ 'other_authority_update_permission'] if 'other_authority_cancel_permission' in response: self.other_authority_cancel_permission = response[ 'other_authority_cancel_permission'] if 'source_information' in response: self.source_information = response['source_information'] if 'source_information_id' in response: self.source_information_id = response['source_information_id'] if 'send_payment_link_info' in response: current_app.logger.info( "send_payment_link_info in session state") self.send_payment_link_info = PaymentLink.from_json( response['send_payment_link_info']) if 'payment_info' in response: current_app.logger.info("payment_info in session state") self.payment_info = PaymentInfo.from_json( response['payment_info']) if 'search_details' in response: self.search_details = SearchDetails.from_json( response['search_details'])