def step_impl_prepare_for_tests(context, service_type): """Prepare bdd tests to run against either mock or real external services.""" step_impl_reset_db(context) with context.app.app_context(): context.bdd_helper = SecureMessagingContextHelper() if service_type.lower() == 'real': party.use_real_service() internal_user_service.use_real_service() else: party.use_mock_service() internal_user_service.use_mock_service()
def setUp(self): """setup test environment""" self.json_message = { 'msg_to': ['Tej'], 'msg_from': 'Gemma', 'subject': 'MyMessage', 'body': 'hello', 'thread_id': "", 'business_id': "7fc0e8ab-189c-4794-b8f4-9f05a1db185b", 'survey': "RSI" } self.now = datetime.now(timezone.utc) internal_user_service.use_mock_service() party.use_mock_service() self.app = create_app()
def test_close_conversation(self): """Test close conversation works""" conversation_id = self.populate_database(1) with self.app.app_context(): internal_user_service.use_mock_service() # msg_id is the same as thread id for a conversation of 1 metadata = Retriever.retrieve_conversation_metadata( conversation_id) Modifier.close_conversation(metadata, self.user_internal) metadata = Retriever.retrieve_conversation_metadata( conversation_id) self.assertTrue(metadata.is_closed) self.assertEqual(metadata.closed_by, "Selphie Tilmitt") self.assertEqual(metadata.closed_by_uuid, "ce12b958-2a5f-44f4-a6da-861e59070a31") self.assertTrue(isinstance(metadata.closed_at, datetime.datetime)) # Test that timestamp on read message is less than 3 seconds old to prove it # was only just created delta = datetime.datetime.utcnow() - metadata.closed_at self.assertTrue(delta.total_seconds() < 3)
def setUp(self): """setup test environment""" self.app = application.create_app() self.client = self.app.test_client() self.engine = create_engine(self.app.config['SQLALCHEMY_DATABASE_URI']) internal_token_data = {constants.USER_IDENTIFIER: AppTestCase.SPECIFIC_INTERNAL_USER, "role": "internal"} external_token_data = {constants.USER_IDENTIFIER: AppTestCase.SPECIFIC_EXTERNAL_USER, "role": "respondent", "claims": [{'business_id': 'f1a5e99c-8edf-489a-9c72-6cabe6c387fc', 'surveys': [AppTestCase.BRES_SURVEY] }] } with self.app.app_context(): internal_signed_jwt = encode(internal_token_data) external_signed_jwt = encode(external_token_data) self.internal_user_header = {'Content-Type': 'application/json', 'Authorization': internal_signed_jwt} self.external_user_header = {'Content-Type': 'application/json', 'Authorization': external_signed_jwt} self.test_message = {'msg_to': ['0a7ad740-10d5-4ecb-b7ca-3c0384afb882'], 'msg_from': AppTestCase.SPECIFIC_INTERNAL_USER, 'subject': 'MyMessage', 'body': 'hello', 'thread_id': "", 'collection_case': 'ACollectionCase', 'collection_exercise': 'ACollectionExercise', 'business_id': 'f1a5e99c-8edf-489a-9c72-6cabe6c387fc', 'survey': self.BRES_SURVEY} with self.app.app_context(): database.db.init_app(current_app) database.db.drop_all() database.db.create_all() self.db = database.db party.use_mock_service() internal_user_service.use_mock_service()
def setUp(self): """setup test environment""" self.app = create_app() self.app.testing = True party.use_mock_service() internal_user_service.use_mock_service()
def setUp(self): self.app = create_app() self.client = self.app.test_client() internal_user_service.use_mock_service() party.use_mock_service()
def step_impl_use_mock_internal_user_service(context): """Use mock internal user service tests.""" internal_user_service.use_mock_service()
def setUp(self): """setup test environment""" self.now = datetime.now(timezone.utc) internal_user_service.use_mock_service() party.use_mock_service()