Exemple #1
0
    def testPrizeOutsideOfRound(self):
        """
    Test that a raffle prize outside of the round does not appear in the list."""
        deadline = RaffleDeadline(
            round_name="Round 1",
            pub_date=datetime.datetime.today() - datetime.timedelta(days=7),
            end_date=datetime.datetime.today() - datetime.timedelta(days=1),
        )
        deadline.save()
        raffle_prize = RafflePrize(
            title="Test raffle prize",
            description="A raffle prize for testing",
            deadline=deadline,
            value=5,
        )
        raffle_prize.save()
        response = self.client.get(reverse("prizes_index"))
        self.failUnlessEqual(response.status_code, 200)
        self.assertNotContains(response, "Test raffle prize")

        # Try allocating a ticket to this prize.
        response = self.client.post(reverse("raffle_add_ticket",
                                            args=(raffle_prize.id, )),
                                    follow=True)
        self.failUnlessEqual(response.status_code, 200)
        self.assertContains(response, "The raffle for this round is over.")
Exemple #2
0
    def setUp(self):
        """Set up rounds, floor, and a user."""
        # Set up rounds.
        self.saved_rounds = settings.COMPETITION_ROUNDS
        self.saved_start = settings.COMPETITION_START
        self.saved_end = settings.COMPETITION_END
        start = datetime.date.today() - datetime.timedelta(days=8)
        end1 = start + datetime.timedelta(days=7)
        end2 = start + datetime.timedelta(days=14)

        settings.COMPETITION_ROUNDS = {
            "Round 1": {
                "start": start.strftime("%Y-%m-%d"),
                "end": end1.strftime("%Y-%m-%d"),
            },
            "Round 2": {
                "start": end1.strftime("%Y-%m-%d"),
                "end": end2.strftime("%Y-%m-%d"),
            },
        }
        settings.COMPETITION_START = start.strftime("%Y-%m-%d")
        settings.COMPETITION_END = end2.strftime("%Y-%m-%d")

        # Set up user
        self.user = User.objects.create_user("user",
                                             "*****@*****.**",
                                             password="******")
        floor = Floor.objects.all()[0]
        profile = self.user.get_profile()
        profile.floor = floor
        profile.setup_complete = True
        profile.setup_profile = True
        profile.save()

        self.client.login(username="******", password="******")

        # Set up raffle deadline
        self.deadline = RaffleDeadline(
            round_name="Round 2",
            pub_date=datetime.datetime.today() - datetime.timedelta(hours=1),
            end_date=datetime.datetime.today() + datetime.timedelta(days=5),
        )
        self.deadline.save()
Exemple #3
0
 def testAllocatedTicket(self):
   """
   Test that allocated_ticket works.
   """
   # Create a raffle prize.
   deadline = RaffleDeadline(
       round_name="Overall", 
       pub_date=datetime.datetime.today() - datetime.timedelta(hours=1),
       end_date=datetime.datetime.today() + datetime.timedelta(days=5),
   )
   deadline.save()
   prize = RafflePrize(
       title="Super prize!",
       description="A test prize",
       deadline=deadline,
       value=5,
   )
   prize.save()
   
   # Test within context of a quest
   self.quest.unlock_conditions = "allocated_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_ticket()"
   self.quest.completion_conditions = "allocated_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.")
Exemple #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.
   """
   self.saved_rounds = settings.COMPETITION_ROUNDS
   start = datetime.date.today()
   end = start + datetime.timedelta(days=7)
   
   settings.COMPETITION_ROUNDS = {
     "Round 1" : {
       "start": start.strftime("%Y-%m-%d"),
       "end": end.strftime("%Y-%m-%d"),
     },
   }
   
   # Create a test user
   self.user = User.objects.create_user("user", "*****@*****.**", password="******")
   
   # Set up raffle deadline
   self.deadline = RaffleDeadline(
       round_name="Round 1", 
       pub_date=datetime.datetime.today() - datetime.timedelta(hours=1),
       end_date=datetime.datetime.today() + datetime.timedelta(days=5),
   )
   self.deadline.save()
   
   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,
       value=5,
       deadline=self.deadline,
   )