test_shot_data.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from yandex_music import ShotData
  2. class TestShotData:
  3. cover_uri = 'avatars.mds.yandex.net/get-music-misc/49997/img.5da435f1da39b871a74270e2/%%'
  4. mds_url = 'https://storage.mds.yandex.net/get-music/1634376/public/shots/1036797_1574621686'
  5. shot_text = 'Бард - это не просто певец, это поющий поэт.'
  6. def test_expected_values(self, shot_data, shot_type):
  7. assert shot_data.cover_uri == self.cover_uri
  8. assert shot_data.mds_url == self.mds_url
  9. assert shot_data.shot_text == self.shot_text
  10. assert shot_data.shot_type == shot_type
  11. def test_de_json_none(self, client):
  12. assert ShotData.de_json({}, client) is None
  13. def test_de_json_required(self, client, shot_type):
  14. json_dict = {
  15. 'cover_uri': self.cover_uri,
  16. 'mds_url': self.mds_url,
  17. 'shot_text': self.shot_text,
  18. 'shot_type': shot_type.to_dict(),
  19. }
  20. shot_data = ShotData.de_json(json_dict, client)
  21. assert shot_data.cover_uri == self.cover_uri
  22. assert shot_data.mds_url == self.mds_url
  23. assert shot_data.shot_text == self.shot_text
  24. assert shot_data.shot_type == shot_type
  25. def test_de_json_all(self, client, shot_type):
  26. json_dict = {
  27. 'cover_uri': self.cover_uri,
  28. 'mds_url': self.mds_url,
  29. 'shot_text': self.shot_text,
  30. 'shot_type': shot_type.to_dict(),
  31. }
  32. shot_data = ShotData.de_json(json_dict, client)
  33. assert shot_data.cover_uri == self.cover_uri
  34. assert shot_data.mds_url == self.mds_url
  35. assert shot_data.shot_text == self.shot_text
  36. assert shot_data.shot_type == shot_type
  37. def test_equality(self, shot_type):
  38. a = ShotData(self.cover_uri, self.mds_url, self.shot_text, shot_type)
  39. b = ShotData('', self.mds_url, self.shot_text, shot_type)
  40. c = ShotData(self.cover_uri, '', self.shot_text, shot_type)
  41. d = ShotData(self.cover_uri, self.mds_url, self.shot_text, shot_type)
  42. assert a != b != c != d
  43. assert hash(a) != hash(b) != hash(c) != hash(d)
  44. assert a is not b is not c is not d
  45. assert a == d
  46. assert hash(a) == hash(d)