Example #1
0
def setup_round_prize(round_name, award_to, competition_type):
    """set the prize for testing"""
    prize = Prize(
        title="Super prize!",
        short_description="A test prize",
        long_description="A test prize",
        award_to=award_to,
        round=RoundSetting.objects.get(name=round_name),
        competition_type=competition_type,
        value=5,
    )
    prize.save()
    return prize
def setup_round_prize(round_name, award_to, competition_type):
    """set the prize for testing"""
    prize = Prize(
        title="Super prize!",
        short_description="A test prize",
        long_description="A test prize",
        award_to=award_to,
        round=RoundSetting.objects.get(name=round_name),
        competition_type=competition_type,
        value=5,
        )
    prize.save()
    return prize
def setup_prize(award_to, competition_type):
    """set the prize for testing"""
    image_path = os.path.join(settings.PROJECT_ROOT, "fixtures", "test_images", "test.jpg")
    image = ImageFile(open(image_path, "r"))
    prize = Prize(
        title="Super prize!",
        short_description="A test prize",
        long_description="A test prize",
        image=image,
        award_to=award_to,
        competition_type=competition_type,
        value=5,
        )
    prize.save()
    return prize
Example #4
0
def setup_prize(award_to, competition_type):
    """set the prize for testing"""
    image_path = os.path.join(settings.PROJECT_ROOT, "fixtures", "test_images",
                              "test.jpg")
    image = ImageFile(open(image_path, "r"))
    prize = Prize(
        title="Super prize!",
        short_description="A test prize",
        long_description="A test prize",
        image=image,
        award_to=award_to,
        competition_type=competition_type,
        value=5,
    )
    prize.save()
    return prize
Example #5
0
    def testConstraints(self):
        """
        Tests that the uniqueness constraints are enforced.
        A prize with the same round_name, award_to, and competition_type as another cannot be created.
        """

        image_path = os.path.join(settings.PROJECT_ROOT, "fixtures",
                                  "test_images", "test.jpg")
        image = ImageFile(open(image_path, "r"))
        prize = Prize(
            round=RoundSetting.objects.get(name="Round 1"),
            title="Super prize!",
            image=image,
            award_to="individual_overall",
            competition_type="points",
            short_description="A test prize",
            long_description="A test prize",
            value=5,
        )

        prize.save()

        prize2 = Prize(
            title="Dup prize!",
            short_description="A test prize",
            long_description="A test prize",
            image=image,
            award_to="individual_overall",
            competition_type="points",
            round=RoundSetting.objects.get(name="Round 1"),
            value=5,
        )

        prize2.round = RoundSetting.objects.get(name="Round 1")
        prize2.competition_type = "energy"
        try:
            prize2.save()
        except IntegrityError:
            self.fail("IntegrityError exception should not be thrown.")

        prize2.competition_type = "points"
        prize2.award_to = "team_overall"
        try:
            prize2.save()
        except IntegrityError:
            self.fail("IntegrityError exception should not be thrown.")

        prize2.round = RoundSetting.objects.get(name="Round 1")
        prize2.competition_type = "points"
        prize2.award_to = "individual_overall"
        try:
            prize2.save()
            # Make sure to clean up!
            prize.image.delete()
            prize.delete()
            prize2.image.delete()
            prize2.delete()
            self.fail("IntegrityError exception not thrown.")
        except IntegrityError:
            transaction.rollback()
Example #6
0
    def testConstraints(self):
        """
        Tests that the uniqueness constraints are enforced.
        A prize with the same round_name, award_to, and competition_type as another cannot be created.
        """
        image_path = os.path.join(settings.PROJECT_ROOT, "fixtures", "test_images", "test.jpg")
        image = ImageFile(open(image_path, "r"))
        prize = Prize(
            round_name="Round 1",
            title="Super prize!",
            image=image,
            award_to="individual_overall",
            competition_type="points",
            short_description="A test prize",
            long_description="A test prize",
            value=5,
        )

        prize.save()

        prize2 = Prize(
            title="Dup prize!",
            short_description="A test prize",
            long_description="A test prize",
            image=image,
            award_to="individual_overall",
            competition_type="points",
            round_name="Round 1",
            value=5,
        )

        prize2.round_name = "Round 1"
        prize2.competition_type = "energy"
        try:
            prize2.save()
        except IntegrityError:
            self.fail("IntegrityError exception should not be thrown.")

        prize2.competition_type = "points"
        prize2.award_to = "team_overall"
        try:
            prize2.save()
        except IntegrityError:
            self.fail("IntegrityError exception should not be thrown.")

        prize2.round_name = "Round 1"
        prize2.competition_type = "points"
        prize2.award_to = "individual_overall"
        try:
            prize2.save()
            # Make sure to clean up!
            prize.image.delete()
            prize.delete()
            prize2.image.delete()
            prize2.delete()
            self.fail("IntegrityError exception not thrown.")
        except IntegrityError:
            transaction.rollback()