def _make_client( status="SUCCESS", keypoint_id=111, with_extract_exception=False, with_wait_exception=False, with_drawing=False, with_upload=False, ): client_mock = mocker.MagicMock() extract_mock = client_mock.return_value.extract_keypoint if with_extract_exception: extract_mock.side_effect = RequestsError() else: extract_mock.return_value = keypoint_id wait_mock = client_mock.return_value.wait_for_extraction if with_wait_exception: wait_mock.side_effect = RequestsError() else: wait_mock.return_value.status = status if status == "FAILURE": wait_mock.return_value.failure_detail = "message" if with_drawing: mocker.patch("anymotion_cli.commands.extract.draw", mocker.MagicMock()) if with_upload: mocker.patch("anymotion_cli.commands.extract.upload", mocker.MagicMock()) mocker.patch("anymotion_cli.commands.extract.get_client", client_mock) return client_mock
def _get_client_mock( self, mocker, status="SUCCESS", with_analyze_exception=False, with_wait_exception=False, ): analysis_id = 111 client_mock = mocker.MagicMock() if with_analyze_exception: client_mock.return_value.analyze_keypoint.side_effect = RequestsError( ) else: client_mock.return_value.analyze_keypoint.return_value = analysis_id wait_mock = client_mock.return_value.wait_for_analysis if with_wait_exception: wait_mock.side_effect = RequestsError() else: wait_mock.return_value.status = status if status == "FAILURE": wait_mock.return_value.failure_detail = "message" mocker.patch("anymotion_cli.commands.analyze.get_client", client_mock) return client_mock
def _make_client( status="SUCCESS", comparison_id=111, with_compare_exception=False, with_wait_exception=False, ): client_mock = mocker.MagicMock() compare_mock = client_mock.return_value.compare_keypoint if with_compare_exception: compare_mock.side_effect = RequestsError("requests error") else: compare_mock.return_value = comparison_id wait_mock = client_mock.return_value.wait_for_comparison if with_wait_exception: wait_mock.side_effect = RequestsError("requests error") else: wait_mock.return_value.status = status if status == "FAILURE": wait_mock.return_value.failure_detail = "message" mocker.patch("anymotion_cli.commands.compare.get_client", client_mock) return client_mock
def _make_client(num_data=1, with_exception=False): client_mock = mocker.MagicMock() if with_exception: client_mock.return_value.get_analyses.side_effect = RequestsError() else: data = [{"id": i + 1, "execStatus": "SUCCESS"} for i in range(num_data)] client_mock.return_value.get_analyses.return_value = data mocker.patch("anymotion_cli.commands.analysis.get_client", client_mock) return client_mock
def _make_client(num_data=1, with_exception=False): client_mock = mocker.MagicMock() comparison_mock = client_mock.return_value.get_comparisons if with_exception: comparison_mock.side_effect = RequestsError("requests error") else: data = [{"id": i + 1, "execStatus": "SUCCESS"} for i in range(num_data)] comparison_mock.return_value = data mocker.patch("anymotion_cli.commands.comparison.get_client", client_mock) return client_mock
def _make_client(status="SUCCESS", with_exception=False): client_mock = mocker.MagicMock() if with_exception: client_mock.return_value.get_drawing.side_effect = RequestsError() else: client_mock.return_value.get_drawing.return_value = { "id": 1, "execStatus": status, } mocker.patch("anymotion_cli.commands.drawing.get_client", client_mock) return client_mock
def _make_client( status="SUCCESS", with_get_drawing_exception=False, with_get_name_exception=False, with_download_exception=False, ): if status == "SUCCESS": url = "http://example.com/image.jpg" else: url = None client_mock = mocker.MagicMock() get_drawing_mock = client_mock.return_value.get_drawing if with_get_drawing_exception: get_drawing_mock.side_effect = RequestsError() else: get_drawing_mock.return_value = { "execStatus": status, "drawingUrl": url, "keypoint": 222, } if with_download_exception: client_mock.return_value.download.side_effect = RequestsError() else: client_mock.return_value.download.return_value = None mocker.patch("anymotion_cli.commands.download.get_client", client_mock) if with_get_name_exception: get_name_mock = mocker.MagicMock(side_effect=RequestsError()) else: get_name_mock = mocker.MagicMock(return_value="image") mocker.patch( "anymotion_cli.commands.download._get_name_from_keypoint_id", get_name_mock, ) return client_mock
def _make_client(with_exception=False): client_mock = mocker.MagicMock() if with_exception: client_mock.return_value.get_image.side_effect = RequestsError( ) else: client_mock.return_value.get_image.return_value = { "id": 1, "name": "image", } mocker.patch("anymotion_cli.commands.image.get_client", client_mock) return client_mock
def _make_client(num_data=1, with_exception=False): client_mock = mocker.MagicMock() if with_exception: client_mock.return_value.get_images.side_effect = RequestsError( ) else: data = [{ "id": i + 1, "name": "image" } for i in range(num_data)] client_mock.return_value.get_images.return_value = data mocker.patch("anymotion_cli.commands.image.get_client", client_mock) return client_mock
def _make_client(status="SUCCESS", with_exception=False): client_mock = mocker.MagicMock() if status == "SUCCESS": data = [{"analysisType": "angle", "values": [180]}] else: data = None if with_exception: client_mock.return_value.get_analysis.side_effect = RequestsError() else: client_mock.return_value.get_analysis.return_value = { "id": 111, "result": data, "execStatus": status, } mocker.patch("anymotion_cli.commands.analysis.get_client", client_mock) return client_mock
def _make_client(status="SUCCESS", num_data=1, with_exception=False): if status == "SUCCESS": data = [{"1": [i + 1, i * i]} for i in range(num_data)] else: data = None client_mock = mocker.MagicMock() if with_exception: client_mock.return_value.get_keypoint.side_effect = RequestsError( ) else: client_mock.return_value.get_keypoint.return_value = { "id": 111, "keypoint": data, "execStatus": status, } mocker.patch("anymotion_cli.commands.keypoint.get_client", client_mock) return client_mock
def _make_client( media_type="image", with_file_type_error=False, with_requests_error=False ): client_mock = mocker.MagicMock() if with_file_type_error: client_mock.return_value.upload.side_effect = FileTypeError() elif with_requests_error: client_mock.return_value.upload.side_effect = RequestsError() elif media_type == "image": client_mock.return_value.upload.return_value.image_id = 1 client_mock.return_value.upload.return_value.movie_id = None else: client_mock.return_value.upload.return_value.image_id = None client_mock.return_value.upload.return_value.movie_id = 1 mocker.patch("anymotion_cli.commands.upload.get_client", client_mock) return client_mock
def _make_client(status="SUCCESS", with_exception=False): client_mock = mocker.MagicMock() if status == "SUCCESS": data = [{"nose": {"distance": 0.0, "direction": 0.0}}] else: data = None comparison_mock = client_mock.return_value.get_comparison if with_exception: comparison_mock.side_effect = RequestsError("requests error") else: comparison_mock.return_value = { "id": 111, "target": 222, "source": 333, "difference": data, "execStatus": status, } mocker.patch("anymotion_cli.commands.comparison.get_client", client_mock) return client_mock
def _make_client(status="SUCCESS", drawing_id=111, with_exception=False): client_mock = mocker.MagicMock() client_mock.return_value.draw_keypoint.return_value = drawing_id if status == "SUCCESS": url = "http://example.com/image.jpg" else: url = None wait_mock = client_mock.return_value.wait_for_drawing if with_exception: wait_mock.side_effect = RequestsError() else: wait_mock.return_value.status = status wait_mock.return_value.get.return_value = url mocker.patch("anymotion_cli.commands.draw.get_client", client_mock) mocker.patch("anymotion_cli.commands.draw.download", mocker.MagicMock()) return client_mock