def test_no_duplicate_slugs(self):
     """Make sure we can't have two competitions by the same slug"""
     c = CompetitionFactory.create(name="MegaMinerAI-Galapagos")
     c2 = CompetitionFactory.create(name="MegaMinerAI Galapagos")
     with self.assertRaises(ValidationError):
         c2.slug = c.slug
         c2.full_clean()
    def setUp(self):
        self.alice = UserFactory.create(username="******")

        self.space = CompetitionFactory.create(name="Space")
        self.galapagos = CompetitionFactory.create(name="Galapagos")

        self.space_org = OrganizerFactory.create(user=self.alice, competition=self.space)
        self.galapagos_org = OrganizerFactory.create(user=self.alice, competition=self.galapagos)
    def setUp(self):
        self.alice = UserFactory.create(username="******")
        self.space = CompetitionFactory.create(name="Space")
        self.galapagos = CompetitionFactory.create(name="Galapagos")
        self.galapagos.is_open = True
        self.galapagos.save()

        self.questions = [QuestionFactory.create(question_type=t)
                          for t in ('SA', 'MC', 'AB', 'SC')]
        self.galapagos.questions.add(*self.questions)
    def setUp(self):
        self.space = CompetitionFactory.create(name="Space")
        self.galapagos = CompetitionFactory.create(name="Galapagos")

        self.alice = UserFactory.create(username="******")
        self.bob = UserFactory.create(username="******")

        # Register Alice and Bob for Space
        self.alice_reg = RegistrationFactory.create(user=self.alice,
                                                    competition=self.space)
        self.bob_reg = RegistrationFactory.create(user=self.bob,
                                                  competition=self.space)
 def test_registrated_for_user(self):
     """List competition where a user is registered"""
     c1 = CompetitionFactory.create(name="MegaMinerAI1")
     c2 = CompetitionFactory.create(name="MegaMinerAI2")
     c3 = CompetitionFactory.create(name="MegaMinerAI3")
     alice = UserFactory.create()
     RegistrationFactory.create(user=alice, competition=c1)
     RegistrationFactory.create(user=alice, competition=c3)
     l = list(Competition.objects.user_registered(alice))
     self.assertEqual(2, len(l))
     self.assertIn(c1, l)
     self.assertIn(c3, l)
 def test_slug_stays_same(self):
     """Changing a name won't change the slug"""
     c = CompetitionFactory.create(name="MegaMinerAI-Galapagos")
     slug = c.slug
     c.name = "derp"
     c.save()
     self.assertEqual(slug, c.slug)
    def setUp(self):
        self.alice = UserFactory.create(username="******")
        self.bob = UserFactory.create(username="******")
        self.carl = UserFactory.create(username="******")

        self.space = CompetitionFactory.create(name="Space",
                                               is_open=False)
        self.galapagos = CompetitionFactory.create(name="Galapagos",
                                                   is_open=True)

        self.alice_team = TeamFactory.create(competition=self.galapagos,
                                             num_members=0)
        self.alice_team.add_team_member(self.alice)

        self.bob_team = TeamFactory.create(competition=self.galapagos,
                                           num_members=0)
        self.bob_team.add_team_member(self.bob)
    def test_positive_cost(self):
        """Cost must be greater than 0"""
        c = CompetitionFactory.build(cost=-20.3)

        with self.assertRaises(ValidationError) as cm:
            c.full_clean()

        self.assertEqual(1, len(cm.exception.message_dict))
        self.assertIn("cost", cm.exception.message_dict)
    def test_positive_max_team_size(self):
        """Team max sizes must be greater than 0"""
        c = CompetitionFactory.build(max_num_team_members=-1)

        with self.assertRaises(ValidationError) as cm:
            c.full_clean()

        self.assertEqual(2, len(cm.exception.message_dict))
        self.assertIn("max_num_team_members", cm.exception.message_dict)
    def test_name_validation(self):
        """Competition names must pass the name validator"""
        c = CompetitionFactory.build(name="{no way}")

        with self.assertRaises(ValidationError) as cm:
            c.full_clean()

        self.assertEqual(1, len(cm.exception.message_dict))
        self.assertIn("name", cm.exception.message_dict)
    def setUp(self):
        self.space = CompetitionFactory.create(name="Space")
        self.galapagos = CompetitionFactory.create(name="Galapagos")

        self.space_teams = [TeamFactory.create(competition=self.space,
                                               num_members=1)
                            for _ in range(3)]
        self.galapagos_teams = [TeamFactory.create(competition=self.galapagos,
                                                   num_members=1)
                                for _ in range(5)]
        self.alice = UserFactory.create(username="******")
        self.bob = UserFactory.create(username="******")

        # Register Alice and Bob for Space
        self.alice_reg = RegistrationFactory.create(user=self.alice,
                                                    competition=self.space)
        self.bob_reg = RegistrationFactory.create(user=self.bob,
                                                  competition=self.space)
    def test_valid_team_sizes(self):
        """Max team size must be greater than min team size"""
        c = CompetitionFactory.build(min_num_team_members=2,
                                     max_num_team_members=1)

        with self.assertRaises(ValidationError) as cm:
            c.full_clean()

        self.assertEqual(1, len(cm.exception.message_dict))
        self.assertIn("__all__", cm.exception.message_dict)
    def test_valid_start_end_times(self):
        """Start time must be before end time"""
        twelve_hours_ago = datetime.now() - TWELVE_HOURS
        c = CompetitionFactory.build(end_time=twelve_hours_ago)

        with self.assertRaises(ValidationError) as cm:
            c.full_clean()

        self.assertEqual(1, len(cm.exception.message_dict))
        self.assertIn("__all__", cm.exception.message_dict)
    def test_name_is_sluggable(self):
        """Competition names must be sluggable"""
        now = datetime.now()
        c = CompetitionFactory.build(name="..")

        with self.assertRaises(ValidationError) as cm:
            c.full_clean()

        self.assertEqual(1, len(cm.exception.message_dict))
        self.assertIn("name", cm.exception.message_dict)
    def setUp(self):
        self.space = CompetitionFactory.create(name="Space",
                                               is_running=True)

        self.space_teams = [TeamFactory.create(competition=self.space,
                                               num_members=1)
                            for _ in range(5)]
        self.alice = UserFactory.create(username="******")
        self.bob = UserFactory.create(username="******")
        self.carl = UserFactory.create(username="******")

        # Register Alice and Bob for Space
        self.alice_reg = RegistrationFactory.create(user=self.alice,
                                                    competition=self.space)
        self.bob_reg = RegistrationFactory.create(user=self.bob,
                                                  competition=self.space)

        # Add users to teams
        self.alice_team = self.space_teams[0]
        self.alice_team.members.add(self.alice)
        self.bob_team = self.space_teams[1]
        self.bob_team.members.add(self.bob)

        # Some other team
        self.other_team = self.space_teams[2]

        # Add a game between bob and alice
        g = GameFactory.create(competition=self.space)
        GameScoreFactory.create(game=g, team=self.alice_team)
        GameScoreFactory.create(game=g, team=self.bob_team)

        # Add a game between alice and not-bob
        g = GameFactory.create(competition=self.space)
        GameScoreFactory.create(game=g, team=self.alice_team)
        GameScoreFactory.create(game=g, team=self.other_team)

        for _ in range(20):
            team1, team2 = random.sample(self.space_teams, 2)
            g = GameFactory.create(competition=self.space)
            GameScoreFactory.create(game=g, team=team1)
            GameScoreFactory.create(game=g, team=team2)
 def setUp(self):
     for _ in range(0, 73):
         CompetitionFactory.create()
 def test_slug_set(self):
     """Competition slug should be set when it's saved"""
     c = CompetitionFactory.build()
     self.assertEqual('', c.slug)
     c.save()
     self.assertEqual(slugify(c.name), c.slug)
 def test_reasonable_name(self):
     """Valid competition names should pass"""
     c = CompetitionFactory.build(name="MegaMinerAI 10: -B.O.N.K-")
     c.full_clean()
 def test_different_slug_similar_name(self):
     """Two competitions with similar names have different slugs"""
     c = CompetitionFactory.create(name="MegaMinerAI-Galapagos")
     c2 = CompetitionFactory.create(name="MegaMinerAI Galapagos")
     self.assertNotEqual(c, c2)
 def test_no_duplicate_names(self):
     """Make sure we can't have two competitions by the same name"""
     CompetitionFactory.create(name="MegaMinerAI")
     with self.assertRaises(IntegrityError):
         CompetitionFactory.create(name="MegaMinerAI")