model_tests.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. from decimal import Decimal
  2. from django.contrib.auth.models import User
  3. from django.test import TestCase
  4. from catalog.constants import INSTATE, REGULAR
  5. from catalog.models import Book, Movie, Map, Subscription
  6. class ItemFixture(TestCase):
  7. @property
  8. def data(self):
  9. # basic item data
  10. return {
  11. "title": "mytitle",
  12. "description": "mydescription",
  13. "synopsis": "mysynopsis",
  14. # todo image
  15. "price": Decimal(5.00),
  16. "shipping_cost": Decimal(5.00),
  17. "shipping_cost_multiple": 1,
  18. "created_by": self.user,
  19. "last_updated_by": self.user,
  20. }
  21. @property
  22. def user(self):
  23. return User.objects.get_or_create(username="test_user")[0]
  24. class BookFixture(ItemFixture):
  25. @property
  26. def book_data(self):
  27. data = self.data
  28. data.update(
  29. {
  30. "authors": "john",
  31. "illustrator": "john",
  32. "publisher": "john",
  33. "printer": "john",
  34. "publish_date": "2007",
  35. "edition": "first",
  36. "features": "my features",
  37. "dimensions": '46"x25"',
  38. "pages": 433,
  39. "isbn": "123456789",
  40. "library_of_congress_number": "987654321",
  41. "genre": "horror",
  42. }
  43. )
  44. return data
  45. class IsValidBook(BookFixture):
  46. def setUp(self):
  47. self.result = Book.objects.get_or_create(defaults=self.book_data)[0]
  48. def test(self):
  49. self.assertIsNotNone(self.result)
  50. class MovieFixture(ItemFixture):
  51. @property
  52. def movie_data(self):
  53. data = self.data
  54. data.update(
  55. {
  56. "producer": "john",
  57. "music": "john",
  58. "runtime_minutes": 120,
  59. "format": "john",
  60. "region": "US",
  61. "sound": "yes",
  62. "language": "english",
  63. "captioning": "english",
  64. "genre": "horror",
  65. }
  66. )
  67. return data
  68. class IsValidMovie(MovieFixture):
  69. def setUp(self):
  70. self.result = Movie.objects.get_or_create(defaults=self.movie_data)
  71. def test(self):
  72. self.assertIsNotNone(self.result)
  73. class MapFixture(ItemFixture):
  74. @property
  75. def map_data(self):
  76. data = self.data
  77. data.update({"dimensions": '46"x25"'})
  78. return data
  79. class IsValidMap(MapFixture):
  80. def setUp(self):
  81. self.result = Map.objects.get_or_create(defaults=self.map_data)
  82. def test(self):
  83. self.assertIsNotNone(self.result)
  84. class SubscriptionFixture(ItemFixture):
  85. @property
  86. def subscription_data(self):
  87. data = self.data
  88. data.update(
  89. {"shipping_type": INSTATE, "shipping_method": REGULAR, "duration": 9}
  90. )
  91. return data
  92. class IsValidSubscription(SubscriptionFixture):
  93. def setUp(self):
  94. self.result = Subscription.objects.get_or_create(
  95. defaults=self.subscription_data
  96. )[0]
  97. def test(self):
  98. self.assertIsNotNone(self.result)