test_photo.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 pytest
  18. from location_guessing_game_telegram_bot import _Photo
  19. @pytest.mark.parametrize(
  20. ("index", "expected_vars"),
  21. (
  22. (
  23. 0,
  24. {
  25. "description_url": "https://commons.wikimedia.org/wiki"
  26. "/File:H%C3%BCtteltalkopf_(Venedigergruppe)_from_Tristkopf.jpg",
  27. "latitude": 47.288805,
  28. "longitude": 12.144116,
  29. "photo_url": "https://upload.wikimedia.org/wikipedia/commons/a/ab"
  30. "/H%C3%BCtteltalkopf_%28Venedigergruppe%29_from_Tristkopf.jpg",
  31. },
  32. ),
  33. (
  34. 1,
  35. {
  36. "description_url": "https://commons.wikimedia.org/wiki"
  37. "/File:Gro%C3%9Fvenediger3.JPG",
  38. "latitude": 47.24854167,
  39. "longitude": 12.25381667,
  40. "photo_url": "https://upload.wikimedia.org/wikipedia/commons/6/65"
  41. "/Gro%C3%9Fvenediger3.JPG",
  42. },
  43. ),
  44. ),
  45. )
  46. def test_from_wikimap_export(wikimap_export, index, expected_vars):
  47. # https://github.com/pytest-dev/pytest/issues/3164 recursive pytest.approx not available
  48. assert vars(_Photo.from_wikimap_export(wikimap_export[index])) == expected_vars
  49. def test___str__():
  50. assert (
  51. str(
  52. _Photo(
  53. photo_url="https://upload.wikimedia.org/wikipedia/commons/6/65"
  54. "/Gro%C3%9Fvenediger3.JPG",
  55. description_url="https://commons.wikimedia.org/wiki"
  56. "/File:Gro%C3%9Fvenediger3.JPG",
  57. latitude=47.24854167,
  58. longitude=12.25381667,
  59. )
  60. )
  61. == "photo https://commons.wikimedia.org/wiki/File:Gro%C3%9Fvenediger3.JPG"
  62. )