def test_can_not_create_suggestion_admin_page_without_suggestion_foreign_key(self):
     """
     Test to check that a SuggestionAdminPage object can not be created
     without a suggestion value
     """
     with self.assertRaises(IntegrityError):
         without_suggestion = SuggestionAdminPage()
         without_suggestion.save()
    def test_suggestion_admin_page_defaults_correctly(self):
        """
        Test to check that if unspecified, a SuggestionAdminPage object defaults
        the following values: status:0, priority:1, in_current_voting_cycle:True,
        current_winner:False
        """
        all_suggestions = Suggestion.objects.all()
        random_suggestion = choice(all_suggestions)

        new_suggestion_admin_object = SuggestionAdminPage(suggestion=random_suggestion)
        new_suggestion_admin_object.save()

        self.assertEqual(new_suggestion_admin_object.status, 0)
        self.assertEqual(new_suggestion_admin_object.priority, 1)
        self.assertEqual(new_suggestion_admin_object.in_current_voting_cycle, True)
        self.assertEqual(new_suggestion_admin_object.current_winner, False)
Exemplo n.º 3
0
    def test_can_get_userpage_values(self):
        """
        Test that get_userpage_values retrieves a dictionary with
        the votes, purchases, coin_history, and SuggestionAdminPages
        for that user
        """
        new_user = User(username="******", email="*****@*****.**", password="******")
        new_user.save()

        suggestion_1 = Suggestion(is_feature=True, user=new_user, title="Userpage suggestion 1",
                                  details="Any old details", delay_submission=False)
        suggestion_1.save()
        suggestion_2 = Suggestion(is_feature=True, user=new_user, title="Userpage suggestion 2",
                                  details="Any old details")
        suggestion_2.save()

        suggestion_admin_1 = SuggestionAdminPage(suggestion=suggestion_1)
        suggestion_admin_1.save()
        suggestion_admin_2 = SuggestionAdminPage(suggestion=suggestion_2)
        suggestion_admin_2.save()

        for i in range(5):
            random_suggestion = choice(Suggestion.objects.all())
            upvote = Upvote(suggestion=random_suggestion, user=new_user)
            upvote.save()

            random_coin_transaction = choice(range(1, 10))
            coin_history_entry = UserCoinHistory(user=new_user, coins_change=1, transaction=random_coin_transaction)
            coin_history_entry.save()

            order = Order(user=new_user)
            order.save()
            random_store_item = choice(StoreItem.objects.all())
            order_item = OrderItem(order=order, item=random_store_item, quantity=1, total_purchase_price=1)
            order_item.save()

        userpage_values = get_userpage_values(new_user)

        self.assertEqual(len(userpage_values["coin_history"]), 5)

        random_purchase = choice(userpage_values["purchases"])
        self.assertTrue(isinstance(random_purchase, Order))
        random_coin_history = choice(userpage_values["coin_history"])
        self.assertTrue(isinstance(random_coin_history, UserCoinHistory))
        random_vote = choice(userpage_values["votes"])
        self.assertTrue(isinstance(random_vote, Upvote))
        random_suggestion_admin = choice(userpage_values["suggestions"])
        self.assertTrue(isinstance(random_suggestion_admin, SuggestionAdminPage))
Exemplo n.º 4
0
    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()

        for i in range(15):
            suggestion = Suggestion(is_feature=True,
                                    user=user_1,
                                    title="For populating chart",
                                    details="Blah blah blah ")
            suggestion.save()
            random_day_in_june = choice(range(1, 31))
            date_completed = datetime.date(2018, 6, random_day_in_june)
            admin_page = SuggestionAdminPage(suggestion=suggestion,
                                             date_completed=date_completed)
            admin_page.save()

        for i in range(40):
            random_suggestion = choice(Suggestion.objects.all())
            upvote = Upvote(user=user_2, suggestion=random_suggestion)
            upvote.save()

        for i in range(10):
            bug = Suggestion(is_feature=False,
                             user=user_1,
                             title="For populating chart",
                             details="Blah blah blah ")
            bug.save()
            random_day_in_june = choice(range(1, 31))
            date_completed = datetime.date(2018, 6, random_day_in_june)
            admin_page = SuggestionAdminPage(suggestion=bug,
                                             date_completed=date_completed)
            admin_page.save()

        for i in range(30):
            random_coin_transaction = choice([1, 2, 9, 3])
            coin_history_entry = UserCoinHistory(
                user=user_1,
                coins_change=(0 - random_coin_transaction),
                transaction=random_coin_transaction)
            coin_history_entry.save()
Exemplo n.º 5
0
    def setUpTestData(cls):

        user_1 = User(username="******")
        user_1.save()
        user_2 = User(username="******", email="*****@*****.**")
        user_2.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(id=2,
                                  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=False,
                                                 user=user_2,
                                                 title="Test Suggestion 3",
                                                 details="Any old details",
                                                 delay_submission=False)
        suggestion_3.save()
        suggestion_4 = Suggestion.objects.create(is_feature=True,
                                                 user=user_1,
                                                 title="Test Suggestion 4",
                                                 details="Any old details",
                                                 delay_submission=False)
        suggestion_4.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)
        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()
Exemplo n.º 6
0
    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()