test_release.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. from collections import namedtuple
  2. from datetime import datetime
  3. import json
  4. import os
  5. import unittest
  6. from yarg.package import json2package
  7. from yarg.release import Release
  8. class TestRelease(unittest.TestCase):
  9. def setUp(self):
  10. package = os.path.join(os.path.dirname(__file__),
  11. 'package.json')
  12. self.json = json.loads(open(package).read())
  13. self.package = json2package(open(package).read())
  14. def test_release_ids(self):
  15. self.assertEquals([u'0.0.0', u'0.0.2', u'0.0.15'],
  16. self.package.release_ids)
  17. def test_release(self):
  18. release_id = '0.0.2'
  19. release = self.json['releases'][release_id]
  20. release_list = [Release(release_id, r) for r in release]
  21. self.assertEquals(release_list[0].md5_digest,
  22. self.package.release(release_id)[0].md5_digest)
  23. self.assertEquals(release_list[1].md5_digest,
  24. self.package.release(release_id)[1].md5_digest)
  25. self.assertEquals('3e3098611177c34706de2e10476b3e50',
  26. self.package.release(release_id)[0].md5_digest)
  27. self.assertEquals('be198baa95116c1c9d17874428e3a0c6',
  28. self.package.release(release_id)[1].md5_digest)
  29. def test_repr(self):
  30. release_id = '0.0.2'
  31. release = self.package.release(release_id)[0]
  32. self.assertEquals(u'<Release 0.0.2>', release.__repr__())
  33. def test_release_id(self):
  34. release_id = '0.0.2'
  35. release = self.package.release(release_id)[0]
  36. self.assertEquals(release_id, release.release_id)
  37. def test_release_id(self):
  38. release_id = '0.0.3'
  39. release = self.package.release(release_id)
  40. self.assertEquals(None, release)
  41. def test_release_uploaded(self):
  42. release_id = '0.0.2'
  43. release = self.package.release(release_id)[0]
  44. self.assertEquals(datetime.strptime("2014-08-16T12:21:20",
  45. "%Y-%m-%dT%H:%M:%S"),
  46. release.uploaded)
  47. def test_release_python_version(self):
  48. release_id = '0.0.2'
  49. release = self.package.release(release_id)[0]
  50. self.assertEquals(u'2.7', release.python_version)
  51. def test_release_url(self):
  52. release_id = '0.0.2'
  53. release = self.package.release(release_id)[0]
  54. url = u'https://pypi.python.org/packages/2.7/y/yarg/yarg-0.0.2-py2.py3-none-any.whl'
  55. self.assertEquals(url, release.url)
  56. def test_release_md5(self):
  57. release_id = '0.0.2'
  58. release = self.package.release(release_id)[0]
  59. md5 = u'3e3098611177c34706de2e10476b3e50'
  60. self.assertEquals(md5, release.md5_digest)
  61. def test_release_filename(self):
  62. release_id = '0.0.2'
  63. release = self.package.release(release_id)[0]
  64. filename = u'yarg-0.0.2-py2.py3-none-any.whl'
  65. self.assertEquals(filename, release.filename)
  66. def test_release_size(self):
  67. release_id = '0.0.2'
  68. release = self.package.release(release_id)[0]
  69. size = 21596
  70. self.assertEquals(size, release.size)
  71. def test_release_unknown_package_type(self):
  72. release_id = '0.0.0'
  73. release = self.package.release(release_id)[0]
  74. self.assertEquals(u'wheeeel', release.package_type)
  75. def test_release_package_type(self):
  76. release_id = '0.0.2'
  77. release = self.package.release(release_id)[0]
  78. self.assertEquals(u'wheel', release.package_type)
  79. def test_release_has_sig(self):
  80. release_id = '0.0.2'
  81. release = self.package.release(release_id)[0]
  82. self.assertEquals(True, release.has_sig)
  83. def test_latest_release_id(self):
  84. self.assertEquals(u'0.0.15', self.package.latest_release_id)
  85. def test_latest_release(self):
  86. release_id = '0.0.15'
  87. release = self.json['releases'][release_id]
  88. release_list = [Release(release_id, r) for r in release]
  89. self.assertEquals(release_list[0].md5_digest,
  90. self.package.latest_release[0].md5_digest)
  91. self.assertEquals(release_list[1].md5_digest,
  92. self.package.latest_release[1].md5_digest)
  93. self.assertEquals('3e3098611177c34706de2e10476b3e51',
  94. self.package.latest_release[0].md5_digest)
  95. self.assertEquals('be198baa95116c1c9d17874428e3a0c7',
  96. self.package.latest_release[1].md5_digest)