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)