test_search_result.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from yandex_music import SearchResult
  2. class TestSearchResult:
  3. total = 3
  4. per_page = 10
  5. order = 0
  6. def test_expected_values(self, search_result_with_results_and_type):
  7. search_result, results, type_ = search_result_with_results_and_type
  8. assert search_result.type == type_
  9. assert search_result.total == self.total
  10. assert search_result.per_page == self.per_page
  11. assert search_result.order == self.order
  12. assert search_result.results == results
  13. def test_de_json_none(self, client):
  14. assert SearchResult.de_json({}, client) is None
  15. def test_de_json_required(self, client, result_with_type):
  16. result, type_ = result_with_type
  17. json_dict = {'total': self.total, 'per_page': self.per_page, 'order': self.order, 'results': [result.to_dict()]}
  18. search_result = SearchResult.de_json(json_dict, client, type_)
  19. assert search_result.type == type_
  20. assert search_result.total == self.total
  21. assert search_result.per_page == self.per_page
  22. assert search_result.order == self.order
  23. assert search_result.results == [result]
  24. def test_de_json_all(self, client, result_with_type):
  25. result, type_ = result_with_type
  26. json_dict = {'total': self.total, 'per_page': self.per_page, 'order': self.order, 'results': [result.to_dict()]}
  27. search_result = SearchResult.de_json(json_dict, client, type_)
  28. assert search_result.type == type_
  29. assert search_result.total == self.total
  30. assert search_result.per_page == self.per_page
  31. assert search_result.order == self.order
  32. assert search_result.results == [result]
  33. def test_equality(self, result_with_type):
  34. result, type_ = result_with_type
  35. a = SearchResult(type_, self.total, self.per_page, self.order, [result])
  36. b = SearchResult(type_, 10, self.per_page, 1, [result])
  37. c = SearchResult(type_, self.total, self.per_page, self.order, [result])
  38. assert a != b
  39. assert hash(a) != hash(b)
  40. assert a is not b
  41. assert a == c