123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- from decimal import Decimal
- from django.contrib.auth.models import User
- from django.test import TestCase
- from catalog.constants import INSTATE, REGULAR
- from catalog.models import Book, Movie, Map, Subscription
- class ItemFixture(TestCase):
- @property
- def data(self):
- # basic item data
- return {
- "title": "mytitle",
- "description": "mydescription",
- "synopsis": "mysynopsis",
- # todo image
- "price": Decimal(5.00),
- "shipping_cost": Decimal(5.00),
- "shipping_cost_multiple": 1,
- "created_by": self.user,
- "last_updated_by": self.user,
- }
- @property
- def user(self):
- return User.objects.get_or_create(username="test_user")[0]
- class BookFixture(ItemFixture):
- @property
- def book_data(self):
- data = self.data
- data.update(
- {
- "authors": "john",
- "illustrator": "john",
- "publisher": "john",
- "printer": "john",
- "publish_date": "2007",
- "edition": "first",
- "features": "my features",
- "dimensions": '46"x25"',
- "pages": 433,
- "isbn": "123456789",
- "library_of_congress_number": "987654321",
- "genre": "horror",
- }
- )
- return data
- class IsValidBook(BookFixture):
- def setUp(self):
- self.result = Book.objects.get_or_create(defaults=self.book_data)[0]
- def test(self):
- self.assertIsNotNone(self.result)
- class MovieFixture(ItemFixture):
- @property
- def movie_data(self):
- data = self.data
- data.update(
- {
- "producer": "john",
- "music": "john",
- "runtime_minutes": 120,
- "format": "john",
- "region": "US",
- "sound": "yes",
- "language": "english",
- "captioning": "english",
- "genre": "horror",
- }
- )
- return data
- class IsValidMovie(MovieFixture):
- def setUp(self):
- self.result = Movie.objects.get_or_create(defaults=self.movie_data)
- def test(self):
- self.assertIsNotNone(self.result)
- class MapFixture(ItemFixture):
- @property
- def map_data(self):
- data = self.data
- data.update({"dimensions": '46"x25"'})
- return data
- class IsValidMap(MapFixture):
- def setUp(self):
- self.result = Map.objects.get_or_create(defaults=self.map_data)
- def test(self):
- self.assertIsNotNone(self.result)
- class SubscriptionFixture(ItemFixture):
- @property
- def subscription_data(self):
- data = self.data
- data.update(
- {"shipping_type": INSTATE, "shipping_method": REGULAR, "duration": 9}
- )
- return data
- class IsValidSubscription(SubscriptionFixture):
- def setUp(self):
- self.result = Subscription.objects.get_or_create(
- defaults=self.subscription_data
- )[0]
- def test(self):
- self.assertIsNotNone(self.result)
|