def test_store_item_defaults_as_desired(self): """ Test to check that when creating a StoreItem, default values are assigned as follows: is_coins: False """ new_store_item = StoreItem(name="Test Defaults", description="Blank", price=12.99, delivery_required=False) new_store_item.save() retrieved_new_item = StoreItem.objects.get(name="Test Defaults") self.assertFalse(retrieved_new_item.is_coins)
def setUpTestData(cls): user_1 = User(username="******") user_1.save() user_2 = User(username="******", email="*****@*****.**") user_2.save() user_3 = User(username="******", password="******", email="*****@*****.**") user_3.save() suggestion_1 = Suggestion(is_feature=True, user=user_1, title="Test Suggestion 1", details="Any old details", delay_submission=False) suggestion_1.save() suggestion_2 = Suggestion(is_feature=True, user=user_2, title="Test Suggestion 2", details="Any old details", delay_submission=True) suggestion_2.save() suggestion_3 = Suggestion.objects.create(is_feature=True, user=user_2, title="Test Suggestion 3", details="Any old details", delay_submission=False) suggestion_3.save() user_1_usercoins = UserCoins(user=user_1, coins=100) user_1_usercoins.save() user_2_usercoins = UserCoins(user=user_2, coins=500) user_2_usercoins.save() user_3_usercoins = UserCoins(user=user_3, coins=0) user_3_usercoins.save() coins_purchase_1 = CoinsPurchase(name="coins purchase 1", coins_price=200) coins_purchase_1.save() coins_purchase_2 = CoinsPurchase(name="coins purchase 2", coins_price=500) coins_purchase_2.save() suggestion_coins_purchase = CoinsPurchase(name="Suggestion", coins_price=500) suggestion_coins_purchase.save() upvote_coins_purchase = CoinsPurchase(name="Upvote", coins_price=100) upvote_coins_purchase.save() promote_feature_purchase = CoinsPurchase( name="Feature Suggestion Promotion", coins_price=600) promote_feature_purchase.save() coins_store_item_500 = StoreItem(name="500 coins", price=0, delivery_required=False, is_coins=True, coins_amount=500) coins_store_item_500.save() coins_store_item_200 = StoreItem(name="200 coins", price=0, delivery_required=False, is_coins=True, coins_amount=200) coins_store_item_200.save() coins_store_item_1000 = StoreItem(name="1000 coins", price=0, delivery_required=False, is_coins=True, coins_amount=1000) coins_store_item_1000.save() non_coins_store_item = StoreItem(name="not coins", price=5, delivery_required=True, is_coins=False) non_coins_store_item.save()
def test_creating_store_item_requires_name_price_and_delivery_required(self): """ Test to check that a name, price, and delivery_required value need to be provided when creating a StoreItem """ with self.assertRaises(IntegrityError): with transaction.atomic(): without_name = StoreItem(price=99.99, delivery_required=True) without_name.save() with transaction.atomic(): without_price = StoreItem(name="A Name", delivery_required=False) without_price.save() with transaction.atomic(): without_delivery = StoreItem(name="Another Name", price=10.50) without_delivery.save()
def setUpTestData(cls): user_1 = User(username="******") user_1.save() user_2 = User(username="******", email="*****@*****.**") user_2.save() user_3 = User(username="******", password="******", email="*****@*****.**") user_3.save() suggestion_1 = Suggestion(is_feature=True, user=user_1, title="Test Suggestion 1", details="Any old detials", delay_submission=False) suggestion_1.save() suggestion_2 = Suggestion(is_feature=True, user=user_2, title="Test Suggestion 2", details="Any old detials", delay_submission=True) suggestion_2.save() suggestion_3 = Suggestion.objects.create(is_feature=True, user=user_2, title="Test Suggestion 3", details="Any old detials", delay_submission=False) suggestion_3.save() suggestion_4 = Suggestion.objects.create(is_feature=True, user=user_1, title="Test Suggestion 4", details="Any old detials", delay_submission=False) suggestion_4.save() suggestion_5 = Suggestion.objects.create(is_feature=False, user=user_1, title="Test Suggestion 4", details="Any old detials", delay_submission=False) suggestion_5.save() comment_1 = Comment(user=user_1, suggestion=suggestion_2, comment="test comment") comment_1.save() comment_2 = Comment(user=user_2, suggestion=suggestion_2, comment="test comment") comment_2.save() admin_page_1 = SuggestionAdminPage(suggestion=suggestion_2, current_winner=False) admin_page_1.save() admin_page_2 = SuggestionAdminPage(suggestion=suggestion_1, current_winner=False) admin_page_2.save() admin_page_3 = SuggestionAdminPage(suggestion=suggestion_3, current_winner=False) admin_page_3.save() admin_page_4 = SuggestionAdminPage(suggestion=suggestion_4, current_winner=False, in_current_voting_cycle=False) admin_page_4.save() upvote_suggestion_1_1 = Upvote(user=user_1, suggestion=suggestion_1) upvote_suggestion_1_1.save() upvote_suggestion_2_1 = Upvote(user=user_1, suggestion=suggestion_2) upvote_suggestion_2_1.save() upvote_suggestion_2_2 = Upvote(user=user_2, suggestion=suggestion_2) upvote_suggestion_2_2.save() upvote_suggestion_2_3 = Upvote(user=user_1, suggestion=suggestion_2) upvote_suggestion_2_3.save() coins_purchase_1 = CoinsPurchase(name="coins purchase 1", coins_price=200) coins_purchase_1.save() coins_purchase_2 = CoinsPurchase(name="coins purchase 2", coins_price=500) coins_purchase_2.save() suggestion_coins_purchase = CoinsPurchase(name="Suggestion", coins_price=500) suggestion_coins_purchase.save() upvote_coins_purchase = CoinsPurchase(name="Upvote", coins_price=100) upvote_coins_purchase.save() promote_feature_purchase = CoinsPurchase(name="Feature Suggestion Promotion", coins_price=600) promote_feature_purchase.save() coins_store_item_500 = StoreItem(name="500 coins", price=0, delivery_required=False, is_coins=True, coins_amount=500) coins_store_item_500.save()