fed8b2eed7
Backend release / release (push) Waiting to run
Bandit Security Scan / bandit_scan (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / manifest (push) Blocked by required conditions
Build and push DocsGPT FE Docker image for development / build (linux/amd64, ubuntu-latest, amd64) (push) Waiting to run
Build and push DocsGPT FE Docker image for development / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Waiting to run
Build and push DocsGPT FE Docker image for development / manifest (push) Blocked by required conditions
Python linting / ruff (push) Waiting to run
Run python tests with pytest / Run tests and count coverage (3.12) (push) Waiting to run
React Widget Build / build (push) Waiting to run
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from pathlib import Path
|
|
from unittest.mock import patch, MagicMock, mock_open
|
|
|
|
from application.parser.file.image_parser import ImageParser
|
|
|
|
|
|
def test_image_init_parser():
|
|
parser = ImageParser()
|
|
assert isinstance(parser._init_parser(), dict)
|
|
assert not parser.parser_config_set
|
|
parser.init_parser()
|
|
assert parser.parser_config_set
|
|
|
|
|
|
@patch("application.parser.file.image_parser.settings")
|
|
def test_image_parser_remote_true(mock_settings):
|
|
mock_settings.PARSE_IMAGE_REMOTE = True
|
|
parser = ImageParser()
|
|
|
|
mock_response = MagicMock()
|
|
mock_response.json.return_value = {"markdown": "# From Image"}
|
|
|
|
with patch("application.parser.file.image_parser.requests.post", return_value=mock_response) as mock_post:
|
|
with patch("builtins.open", mock_open()):
|
|
result = parser.parse_file(Path("img.png"))
|
|
|
|
assert result == "# From Image"
|
|
mock_post.assert_called_once()
|
|
|
|
|
|
@patch("application.parser.file.image_parser.settings")
|
|
def test_image_parser_remote_false(mock_settings):
|
|
mock_settings.PARSE_IMAGE_REMOTE = False
|
|
parser = ImageParser()
|
|
|
|
with patch("application.parser.file.image_parser.requests.post") as mock_post:
|
|
result = parser.parse_file(Path("img.png"))
|
|
|
|
assert result == ""
|
|
mock_post.assert_not_called()
|
|
|