test_suggestions.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import pytest
  2. from tests import TestBest
  3. from yandex_music import Best, Suggestions
  4. @pytest.fixture(scope='class', params=[1, 2, 3, 4, 5])
  5. def suggestions_with_best(request, results, types):
  6. best = Best(types[request.param], results[request.param], TestBest.text)
  7. return Suggestions(best, TestSuggestions.suggestions), best
  8. class TestSuggestions:
  9. suggestions = [
  10. 'empathy test',
  11. 'testament',
  12. 'crash test dummies',
  13. 'seekae - test & recognise',
  14. 'joji - test drive',
  15. 'john powell - test drive',
  16. 'max richter - testament of youth',
  17. 'seekae - test & recognise',
  18. 'testament - first strike still deadly',
  19. '90-е в стиле r&b и соул',
  20. 'crash test dummy: из чего состоит portishead',
  21. 'в стиле: alice testrup',
  22. ]
  23. def test_expected_values(self, suggestions_with_best):
  24. suggestions, best = suggestions_with_best
  25. assert suggestions.best == best
  26. assert suggestions.suggestions == self.suggestions
  27. def test_de_json_none(self, client):
  28. assert Suggestions.de_json({}, client) is None
  29. def test_de_json_required(self, client, best):
  30. json_dict = {'best': best.to_dict(), 'suggestions': self.suggestions}
  31. suggestions = Suggestions.de_json(json_dict, client)
  32. assert suggestions.best == best
  33. assert suggestions.suggestions == self.suggestions
  34. def test_de_json_all(self, client, best):
  35. json_dict = {'best': best.to_dict(), 'suggestions': self.suggestions}
  36. suggestions = Suggestions.de_json(json_dict, client)
  37. assert suggestions.best == best
  38. assert suggestions.suggestions == self.suggestions
  39. def test_equality(self, best):
  40. a = Suggestions(best, self.suggestions)
  41. b = Suggestions(None, self.suggestions)
  42. c = Suggestions(best, [])
  43. d = Suggestions(best, self.suggestions)
  44. assert a != b != c
  45. assert hash(a) != hash(b) != hash(c)
  46. assert a is not b is not c
  47. assert a == d