test_download_info.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import pytest
  2. from yandex_music import DownloadInfo
  3. @pytest.fixture(scope='class')
  4. def download_info():
  5. return DownloadInfo(
  6. TestDownloadInfo.codec,
  7. TestDownloadInfo.bitrate_in_kbps,
  8. TestDownloadInfo.gain,
  9. TestDownloadInfo.preview,
  10. TestDownloadInfo.download_info_url,
  11. TestDownloadInfo.direct,
  12. )
  13. class TestDownloadInfo:
  14. codec = 'mp3'
  15. bitrate_in_kbps = 192
  16. gain = False
  17. preview = False
  18. download_info_url = (
  19. 'https://storage.mds.yandex.net/file-download-info/136146_d158926e.14534319.6.10994777/320'
  20. '?sign=8caf5ea72c946d4753f15298e4033b961c7acb1bb4db48eb5e6b59621e387d64&ts=5dc4a6f2 '
  21. )
  22. direct = False
  23. def test_expected_values(self, download_info):
  24. assert download_info.codec == self.codec
  25. assert download_info.bitrate_in_kbps == self.bitrate_in_kbps
  26. assert download_info.gain == self.gain
  27. assert download_info.preview == self.preview
  28. assert download_info.download_info_url == self.download_info_url
  29. assert download_info.direct == self.direct
  30. def test_de_json_none(self, client):
  31. assert DownloadInfo.de_json({}, client) is None
  32. def test_de_list_none(self, client):
  33. assert DownloadInfo.de_list([], client) == []
  34. def test_de_json_required(self, client):
  35. json_dict = {
  36. 'codec': self.codec,
  37. 'bitrate_in_kbps': self.bitrate_in_kbps,
  38. 'gain': self.gain,
  39. 'preview': self.preview,
  40. 'download_info_url': self.download_info_url,
  41. 'direct': self.direct,
  42. }
  43. download_info = DownloadInfo.de_json(json_dict, client)
  44. assert download_info.codec == self.codec
  45. assert download_info.bitrate_in_kbps == self.bitrate_in_kbps
  46. assert download_info.gain == self.gain
  47. assert download_info.preview == self.preview
  48. assert download_info.download_info_url == self.download_info_url
  49. assert download_info.direct == self.direct
  50. def test_de_json_all(self, client):
  51. json_dict = {
  52. 'codec': self.codec,
  53. 'bitrate_in_kbps': self.bitrate_in_kbps,
  54. 'gain': self.gain,
  55. 'preview': self.preview,
  56. 'download_info_url': self.download_info_url,
  57. 'direct': self.direct,
  58. }
  59. download_info = DownloadInfo.de_json(json_dict, client)
  60. assert download_info.codec == self.codec
  61. assert download_info.bitrate_in_kbps == self.bitrate_in_kbps
  62. assert download_info.gain == self.gain
  63. assert download_info.preview == self.preview
  64. assert download_info.download_info_url == self.download_info_url
  65. assert download_info.direct == self.direct
  66. def test_equality(self):
  67. a = DownloadInfo(self.codec, self.bitrate_in_kbps, self.gain, self.preview, self.download_info_url, self.direct)
  68. b = DownloadInfo(self.codec, 128, self.gain, True, self.download_info_url, True)
  69. c = DownloadInfo(self.codec, self.bitrate_in_kbps, self.gain, self.preview, self.download_info_url, self.direct)
  70. assert a != b
  71. assert hash(a) != hash(b)
  72. assert a is not b
  73. assert a == c