Пример #1
0
    def testAddWithoutTicket(self):
        """
        Test that the user cannot add a ticket to a raffle if they don't have any tickets.
        """
        raffle_prize = RafflePrize(
            title="Test raffle prize",
            description="A raffle prize for testing",
            round=RoundSetting.objects.get(name="Round 1"),
            value=5,
        )
        raffle_prize.save()

        # Test adding a ticket.
        response = self.client.post(reverse("raffle_add_ticket", args=(raffle_prize.id,)),
            follow=True)
        self.failUnlessEqual(response.status_code, 200)
        self.assertContains(response,
            "Your Total Raffle Tickets: <em class=\"raffle-ticket-num\">0</em>",
            msg_prefix="User should have no tickets available")
        self.assertContains(response,
            "Allocated:  <em class=\"raffle-ticket-num\">0</em>,",
            msg_prefix="User should have no tickets available")
        self.assertContains(response,
            "Available: <em class=\"raffle-ticket-num\">0</em>",
            msg_prefix="User should have no tickets available")
        self.assertNotContains(response, reverse("raffle_add_ticket", args=(raffle_prize.id,)),
            msg_prefix="There should not be a url to add a ticket.")
        self.assertNotContains(response, reverse("raffle_remove_ticket", args=(raffle_prize.id,)),
            msg_prefix="There should not be a url to remove a ticket.")
Пример #2
0
    def testIndex(self):
        """Check that we can load the index page."""
        raffle_prize = RafflePrize(
            title="Test raffle prize",
            description="A raffle prize for testing",
            round=RoundSetting.objects.get(name="Round 3"),
            value=5,
        )
        raffle_prize.save()

        response = self.client.get(reverse("win_index"))
        self.failUnlessEqual(response.status_code, 200)
        self.assertContains(
            response,
            "Round 2 Raffle",
            msg_prefix="We should be in round 2 of the raffle.")
        print response
        self.assertContains(
            response,
            "Your Total Raffle Tickets: <em class=\"raffle-ticket-num\">0</em>,",
            msg_prefix="User should not have any raffle tickets.")
        self.assertContains(
            response,
            "Allocated:  <em class=\"raffle-ticket-num\">0</em>,",
            msg_prefix="User should not have any raffle tickets.")
        self.assertContains(
            response,
            "Available: <em class=\"raffle-ticket-num\">0</em>",
            msg_prefix="User should not have any raffle tickets.")
        deadline = challenge_mgr.get_round_info()["end"]
        date_string = deadline.strftime("%b. %d, %Y, %I:%M ")
        date_string = re.sub(r" \b0", " ", date_string)
        #self.assertContains(response, "Deadline for Round 2 submissions: " + date_string,
        #    msg_prefix="Raffle should have the correct deadline.")

        # Give the user some points and see if their tickets update.
        profile = self.user.get_profile()
        profile.add_points(25, datetime.datetime.today(), "test")
        profile.save()
        response = self.client.get(reverse("win_index"))
        self.assertContains(
            response,
            "Your Total Raffle Tickets: <em class=\"raffle-ticket-num\">1</em>",
            msg_prefix="User should have 1 raffle ticket.")
        self.assertContains(
            response,
            "Allocated:  <em class=\"raffle-ticket-num\">0</em>,",
            msg_prefix="User should have 1 raffle ticket.")
        self.assertContains(
            response,
            "Available: <em class=\"raffle-ticket-num\">1</em>",
            msg_prefix="User should have 1 raffle ticket.")
Пример #3
0
    def testPrizeOutsideOfRound(self):
        """
        Test that a raffle prize outside of the round does not appear in the list.
        """

        raffle_prize = RafflePrize(
            title="Test raffle prize",
            description="A raffle prize for testing",
            round=RoundSetting.objects.get(name="Round 1"),
            value=5,
        )
        raffle_prize.save()

        response = self.client.get(reverse("win_index"))
        self.failUnlessEqual(response.status_code, 200)
        self.assertNotContains(response, "Test raffle prize")
Пример #4
0
    def setUp(self):
        """
        Sets up a test individual prize for the rest of the tests.
        This prize is not saved, as the round field is not yet set.
        """

        test_utils.set_competition_round()

        # Create a test user
        self.user = User.objects.create_user("user",
                                             "*****@*****.**",
                                             password="******")

        image_path = os.path.join(settings.PROJECT_ROOT, "fixtures",
                                  "test_images", "test.jpg")
        image = ImageFile(open(image_path, "r"))
        self.prize = RafflePrize(
            title="Super prize!",
            description="A test prize",
            image=image,
            round=RoundSetting.objects.get(name="Round 1"),
            value=5,
        )
Пример #5
0
    def testAllocatedTicket(self):
        """
        Test that allocated_ticket works.
        """
        # Create a raffle prize.
        r = RoundSetting.objects.get(name="Round 1")
        prize = RafflePrize(
            title="Super prize!",
            description="A test prize",
            round=r,
            value=5,
        )
        prize.save()

        # Test within context of a quest
        self.quest.unlock_conditions = "allocated_raffle_ticket()"
        self.quest.save()
        quests = get_quests(self.user)
        self.assertTrue(
            self.quest not in quests["available_quests"],
            "User should not be able to participate in this quest.")

        self.quest.unlock_conditions = "not allocated_raffle_ticket()"
        self.quest.completion_conditions = "allocated_raffle_ticket()"
        self.quest.save()
        quests = get_quests(self.user)
        self.assertTrue(self.quest in quests["available_quests"],
                        "User should be able to participate in this quest.")
        self.quest.accept(self.user)

        # Add a raffle ticket and test that the user completed the quest.
        ticket = RaffleTicket(raffle_prize=prize, user=self.user)
        ticket.save()
        completed_quests = possibly_completed_quests(self.user)
        self.assertTrue(self.quest in completed_quests,
                        "User should have completed the quest.")
Пример #6
0
    def testAddRemoveTicket(self):
        """Test that we can add and remove a ticket for a prize."""
        raffle_prize = RafflePrize(
            title="Test raffle prize",
            description="A raffle prize for testing",
            round=RoundSetting.objects.get(name="Round 2"),
            value=5,
        )
        raffle_prize.save()

        profile = self.user.get_profile()
        profile.add_points(25, datetime.datetime.today(), "test")
        profile.save()

        # Test that we can add a ticket.
        response = self.client.get(reverse("win_index"))
        self.assertContains(
            response,
            reverse("raffle_add_ticket", args=(raffle_prize.id, )),
            msg_prefix="There should be a url to add a ticket.")

        # Test adding a ticket to a prize.
        response = self.client.post(reverse("raffle_add_ticket",
                                            args=(raffle_prize.id, )),
                                    follow=True)
        self.failUnlessEqual(response.status_code, 200)
        self.assertContains(
            response,
            "Your Total Raffle Tickets: <em class=\"raffle-ticket-num\">1</em>",
            msg_prefix="User should have one allocated ticket.")
        self.assertContains(
            response,
            "Allocated:  <em class=\"raffle-ticket-num\">1</em>,",
            msg_prefix="User should have one allocated ticket.")
        self.assertContains(
            response,
            "Available: <em class=\"raffle-ticket-num\">0</em>",
            msg_prefix="User should have one allocated ticket.")
        self.assertContains(
            response,
            reverse("raffle_remove_ticket", args=(raffle_prize.id, )),
            msg_prefix="There should be an url to remove a ticket.")
        self.assertNotContains(
            response,
            reverse("raffle_add_ticket", args=(raffle_prize.id, )),
            msg_prefix="There should not be an url to add a ticket.")

        # Test adding another ticket to the prize.
        profile.add_points(25, datetime.datetime.today(), "test")
        profile.save()
        response = self.client.post(reverse("raffle_add_ticket",
                                            args=(raffle_prize.id, )),
                                    follow=True)
        self.assertContains(
            response,
            "Your Total Raffle Tickets: <em class=\"raffle-ticket-num\">2</em>",
            msg_prefix="User should have two allocated tickets.")
        self.assertContains(
            response,
            "Allocated:  <em class=\"raffle-ticket-num\">2</em>,",
            msg_prefix="User should have two allocated tickets.")
        self.assertContains(
            response,
            "Available: <em class=\"raffle-ticket-num\">0</em>",
            msg_prefix="User should have two allocated tickets.")

        # Test removing a ticket.
        response = self.client.post(reverse("raffle_remove_ticket",
                                            args=(raffle_prize.id, )),
                                    follow=True)
        self.assertContains(
            response,
            "Your Total Raffle Tickets: <em class=\"raffle-ticket-num\">2</em>",
            msg_prefix=
            "User should have one allocated ticket and one available.")
        self.assertContains(
            response,
            "Allocated:  <em class=\"raffle-ticket-num\">1</em>,",
            msg_prefix=
            "User should have one allocated ticket and one available.")
        self.assertContains(
            response,
            "Available: <em class=\"raffle-ticket-num\">1</em>",
            msg_prefix=
            "User should have one allocated ticket and one available.")
        self.assertContains(
            response,
            reverse("raffle_add_ticket", args=(raffle_prize.id, )),
            msg_prefix="There should be a url to add a ticket.")
        self.assertContains(
            response,
            reverse("raffle_remove_ticket", args=(raffle_prize.id, )),
            msg_prefix="There should be an url to remove a ticket.")