test_photo.py 2.9 KB

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