Exemplo n.º 1
0
    def test_manual_migration_makes_submissions_out_of_only_parents_not_children(
            self):
        self.client.login(username='******', password='******')

        # make 1 submission with 4 children
        parent = SubmissionFactory(owner=self.creator,
                                   phase=self.phase_1,
                                   has_children=True,
                                   status=Submission.FINISHED)
        for _ in range(4):
            # Make a submission _and_ new Task for phase 2
            self.phase_2.tasks.add(TaskFactory())
            SubmissionFactory(owner=self.creator,
                              phase=self.phase_1,
                              parent=parent,
                              status=Submission.FINISHED)

        assert self.phase_1.submissions.count() == 5
        assert self.phase_2.submissions.count() == 0

        # call "migrate" from phase 1 -> 2
        with mock.patch(
                "competitions.tasks.run_submission") as run_submission_mock:
            url = reverse('phases-manually_migrate',
                          kwargs={"pk": self.phase_1.pk})
            resp = self.client.post(url)
            assert resp.status_code == 200
            # Only 1 run here because parent has to create children
            assert run_submission_mock.call_count == 1

        # check phase 2 has the 1 parent submission
        assert self.phase_1.submissions.count() == 5
        assert self.phase_2.submissions.count() == 1
Exemplo n.º 2
0
 def test_protected_keys_prefixed_when_exploded(self):
     """Test that protected info keys are prefixed."""
     info = {'foo': 'bar', 'info': 'baz'}
     task = TaskFactory()
     taskrun = TaskRunFactory.create(task=task, info=info)
     df = self.base_analyst.get_task_run_df(task, [taskrun])
     assert_equal(df['_info'].tolist(), [info['info']])
    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)
        }
Exemplo n.º 4
0
 def create_app_with_contributors(self, anonymous, registered,
                                  two_tasks=False, name='my_app', hidden=0):
     app = AppFactory.create(name=name, hidden=hidden)
     task = TaskFactory(app=app)
     if two_tasks:
         task2 = TaskFactory(app=app)
     for i in range(anonymous):
         task_run = AnonymousTaskRunFactory(task=task,
                            user_ip='127.0.0.%s' % i)
         if two_tasks:
             task_run2 = AnonymousTaskRunFactory(task=task2,
                            user_ip='127.0.0.%s' % i)
     for i in range(registered):
         user = UserFactory.create()
         task_run = TaskRunFactory(task=task, user=user)
         if two_tasks:
             task_run2 = TaskRunFactory(task=task2, user=user)
     return app
Exemplo n.º 5
0
 def test_get_dataframe_with_list(self):
     """Test the task run dataframe with a list as the info."""
     info = [{'foo': 'bar'}, {'baz': 'qux'}]
     n_task_runs = 2
     task = TaskFactory()
     taskruns = TaskRunFactory.create_batch(n_task_runs,
                                            task=task,
                                            info=info)
     df = self.base_analyst.get_task_run_df(task, taskruns)
     assert_equal(df['info'].tolist(), [info] * n_task_runs)
Exemplo n.º 6
0
 def create_project_with_contributors(self,
                                      anonymous,
                                      registered,
                                      two_tasks=False,
                                      name='my_app',
                                      info={}):
     project = ProjectFactory.create(name=name, info=info)
     task = TaskFactory(project=project)
     if two_tasks:
         task2 = TaskFactory(project=project)
     for i in range(anonymous):
         task_run = AnonymousTaskRunFactory(task=task,
                                            user_ip='127.0.0.%s' % i)
         if two_tasks:
             task_run2 = AnonymousTaskRunFactory(task=task2,
                                                 user_ip='127.0.0.%s' % i)
     for i in range(registered):
         user = UserFactory.create()
         task_run = TaskRunFactory(task=task, user=user)
         if two_tasks:
             task_run2 = TaskRunFactory(task=task2, user=user)
     return project
 def test_exeption_if_no_collection_iri_for_parent(self, requests):
     """Test exception if no collection iri when child tasks generated."""
     manifest = self.create_manifest()
     headers = {'Content-Type': 'application/json'}
     response = FakeResponse(text=json.dumps(manifest),
                             status_code=200,
                             headers=headers,
                             encoding='utf-8')
     requests.get.return_value = response
     parent = ProjectFactory()
     task = TaskFactory(project=parent, n_answers=1)
     TaskRunFactory.create(task=task)
     importer = BulkTaskIIIFEnhancedImporter(manifest_uri=self.manifest_uri,
                                             parent_id=parent.id)
     assert_raises(BulkImportException, importer.tasks)
Exemplo n.º 8
0
    def test_limits_query(self):
        """Test API GET limits works"""
        owner = UserFactory.create()
        for i in range(30):
            app = AppFactory.create(owner=owner)
            task = TaskFactory(app=app)
            taskrun = TaskRunFactory(task=task)

        res = self.app.get('/api/app')
        data = json.loads(res.data)
        assert len(data) == 20, len(data)

        res = self.app.get('/api/app?limit=10')
        data = json.loads(res.data)
        assert len(data) == 10, len(data)

        res = self.app.get('/api/app?limit=10&offset=10')
        data = json.loads(res.data)
        assert len(data) == 10, len(data)
        assert data[0].get('name') == 'My Project number 11', data[0]

        res = self.app.get('/api/task')
        data = json.loads(res.data)
        assert len(data) == 20, len(data)

        res = self.app.get('/api/taskrun')
        data = json.loads(res.data)
        assert len(data) == 20, len(data)

        UserFactory.create_batch(30)

        res = self.app.get('/api/user')
        data = json.loads(res.data)
        assert len(data) == 20, len(data)

        res = self.app.get('/api/user?limit=10')
        data = json.loads(res.data)
        print data
        assert len(data) == 10, len(data)

        res = self.app.get('/api/user?limit=10&offset=10')
        data = json.loads(res.data)
        assert len(data) == 10, len(data)
        assert data[0].get('name') == 'user11', data
Exemplo n.º 9
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"]
Exemplo n.º 10
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))
 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)
Exemplo n.º 12
0
 def test_user_ids_in_task_run_dataframe(self):
     """Test that user IDs are included in the task run dataframe."""
     task = TaskFactory()
     taskruns = TaskRunFactory.create_batch(2, task=task)
     df = self.base_analyst.get_task_run_df(task, taskruns)
     assert_equal(df['user_id'].tolist(), [tr.user_id for tr in taskruns])