diff --git a/README.md b/README.md index 0d2f09bc..2b353e7b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![tests status](https://github.com/arcan1s/ahriman/actions/workflows/run-tests.yml/badge.svg)](https://github.com/arcan1s/ahriman/actions/workflows/run-tests.yml) [![setup status](https://github.com/arcan1s/ahriman/actions/workflows/run-setup.yml/badge.svg)](https://github.com/arcan1s/ahriman/actions/workflows/run-setup.yml) -[![docker image](https://github.com/arcan1s/ahriman/actions/workflows/docker-image.yml/badge.svg)](https://github.com/arcan1s/ahriman/actions/workflows/docker-image.yml) +[![Docker Image Version (latest semver)](https://img.shields.io/docker/v/arcan1s/ahriman?label=docker%20image)](https://hub.docker.com/r/arcan1s/ahriman) [![CodeFactor](https://www.codefactor.io/repository/github/arcan1s/ahriman/badge)](https://www.codefactor.io/repository/github/arcan1s/ahriman) [![Documentation Status](https://readthedocs.org/projects/ahriman/badge/?version=latest)](https://ahriman.readthedocs.io/?badge=latest) diff --git a/docs/index.rst b/docs/index.rst index 85757e13..a630d698 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -30,10 +30,3 @@ Contents advanced-usage triggers modules - -Indices and tables ------------------- - -* :ref:`genindex` -* :ref:`modindex` -* :ref:`search` diff --git a/src/ahriman/core/report/telegram.py b/src/ahriman/core/report/telegram.py index da400e71..ce5a22ee 100644 --- a/src/ahriman/core/report/telegram.py +++ b/src/ahriman/core/report/telegram.py @@ -94,8 +94,11 @@ class Telegram(Report, JinjaTemplate): text = self.make_html(result, self.template_path) # telegram content is limited by 4096 symbols, so we are going to split the message by new lines # to fit into this restriction - if len(text) > self.TELEGRAM_MAX_CONTENT_LENGTH: + while len(text) > self.TELEGRAM_MAX_CONTENT_LENGTH: position = text.rfind("\n", 0, self.TELEGRAM_MAX_CONTENT_LENGTH) + if position == -1: + # normally should not happen, but we allow templates editing + raise ValueError("substring not found") portion, text = text[:position], text[position + 1:] # +1 to exclude newline we split self._send(portion) # send remaining (or full in case if size is less than max length) text diff --git a/tests/ahriman/core/report/test_telegram.py b/tests/ahriman/core/report/test_telegram.py index 2809c9d9..920e263c 100644 --- a/tests/ahriman/core/report/test_telegram.py +++ b/tests/ahriman/core/report/test_telegram.py @@ -57,6 +57,18 @@ def test_generate(configuration: Configuration, package_ahriman: Package, result send_mock.assert_called_once_with(pytest.helpers.anyvar(int)) +def test_generate_big_text_without_spaces(configuration: Configuration, package_ahriman: Package, result: Result, + mocker: MockerFixture) -> None: + """ + must raise ValueError in case if there are no new lines in text + """ + mocker.patch("ahriman.core.report.JinjaTemplate.make_html", return_value="ab" * 4096) + report = Telegram("x86_64", configuration, "telegram") + + with pytest.raises(ValueError): + report.generate([package_ahriman], result) + + def test_generate_big_text(configuration: Configuration, package_ahriman: Package, result: Result, mocker: MockerFixture) -> None: """ @@ -72,6 +84,23 @@ def test_generate_big_text(configuration: Configuration, package_ahriman: Packag ]) +def test_generate_very_big_text(configuration: Configuration, package_ahriman: Package, result: Result, + mocker: MockerFixture) -> None: + """ + must generate report with very big text + """ + mocker.patch("ahriman.core.report.JinjaTemplate.make_html", return_value="ab\n" * 4096) + send_mock = mocker.patch("ahriman.core.report.Telegram._send") + + report = Telegram("x86_64", configuration, "telegram") + report.generate([package_ahriman], result) + send_mock.assert_has_calls([ + mock.call(pytest.helpers.anyvar(str, strict=True)), + mock.call(pytest.helpers.anyvar(str, strict=True)), + mock.call(pytest.helpers.anyvar(str, strict=True)), + ]) + + def test_generate_no_empty(configuration: Configuration, package_ahriman: Package, mocker: MockerFixture) -> None: """ must generate report