test_run.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. from location_guessing_game_telegram_bot import _run
  19. def test__run(tmp_path, wikimap_export_path):
  20. telegram_token_path = tmp_path.joinpath("token")
  21. telegram_token_path.write_text("secret\n")
  22. with unittest.mock.patch("telegram.ext.Updater") as updater_mock:
  23. _run(
  24. telegram_token_path=telegram_token_path,
  25. wikimap_export_path=wikimap_export_path,
  26. )
  27. assert updater_mock.call_count == 1
  28. assert not updater_mock.call_args.args
  29. assert set(updater_mock.call_args.kwargs.keys()) == {
  30. "persistence",
  31. "token",
  32. "use_context",
  33. }
  34. assert updater_mock.call_args.kwargs["token"] == "secret"
  35. assert updater_mock.call_args.kwargs["use_context"] is True
  36. persistence = updater_mock.call_args.kwargs["persistence"]
  37. photos = persistence.get_bot_data()["photos"]
  38. assert len(photos) == 25
  39. assert (
  40. photos[1].photo_url
  41. == "https://upload.wikimedia.org/wikipedia/commons/6/65/Gro%C3%9Fvenediger3.JPG"
  42. )