mirror of
https://github.com/Tech-Workers-Coalition-Italia/mobilizon-reshare.git
synced 2025-01-30 17:14:53 +01:00
8a27de8981
* fixed test_window_no_event * added strategy tests * removed unused code * added config tests * added more config tests * refactored tests * updated pytest
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import dynaconf
|
|
import pkg_resources
|
|
import pytest
|
|
|
|
from mobilizon_bots.config.config import update_settings_files
|
|
|
|
|
|
@pytest.fixture
|
|
def invalid_settings_file(tmp_path, toml_content):
|
|
file = tmp_path / "tmp.toml"
|
|
file.write_text(toml_content)
|
|
return file
|
|
|
|
|
|
@pytest.mark.parametrize("toml_content", ["invalid toml["])
|
|
def test_update_failure_invalid_toml(invalid_settings_file):
|
|
with pytest.raises(dynaconf.vendor.toml.decoder.TomlDecodeError):
|
|
update_settings_files([invalid_settings_file.absolute()])
|
|
|
|
|
|
@pytest.mark.parametrize("toml_content", [""])
|
|
def test_update_failure_invalid_preliminary_config(invalid_settings_file):
|
|
with pytest.raises(dynaconf.validator.ValidationError):
|
|
update_settings_files([invalid_settings_file.absolute()])
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"invalid_toml,pattern_in_exception",
|
|
[
|
|
["config_with_strategy.toml", "publisher.*.active"],
|
|
["config_with_preliminary.toml", "publishing.window.begin"],
|
|
["config_with_invalid_telegram.toml", "token"],
|
|
],
|
|
)
|
|
def test_update_failure_config_without_publishers(invalid_toml, pattern_in_exception):
|
|
with pytest.raises(dynaconf.validator.ValidationError) as e:
|
|
update_settings_files(
|
|
[pkg_resources.resource_filename("tests.resources.config", invalid_toml)]
|
|
)
|
|
assert e.match(pattern_in_exception)
|