test_photo.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. # coordinates["1"]
  45. (
  46. 8,
  47. {
  48. "description_url": "https://commons.wikimedia.org/wiki"
  49. "/File:Kasern_-_hinteres_Ahrntal.JPG",
  50. "latitude": 47.06111,
  51. "longitude": 12.15333,
  52. "photo_url": "https://upload.wikimedia.org/wikipedia/commons/c/ce"
  53. "/Kasern_-_hinteres_Ahrntal.JPG",
  54. },
  55. ),
  56. ),
  57. )
  58. def test_from_wikimap_export(wikimap_export, index, expected_vars):
  59. # https://github.com/pytest-dev/pytest/issues/3164 recursive pytest.approx not available
  60. assert vars(_Photo.from_wikimap_export(wikimap_export[index])) == expected_vars
  61. def test___str__():
  62. assert (
  63. str(
  64. _Photo(
  65. photo_url="https://upload.wikimedia.org/wikipedia/commons/6/65"
  66. "/Gro%C3%9Fvenediger3.JPG",
  67. description_url="https://commons.wikimedia.org/wiki"
  68. "/File:Gro%C3%9Fvenediger3.JPG",
  69. latitude=47.24854167,
  70. longitude=12.25381667,
  71. )
  72. )
  73. == "photo https://commons.wikimedia.org/wiki/File:Gro%C3%9Fvenediger3.JPG"
  74. )