def test_acquire_lock(self, lock_file: unittest.mock.Mock) -> None: (_, path) = tempfile.mkstemp() lockfile_file_descriptor = None with acquire_lock(path, blocking=False) as file_descriptor: lockfile_file_descriptor = file_descriptor with acquire_lock(path, blocking=True): pass lock_file.assert_has_calls( [ call(lockfile_file_descriptor, fcntl.LOCK_EX | fcntl.LOCK_NB), call(lockfile_file_descriptor, fcntl.LOCK_UN), call(lockfile_file_descriptor, fcntl.LOCK_EX), call(lockfile_file_descriptor, fcntl.LOCK_UN), ] ) def fail_on_exclusive(_, lock_kind): if lock_kind == fcntl.LOCK_EX | fcntl.LOCK_NB: raise OSError() return None lock_file.side_effect = fail_on_exclusive with self.assertRaises(OSError): with acquire_lock(path, blocking=False): pass
def test_good_client_response_feature( self, mock_get_preview_data: unittest.mock.Mock) -> None: """ """ expected_response_json = { 'msg': 'Success', 'previewData': { 'columns': [{}, {}], 'data': [{ 'id': 1, 'name': 'Admin' }, { 'id': 2, 'name': 'Public' }, { 'id': 3, 'name': 'Alpha' }] } } local_app.config['PREVIEW_CLIENT'] = PREVIEW_CLIENT_CLASS response = json.dumps({'preview_data': good_json_data}) mock_get_preview_data.return_value = Response(response=response, status=HTTPStatus.OK) with local_app.test_client() as test: post_response = test.post('/api/preview/v0/feature_preview') self.assertEqual(post_response.status_code, HTTPStatus.OK) self.assertEqual(post_response.json, expected_response_json)
def test_try_lock(self, lock_file: unittest.mock.Mock) -> None: (_, path) = tempfile.mkstemp() lockfile_file_descriptor = None with try_lock(path) as file_descriptor: lockfile_file_descriptor = file_descriptor lock_file.assert_has_calls([ call(lockfile_file_descriptor, fcntl.LOCK_EX | fcntl.LOCK_NB), call(lockfile_file_descriptor, fcntl.LOCK_UN) ]) def fail_on_exclusive(_, lock_kind): if lock_kind == fcntl.LOCK_EX | fcntl.LOCK_NB: raise OSError() return None lock_file.side_effect = fail_on_exclusive with self.assertRaises(OSError): with try_lock(path): pass
def test_good_client_response(self, mock_get_posts: unittest.mock.Mock) -> None: """ :return: """ local_app.config['ANNOUNCEMENT_CLIENT'] = ANNOUNCEMENT_CLIENT_CLASS mock_get_posts.return_value = Response(response='', status=HTTPStatus.OK) with local_app.test_client() as test: response = test.get('/api/announcements/v0/') self.assertEqual(response.status_code, HTTPStatus.OK)
def test_try_lock(self, lock_file: unittest.mock.Mock) -> None: (_, path) = tempfile.mkstemp() lockfile_file_descriptor = None # pyre-ignore: T29602753 with try_lock(path) as file_descriptor: lockfile_file_descriptor = file_descriptor lock_file.assert_has_calls([ call(lockfile_file_descriptor, fcntl.LOCK_EX | fcntl.LOCK_NB), call(lockfile_file_descriptor, fcntl.LOCK_UN), ]) def fail_on_exclusive(_, lock_kind): if lock_kind == fcntl.LOCK_EX | fcntl.LOCK_NB: raise OSError() return None lock_file.side_effect = fail_on_exclusive with self.assertRaises(OSError): with try_lock(path): pass
def test_create_jira_issue_missing_config( self, mock_issue_tracker_client: unittest.mock.Mock) -> None: """ Test request failure if config settings are missing :return: """ mock_issue_tracker_client.side_effect = IssueConfigurationException local_app.config['ISSUE_TRACKER_URL'] = None with local_app.test_client() as test: response = test.post('/api/issue/issue', data={ 'description': 'test description', 'title': 'test title', 'key': 'key' }) self.assertEqual(response.status_code, HTTPStatus.NOT_IMPLEMENTED)
def test_create_jira_issue_missing_config(self, mock_issue_tracker_client: unittest.mock.Mock) -> None: """ Test request failure if config settings are missing :return: """ mock_issue_tracker_client.side_effect = IssueConfigurationException local_app.config['ISSUE_TRACKER_URL'] = None with local_app.test_client() as test: response = test.post('/api/issue/issue', data={ 'description': 'test description', 'owner_ids': ['*****@*****.**', '*****@*****.**'], 'frequent_user_ids': ['*****@*****.**', '*****@*****.**'], 'priority_level': 'P2', 'project_key': 'test project', 'title': 'test title', 'key': 'key', 'resource_path': '/table_detail/cluster/database/schema/table_name' }) self.assertEqual(response.status_code, HTTPStatus.NOT_IMPLEMENTED)
def test_bad_client_response( self, mock_get_preview_data: unittest.mock.Mock) -> None: """ """ expected_response_json = { 'msg': 'Encountered exception: The preview client did not return a valid PreviewData object', 'previewData': {} } local_app.config['PREVIEW_CLIENT'] = PREVIEW_CLIENT_CLASS response = json.dumps({'preview_data': bad_json_data}) mock_get_preview_data.return_value = Response(response=response, status=HTTPStatus.OK) with local_app.test_client() as test: post_response = test.post('/api/preview/v0/') self.assertEqual(post_response.status_code, HTTPStatus.INTERNAL_SERVER_ERROR) self.assertEqual(post_response.json, expected_response_json)