test_run.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # location-guessing-game-telegram-bot - Telegram Bot Sending Random Wikimedia Commons Photos
  2. #
  3. # Copyright (C) 2021 Fabian Peter Hammerle <fabian@hammerle.me>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. import unittest.mock
  18. # pylint: disable=import-private-name; tests
  19. from location_guessing_game_telegram_bot import _run
  20. def test__run(tmp_path, wikimap_export_path):
  21. telegram_token_path = tmp_path.joinpath("token")
  22. telegram_token_path.write_text("secret\n")
  23. with unittest.mock.patch("telegram.ext.Updater") as updater_mock:
  24. _run(
  25. telegram_token_path=telegram_token_path,
  26. wikimap_export_path=wikimap_export_path,
  27. )
  28. updater_mock.assert_called_once()
  29. # > Changed in version 3.8: Added args and kwargs properties.
  30. # https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.call_args_list
  31. init_args, init_kwargs = updater_mock.call_args
  32. assert not init_args
  33. assert set(init_kwargs.keys()) == {
  34. "persistence",
  35. "token",
  36. "use_context",
  37. }
  38. assert init_kwargs["token"] == "secret"
  39. assert init_kwargs["use_context"] is True
  40. photos = init_kwargs["persistence"].get_bot_data()["photos"]
  41. assert len(photos) == 25
  42. assert (
  43. photos[1].photo_url
  44. == "https://upload.wikimedia.org/wikipedia/commons/6/65/Gro%C3%9Fvenediger3.JPG"
  45. )