mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-23 23:07:17 +00:00
replace if with while for telelgram reporting
This commit is contained in:
parent
bf959ceb5f
commit
b8d2775050
@ -2,7 +2,7 @@
|
||||
|
||||
[](https://github.com/arcan1s/ahriman/actions/workflows/run-tests.yml)
|
||||
[](https://github.com/arcan1s/ahriman/actions/workflows/run-setup.yml)
|
||||
[](https://github.com/arcan1s/ahriman/actions/workflows/docker-image.yml)
|
||||
[](https://hub.docker.com/r/arcan1s/ahriman)
|
||||
[](https://www.codefactor.io/repository/github/arcan1s/ahriman)
|
||||
[](https://ahriman.readthedocs.io/?badge=latest)
|
||||
|
||||
|
@ -30,10 +30,3 @@ Contents
|
||||
advanced-usage
|
||||
triggers
|
||||
modules
|
||||
|
||||
Indices and tables
|
||||
------------------
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user