def setUp(self):
        self.user = UserFactory()
        self.comp = CompetitionFactory(created_by=self.user)
        self.tasks = [TaskFactory(created_by=self.user)]
        self.base = {'competition': self.comp, 'tasks': self.tasks}
        self.phase1 = PhaseFactory.create(**self.base)
        self.phase2 = PhaseFactory.create(**self.base)
        self.phase3 = PhaseFactory.create(**self.base)

        self.before_previous = {
            'start': now() - timedelta(minutes=20),
            'end': now() - timedelta(minutes=15)
        }
        self.previous = {
            'start': now() - timedelta(minutes=10),
            'end': now() - timedelta(minutes=5)
        }
        self.current = {
            'start': now() - timedelta(minutes=1),
            'end': now() + timedelta(minutes=5)
        }
        self.next = {
            'start': now() + timedelta(minutes=10),
            'end': now() + timedelta(minutes=15)
        }
        self.after_next = {
            'start': now() + timedelta(minutes=20),
            'end': now() + timedelta(minutes=25)
        }
    def setUp(self):
        self.owner = UserFactory(username='******', super_user=True)
        self.normal_user = UserFactory(username='******')
        self.competition = CompetitionFactory(created_by=self.owner,
                                              title="Competition One")
        self.competition_participant = CompetitionParticipantFactory(
            user=self.normal_user, competition=self.competition)
        self.phase1 = PhaseFactory(competition=self.competition,
                                   auto_migrate_to_this_phase=False,
                                   start=twenty_five_minutes_ago,
                                   end=twenty_minutes_ago,
                                   index=0,
                                   name='Phase1',
                                   status=Phase.CURRENT)

        self.phase2 = PhaseFactory(competition=self.competition,
                                   auto_migrate_to_this_phase=True,
                                   start=five_minutes_ago,
                                   end=twenty_minutes_from_now,
                                   index=1,
                                   name='Phase2',
                                   status=Phase.NEXT)

        self.phase3 = PhaseFactory(competition=self.competition,
                                   auto_migrate_to_this_phase=False,
                                   start=twenty_minutes_from_now,
                                   index=2,
                                   name='Phase3',
                                   status=Phase.FINAL)

        for _ in range(4):
            self.make_submission()
 def setUp(self):
     self.creator = UserFactory(username='******', password='******')
     self.other_user = UserFactory(username='******', password='******')
     self.comp = CompetitionFactory(created_by=self.creator)
     PhaseFactory(competition=self.comp)
     self.leaderboard = LeaderboardFactory(competition=self.comp)
     ColumnFactory(leaderboard=self.leaderboard)
 def setUp(self):
     self.admin = UserFactory(username='******', password='******', super_user=True)
     self.user = UserFactory(username='******', password='******')
     self.norm = UserFactory(username='******', password='******')
     self.collab = UserFactory(username='******', password='******')
     self.comp = CompetitionFactory(created_by=self.user, collaborators=[self.collab], published=True)
     for _ in range(5):
         CompetitionParticipantFactory(competition=self.comp)
    def setUp(self):
        self.user = UserFactory(username='******')
        self.admin = UserFactory(username='******', super_user=True)
        self.collab = UserFactory(username='******')
        self.normal_user = UserFactory(username='******')
        self.competition = CompetitionFactory(created_by=self.user)
        self.competition.collaborators.add(self.collab)
        self.phase = PhaseFactory(competition=self.competition)

        for _ in range(4):
            self.make_submission()
 def setUp(self):
     self.user = UserFactory(username='******')
     self.admin = UserFactory(username='******', super_user=True)
     self.collab = UserFactory(username='******')
     self.normal_user = UserFactory(username='******')
     self.competition = CompetitionFactory(created_by=self.user)
     self.competition.collaborators.add(self.collab)
     self.phase = PhaseFactory(competition=self.competition)
     self.leaderboard = LeaderboardFactory(competition=self.competition)
     self.column = ColumnFactory(leaderboard=self.leaderboard, key='test')
     self.submission = self.make_submission()
Beispiel #7
0
class CompetitionMixinTests(ChaHubTestCase):
    def setUp(self):
        self.comp = CompetitionFactory(published=False)
        PhaseFactory(competition=self.comp)
        super().setUp()

    def test_unpublished_comp_doesnt_send_private_data(self):
        resp = self.mock_chahub_save(self.comp)
        # Gross traversal through call args to get the data passed to _send
        assert resp.called
        data = resp.call_args[0][1][0]
        whitelist = self.comp.get_whitelist()
        for key, value in data.items():
            if key not in whitelist:
                assert value is None
Beispiel #8
0
 def setUp(self):
     self.user = UserFactory()
     self.comp = CompetitionFactory(published=True)
     self.participant = CompetitionParticipantFactory(user=self.user,
                                                      competition=self.comp)
     self.phase = PhaseFactory(competition=self.comp)
     self.data = DataFactory()
     # Calling this after initial setup so we don't turn on FORCE_CHAHUB and try and send all our setup objects
     super().setUp()
     self.submission = SubmissionFactory.build(
         owner=self.user,
         phase=self.phase,
         data=self.data,
         participant=self.participant,
         status='Finished',
         is_public=True,
     )
Beispiel #9
0
 def setUp(self):
     for _ in range(5):
         user = UserFactory(chahub_needs_retry=True)
         comp = CompetitionFactory(chahub_needs_retry=True, published=True)
         participant = CompetitionParticipantFactory(competition=comp,
                                                     user=user,
                                                     status='approved')
         phase = PhaseFactory(competition=comp)
         DataFactory(chahub_needs_retry=True,
                     is_public=True,
                     upload_completed_successfully=True)
         SubmissionFactory(chahub_needs_retry=True,
                           status="Finished",
                           phase=phase,
                           is_public=True,
                           participant=participant)
     super().setUp()
Beispiel #10
0
 def setUp(self):
     self.creator = UserFactory(username='******', password='******')
     self.bot_user = UserFactory(username='******',
                                 password='******',
                                 is_bot=True)
     self.non_bot_user = UserFactory(username='******', password='******')
     self.bot_comp = CompetitionFactory(created_by=self.creator,
                                        allow_robot_submissions=True)
     self.bot_phase = PhaseFactory(competition=self.bot_comp)
     self.bot_phase_day_limited = PhaseFactory(competition=self.bot_comp,
                                               has_max_submissions=True,
                                               max_submissions_per_day=1)
     self.bot_phase_person_limited = PhaseFactory(
         competition=self.bot_comp,
         has_max_submissions=True,
         max_submissions_per_person=1)
     CompetitionParticipant(user=self.non_bot_user,
                            competition=self.bot_comp,
                            status=CompetitionParticipant.APPROVED).save()
Beispiel #11
0
    def test_task_shown_as_validated_properly(self):
        user = UserFactory(username='******')
        solution = SolutionFactory(md5="12345")
        task = TaskFactory(created_by=user, solutions=[solution])
        competition = CompetitionFactory(created_by=user)
        phase = PhaseFactory(competition=competition, tasks=[task])
        submission = SubmissionFactory(md5="12345", phase=phase, status=Submission.FINISHED)
        url = reverse('task-detail', kwargs={'pk': task.id})
        self.client.login(username=user.username, password='******')

        # task should be validated because we have a successful submission matching
        # our solution
        resp = self.client.get(url)
        assert resp.status_code == 200
        assert resp.data["validated"]

        # make submission anything but Submission.FINISHED, task -> invalidated
        submission.status = Submission.FAILED
        submission.save()
        resp = self.client.get(url)
        assert resp.status_code == 200
        assert not resp.data["validated"]

        # make submission Submission.Finished, task -> re-validated
        submission.status = Submission.FINISHED
        submission.save()
        resp = self.client.get(url)
        assert resp.status_code == 200
        assert resp.data["validated"]

        # delete submission, task -> re-invalidated
        submission.delete()
        resp = self.client.get(url)
        assert resp.status_code == 200
        assert not resp.data["validated"]

        # make submission with different Sha -> still invalid
        SubmissionFactory(md5="different", phase=phase, status=Submission.FINISHED)
        resp = self.client.get(url)
        assert resp.status_code == 200
        assert not resp.data["validated"]
Beispiel #12
0
    def handle(self, *args, **kwargs):
        size = kwargs.get('size') or 3
        no_admin = kwargs.get('no_admin')
        print(
            f'Creating data of size {size} {"without an admin account." if no_admin else "with an admin account." }'
        )
        users = []
        for i in range(size):
            if i == 0 and not no_admin:
                try:
                    user = UserFactory(username='******',
                                       password='******',
                                       super_user=True)
                except IntegrityError:
                    # admin user already exists
                    user = User.objects.get(username='******')
            else:
                user = UserFactory()
            users.append(user)

        for user in users:
            for _ in range(size):
                comp = CompetitionFactory(created_by=user)
                for u in users:
                    try:
                        CompetitionParticipantFactory(competition=comp,
                                                      user=u,
                                                      status='approved')
                    except IntegrityError:
                        # User already a participant in the competition
                        pass
                for i in range(size):
                    phase = PhaseFactory(competition=comp,
                                         index=i,
                                         tasks=[TaskFactory(created_by=user)])
                    for _ in range(size):
                        SubmissionFactory(phase=phase,
                                          owner=random.choice(users))
Beispiel #13
0
    def setUp(self):
        self.superuser = UserFactory(is_superuser=True, is_staff=True)

        # Competition and creator
        self.creator = UserFactory(username='******', password='******')
        self.collaborator = UserFactory(username='******', password='******')
        self.comp = CompetitionFactory(created_by=self.creator,
                                       collaborators=[self.collaborator])
        self.phase = PhaseFactory(competition=self.comp)

        # Extra dummy user to test permissions, they shouldn't have access to many things
        self.other_user = UserFactory(username='******', password='******')

        # Make a participant and submission into competition
        self.participant = UserFactory(username='******',
                                       password='******')
        CompetitionParticipantFactory(user=self.participant,
                                      competition=self.comp)
        self.existing_submission = SubmissionFactory(
            phase=self.phase,
            owner=self.participant,
            status=Submission.SUBMITTED,
            secret='7df3600c-1234-5678-bbc8-bbe91f42d875')
Beispiel #14
0
    def setUp(self):
        # Competition and creator
        self.creator = UserFactory(username='******', password='******')
        self.comp = CompetitionFactory(created_by=self.creator)
        self.phase = PhaseFactory(competition=self.comp)
        for _ in range(2):
            self.phase.tasks.add(TaskFactory.create())

        # Extra phase for testing tasks can't be run on the wrong phase
        self.other_phase = PhaseFactory(competition=self.comp)

        # URL and data for making submissions
        self.submission_url = reverse('submission-list')
        self.submission_data = {
            'phase':
            self.phase.id,
            'data':
            Data.objects.create(created_by=self.creator,
                                type=Data.SUBMISSION).key,
            'tasks':
            random.sample(
                list(self.phase.tasks.all().values_list('id', flat=True)), 2)
        }
        self.sorted_tasks = sorted(self.submission_data['tasks'])
 def setUp(self):
     self.user = UserFactory(username='******')
     self.competition = CompetitionFactory(created_by=self.user, id=1)
     self.phase = PhaseFactory(competition=self.competition)
     self.leaderboard = LeaderboardFactory(competition=self.competition)
 def setUp(self):
     self.user = UserFactory(username='******')
     self.competition = CompetitionFactory(created_by=self.user)
     self.phase = PhaseFactory(competition=self.competition)
Beispiel #17
0
 def setUp(self):
     self.comp = CompetitionFactory(published=False)
     PhaseFactory(competition=self.comp)
     super().setUp()
 def setUp(self):
     self.user = UserFactory()
     self.comp = CompetitionFactory()
     self.tasks = [TaskFactory() for _ in range(2)]
     self.phase = PhaseFactory(competition=self.comp, tasks=self.tasks)