test_genre.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import pytest
  2. from yandex_music import Genre
  3. @pytest.fixture(scope='class')
  4. def genre(title, images, icon, genre_without_sub_genre):
  5. return Genre(
  6. TestGenre.id,
  7. TestGenre.weight,
  8. TestGenre.composer_top,
  9. TestGenre.title,
  10. {'uz': title},
  11. images,
  12. TestGenre.show_in_menu,
  13. TestGenre.show_in_regions,
  14. TestGenre.full_title,
  15. TestGenre.url_part,
  16. TestGenre.color,
  17. icon,
  18. [genre_without_sub_genre],
  19. TestGenre.hide_in_regions,
  20. )
  21. @pytest.fixture(scope='class')
  22. def genre_without_sub_genre(title, images, icon):
  23. return Genre(
  24. TestGenre.id,
  25. TestGenre.weight,
  26. TestGenre.composer_top,
  27. TestGenre.title,
  28. {'uz': title},
  29. images,
  30. TestGenre.show_in_menu,
  31. )
  32. class TestGenre:
  33. id = 'all'
  34. weight = 2
  35. composer_top = False
  36. title = None
  37. show_in_menu = True
  38. show_in_regions = [181]
  39. full_title = 'Музыка всех жанров'
  40. url_part = None
  41. color = None
  42. hide_in_regions = None
  43. def test_expected_values(self, genre, title, images, icon, genre_without_sub_genre):
  44. assert genre.id == self.id
  45. assert genre.weight == self.weight
  46. assert genre.composer_top == self.composer_top
  47. assert genre.title == self.title
  48. assert genre.titles == {'uz': title}
  49. assert genre.images == images
  50. assert genre.show_in_menu == self.show_in_menu
  51. assert genre.show_in_regions == self.show_in_regions
  52. assert genre.full_title == self.full_title
  53. assert genre.url_part == self.url_part
  54. assert genre.color == self.color
  55. assert genre.radio_icon == icon
  56. assert genre.sub_genres == [genre_without_sub_genre]
  57. assert genre.hide_in_regions == self.hide_in_regions
  58. def test_de_json_none(self, client):
  59. assert Genre.de_json({}, client) is None
  60. def test_de_list_none(self, client):
  61. assert Genre.de_list([], client) == []
  62. def test_de_json_required(self, client, title, images):
  63. json_dict = {
  64. 'id': self.id,
  65. 'weight': self.weight,
  66. 'composer_top': self.composer_top,
  67. 'title': self.title,
  68. 'titles': {'uz': title.to_dict()},
  69. 'images': images.to_dict(),
  70. 'show_in_menu': self.show_in_menu,
  71. }
  72. genre = Genre.de_json(json_dict, client)
  73. assert genre.id == self.id
  74. assert genre.weight == self.weight
  75. assert genre.composer_top == self.composer_top
  76. assert genre.title == self.title
  77. assert genre.titles == {'uz': title}
  78. assert genre.images == images
  79. assert genre.show_in_menu == self.show_in_menu
  80. def test_de_json_all(self, client, title, images, icon, genre_without_sub_genre):
  81. json_dict = {
  82. 'id': self.id,
  83. 'weight': self.weight,
  84. 'composer_top': self.composer_top,
  85. 'title': self.title,
  86. 'titles': {'uz': title.to_dict()},
  87. 'images': images.to_dict(),
  88. 'show_in_menu': self.show_in_menu,
  89. 'full_title': self.full_title,
  90. 'url_part': self.url_part,
  91. 'color': self.color,
  92. 'radio_icon': icon.to_dict(),
  93. 'sub_genres': [genre_without_sub_genre.to_dict()],
  94. 'hide_in_regions': self.hide_in_regions,
  95. 'show_in_regions': self.show_in_regions,
  96. }
  97. genre = Genre.de_json(json_dict, client)
  98. assert genre.id == self.id
  99. assert genre.weight == self.weight
  100. assert genre.composer_top == self.composer_top
  101. assert genre.title == self.title
  102. assert genre.titles == {'uz': title}
  103. assert genre.images == images
  104. assert genre.show_in_menu == self.show_in_menu
  105. assert genre.show_in_regions == self.show_in_regions
  106. assert genre.full_title == self.full_title
  107. assert genre.url_part == self.url_part
  108. assert genre.color == self.color
  109. assert genre.radio_icon == icon
  110. assert genre.sub_genres == [genre_without_sub_genre]
  111. assert genre.hide_in_regions == self.hide_in_regions
  112. def test_equality(self, title, images):
  113. a = Genre(self.id, self.weight, self.composer_top, self.title, {'uz': title}, images, self.show_in_menu)
  114. b = Genre(self.id, self.weight, False, '', {'uz': title}, images, self.show_in_menu)
  115. c = Genre(self.id, 30, self.composer_top, self.title, {'uz': title}, images, self.show_in_menu)
  116. d = Genre(self.id, self.weight, self.composer_top, self.title, {'uz': title}, images, self.show_in_menu)
  117. assert a != b != c
  118. assert hash(a) != hash(b) != hash(c)
  119. assert a is not b is not c
  120. assert a == d