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_cannot_send_too_many_invites(self):
     """# of invites <= comp.max_num_team_members"""
     # Add two more users to Alice's team
     self.alice_team.add_team_member(UserFactory.create())
     self.alice_team.add_team_member(UserFactory.create())
     self.assertEqual(0, Invitation.objects.all().count())
     with self.loggedInAs("alice", "123"):
         resp = self.client.rpost('invitation_create',
                                  follow=True,
                                  data={'team': self.alice_team.pk,
                                        'receiver': self.carl.pk,
                                        'message': "Hello"})
     self.assertEqual(0, Invitation.objects.all().count())
     self.assertIn('__all__', resp.context['form'].errors)
    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.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 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 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",
                                               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 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)