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( title="Super 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, ) 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, ) try: prize2.save() self.fail("IntegrityError exception not thrown.") except IntegrityError: pass prize2.round_name = "Overall" try: prize2.save() except IntegrityError: self.fail("IntegrityError exception should not be thrown.") 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 = "floor_overall" try: prize2.save() except IntegrityError: self.fail("IntegrityError exception should not be thrown.") # Make sure to clean up! prize.image.delete() prize.delete() prize2.image.delete() prize2.delete()
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. """ image_path = os.path.join(settings.PROJECT_ROOT, "fixtures", "test_images", "test.jpg") image = ImageFile(open(image_path, "r")) self.prize = Prize( title="Super prize!", short_description="A test prize", long_description="A test prize", image=image, award_to="individual_overall", competition_type="points", value=5, ) self.saved_rounds = settings.COMPETITION_ROUNDS self.current_round = "Round 1" 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 test users. self.users = [ User.objects.create_user("test%d" % i, "*****@*****.**") for i in range(0, 3) ]
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. """ image_path = os.path.join(settings.PROJECT_ROOT, "fixtures", "test_images", "test.jpg") image = ImageFile(open(image_path, "r")) self.prize = Prize( title="Super prize!", short_description="A test prize", long_description="A test prize", image=image, award_to="individual_floor", competition_type="points", value=5, ) self.saved_rounds = settings.COMPETITION_ROUNDS self.current_round = "Round 1" 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 test dorms, floors, and users. self.dorm = Dorm(name="Test Dorm") self.dorm.save() self.floors = [ Floor(number=str(i), dorm=self.dorm) for i in range(0, 2) ] map(lambda f: f.save(), self.floors) self.users = [ User.objects.create_user("test%d" % i, "*****@*****.**") for i in range(0, 4) ] # Assign users to floors. for index, user in enumerate(self.users): user.get_profile().floor = self.floors[index % 2] user.get_profile().save()