def test_get(self):
        context = AnalyzeJudgingContext()
        judging_round = context.judging_round
        judge = context.add_judge()
        with self.login(email=self.basic_user().email):

            response = self.client.get(self._url(judging_round.id, judge.id))
            assert response.status_code == 200
 def test_get_full_panel(self):
     context = AnalyzeJudgingContext()
     judging_round = context.judging_round
     panel_size = context.scenario.panel_size
     context.add_applications(panel_size * 2)
     with self.login(email=self.basic_user().email):
         url = reverse(AllocateApplicationsView.view_name,
                       args=[judging_round.id, context.judge.id])
         response = self.client.get(url)
         assert len(response.data) == panel_size
 def test_get_by_judge_succeeds(self):
     context = AnalyzeJudgingContext()
     judging_round = context.judging_round
     judge = context.add_judge()
     judge.set_password("password")
     judge.save()
     with self.login(email=judge.email):
         url = reverse(AllocateApplicationsView.view_name,
                       args=[judging_round.id, judge.id])
         response = self.client.get(url)
         assert response.status_code == 200
 def test_get_judging_round_inactive(self):
     context = AnalyzeJudgingContext(is_active=False)
     judging_round = context.judging_round
     judge = context.add_judge()
     with self.login(email=self.basic_user().email):
         url = reverse(AllocateApplicationsView.view_name,
                       args=[judging_round.id, judge.id])
         response = self.client.get(url)
         assert response.status_code == 403
         assert [
             JUDGING_ROUND_INACTIVE_ERROR.format(judging_round.id)
             in response.data
         ]
 def assert_judge_feature_filter(self, name, options, field):
     context = AnalyzeJudgingContext(type="judge",
                                     name=name,
                                     read_count=1,
                                     options=options)
     judge_with_panels = [
         _judge_with_panel(context, field, option) for option in options
     ]
     count = len(options)
     context.add_applications(context.scenario.panel_size * count)
     for counter, app in enumerate(context.applications):
         (option, judge, panel) = judge_with_panels[counter % count]
         context.add_feedback(application=app, judge=judge, panel=panel)
     example = judge_with_panels[0]
     new_judge = ExpertFactory(**{field: example.option})
     context.add_judge(assigned=False, complete=False, judge=new_judge)
     with self.login(email=self.basic_user().email):
         url = reverse(AllocateApplicationsView.view_name,
                       args=[context.judging_round.id, new_judge.id])
         self.client.get(url)
         example_apps = example.judge.judgepanelassignment_set.values_list(
             "panel__applicationpanelassignment__application_id", flat=True)
         new_judge_apps = new_judge.judgepanelassignment_set.values_list(
             "panel__applicationpanelassignment__application_id", flat=True)
         assert set(example_apps).intersection(new_judge_apps) == set()
 def test_get_with_unread_application(self):
     context = AnalyzeJudgingContext(type="reads",
                                     name="reads",
                                     read_count=2,
                                     options=[""])
     program_family = context.program.program_family
     email = self.global_operations_manager(program_family).email
     with self.login(email=email):
         url = reverse(AnalyzeJudgingRoundView.view_name,
                       args=[context.judging_round.id])
         response = self.client.get(url)
         assert len(response.data) == 1
         first_result = response.data["results"][0]
         assert (first_result["remaining_needed_reads"] ==
                 context.needed_reads())
Example #7
0
 def test_get_no_reads_criteria_exists(self):
     context = AnalyzeJudgingContext(type="gender", read_count=0)
     judging_round_id = context.judging_round.id
     with self.login(email=self.basic_user().email):
         url = reverse(self.view_name, args=[judging_round_id])
         response = self.client.get(url)
         _assert_response_matches_context(response, context)
 def test_get_already_assigned(self):
     context = AnalyzeJudgingContext()
     judging_round = context.judging_round
     judge = context.add_judge()
     with self.login(email=self.basic_user().email):
         url = reverse(AllocateApplicationsView.view_name,
                       args=[judging_round.id, judge.id])
         response = self.client.get(url)
         assert response.status_code == 200
         count = len(response.data)
         response = self.client.get(url)
         assert response.status_code == 403
         assert [
             ALREADY_ASSIGNED_ERROR.format(judge=judge.email, count=count)
             in response.data
         ]
 def test_get_no_app_for_judge(self):
     context = AnalyzeJudgingContext()
     for app in context.applications:
         if not app.judgeapplicationfeedback_set.filter(
                 judge=context.judge).exists():
             context.add_feedback(application=app,
                                  judge=context.judge,
                                  panel=context.panel)
     with self.login(email=self.basic_user().email):
         url = reverse(AllocateApplicationsView.view_name,
                       args=[context.judging_round.id, context.judge.id])
         response = self.client.get(url)
         assert response.status_code == 403
         assert [
             NO_APP_LEFT_FOR_JUDGE.format(context.judge.email)
             in response.data
         ]
 def test_get_with_program_criterion(self):
     context = AnalyzeJudgingContext(type="matching",
                                     name="program",
                                     read_count=1,
                                     options=[""])
     # This is where I gave up and just hard coded it!
     dists = {context.program.program_family.name: {0: 1, 1: 1}}
     self.assert_option_distributions(context, dists)
 def test_program_option_field_can_be_nonempty(self):
     context = AnalyzeJudgingContext(type="matching",
                                     name="program",
                                     read_count=1,
                                     options=["nonempty value"])
     # This is where I gave up and just hard coded it!
     dists = {context.program.program_family.name: {0: 1, 1: 1}}
     self.assert_option_distributions(context, dists)
 def test_get_with_gender_criterion(self):
     genders = ["f", "m"]
     context = AnalyzeJudgingContext(type="judge",
                                     name="gender",
                                     read_count=1,
                                     options=genders)
     judge_key = context.judge.expertprofile.gender
     dists = _calc_judge_dists(context, judge_key)
     self.assert_option_distributions(context, dists)
 def test_get_with_role_criterion(self):
     roles = ["Executive", "Lawyer", "Investor"]
     context = AnalyzeJudgingContext(type="judge",
                                     name="role",
                                     read_count=1,
                                     options=roles)
     judge_key = context.judge.expertprofile.expert_category.name
     dists = _calc_judge_dists(context, judge_key)
     self.assert_option_distributions(context, dists)
 def test_get_with_industry_criterion(self):
     context = AnalyzeJudgingContext(type="matching",
                                     name="industry",
                                     read_count=1,
                                     options=[""])
     judge_key = context.judge.expertprofile.primary_industry.name
     options = _industry_options(context)
     dists = _calc_industry_dists(options, judge_key)
     self.assert_option_distributions(context, dists)
 def test_industry_option_field_can_be_nonempty(self):
     context = AnalyzeJudgingContext(type="matching",
                                     name="industry",
                                     read_count=1,
                                     options=["some value"])
     judge_key = context.judge.expertprofile.primary_industry.name
     options = _industry_options(context)
     dists = _calc_industry_dists(options, judge_key)
     self.assert_option_distributions(context, dists)
Example #16
0
 def test_options_judging_round_criteria_header(self):
     context = AnalyzeJudgingContext()
     judging_round_id = context.judging_round.id
     with self.login(email=self.basic_user().email):
         url = reverse(self.view_name, args=[judging_round_id])
         response = self.client.options(url)
         results = response.data["actions"]["GET"]["properties"]["results"]
         get_options = results["item"]["properties"]
         assert_fields(JudgingRoundCriteriaHeaderView.fields().keys(),
                       get_options)
 def test_commitment_quota_none_is_tolerated(self):
     context = AnalyzeJudgingContext()
     judging_round = context.judging_round
     commitment = context.judges[0].judgeroundcommitment_set.first()
     commitment.current_quota = None
     commitment.save()
     with self.login(email=self.basic_user().email):
         url = reverse(AllocateApplicationsView.view_name,
                       args=[judging_round.id, context.judge.id])
         # No error == success
         self.client.get(url)
 def test_get_when_no_applications_for_round(self):
     context = AnalyzeJudgingContext(add_application=False)
     judging_round_id = context.criterion.judging_round.id
     program_family = context.program.program_family
     email = self.global_operations_manager(program_family).email
     with self.login(email=email):
         url = reverse(AnalyzeJudgingRoundView.view_name,
                       args=[judging_round_id])
         response = self.client.get(url)
         results = response.data["results"]
         for result in results:
             assert result["needy_apps"] == 0    
 def test_get_by_another_expert_fails(self):
     context = AnalyzeJudgingContext()
     judging_round = context.judging_round
     judge = context.judge
     judge.set_password("password")
     judge.save()
     with self.login(email=judge.email):
         url = reverse(AllocateApplicationsView.view_name,
                       args=[judging_round.id,
                             ExpertFactory().id])
         response = self.client.get(url)
         assert response.status_code == 403
 def test_allocator_does_not_reassign_conflicted_apps_to_same_judge(self):
     context = AnalyzeJudgingContext()
     AllocatorFactory(judging_round=context.judging_round,
                      scenario=context.scenario)
     context.add_applications(20)
     panel = context.add_panel()
     for app in context.applications[-10:]:
         ApplicationPanelAssignmentFactory(application=app,
                                           panel=panel,
                                           scenario=context.scenario)
     judge = context.add_judge(assigned=True, complete=True, panel=panel)
     for app in context.applications[-10:]:
         JudgeApplicationFeedbackFactory(
             application=app,
             form_type=context.judging_round.judging_form,
             judge=judge,
             panel=panel,
             judging_status=JUDGING_STATUS_CONFLICT,
             feedback_status=JUDGING_FEEDBACK_STATUS_CONFLICT)
     judge.set_password("password")
     judge.save()
     with self.login(email=judge.email):
         response = self.client.get(
             self._url(context.judging_round.id, judge.id))
     assignments = response.json()
     assigned_ids = [app.id for app in context.applications[-10:]]
     reassigned_apps = set(assignments).intersection(assigned_ids)
     assert 0 == len(reassigned_apps)
 def test_get_for_unknown_judge_fails(self):
     context = AnalyzeJudgingContext()
     judging_round = context.judging_round
     judge = ExpertFactory()
     with self.login(email=self.basic_user().email):
         url = reverse(AllocateApplicationsView.view_name,
                       args=[judging_round.id, judge.id])
         response = self.client.get(url)
         assert response.status_code == 403
         assert [
             NO_DATA_FOR_JUDGE.format(judging_round=context.judging_round,
                                      judge=context.judge.email)
             in response.data
         ]
 def test_allocator_respects_completed_assignments(self):
     context = AnalyzeJudgingContext()
     AllocatorFactory(judging_round=context.judging_round,
                      scenario=context.scenario)
     context.add_applications(20)
     panel = context.add_panel()
     for app in context.applications[-10:]:
         ApplicationPanelAssignmentFactory(application=app,
                                           panel=panel,
                                           scenario=context.scenario)
     context.add_judge(assigned=True, complete=True, panel=panel)
     new_judge = context.add_judge(assigned=False, complete=False)
     new_judge.set_password("password")
     new_judge.save()
     with self.login(email=new_judge.email):
         response = self.client.get(
             self._url(context.judging_round.id, new_judge.id))
     assignments = response.json()
     assigned_ids = [app.id for app in context.applications[-10:]]
     reassigned_apps = set(assignments).intersection(assigned_ids)
     assert 0 == len(reassigned_apps)
 def test_get_program_filter(self):
     context = AnalyzeJudgingContext(type="matching",
                                     name="program",
                                     read_count=1)
     count = 4
     options = ProgramFactory.create_batch(count, cycle=context.cycle)
     context.add_applications(context.scenario.panel_size * count,
                              programs=options)
     judge_option = options[0].program_family
     judge = ExpertFactory(profile__home_program_family=judge_option)
     context.add_judge(assigned=False, complete=False, judge=judge)
     field = "startup__startupprograminterest__program__program_family"
     apps = Application.objects.filter(**{
         field: judge_option
     }).values_list("id", flat=True)
     self.assert_matching_allocation(context.judging_round, judge, apps)
    def test_get_with_commitment(self):
        context = AnalyzeJudgingContext(type="matching",
                                        name="program",
                                        read_count=1,
                                        options=[""])
        commitment = context.judges[0].judgeroundcommitment_set.first()
        judging_round_id = context.criterion.judging_round.id
        program_family = context.program.program_family
        email = self.global_operations_manager(program_family).email
        program_family = context.program.program_family
        with self.login(email=email):
            url = reverse(AnalyzeJudgingRoundView.view_name,
                          args=[judging_round_id])
            response = self.client.get(url)
            results = response.data["results"]

            for result in results:
                if result["option"] == program_family:
                    assert commitment.capacity == result[
                        'total_capacity']
                    assert commitment.capacity - 1 == result[
                        'remaining_capacity']
 def test_get_industry_filter_with_child_industry(self):
     context = AnalyzeJudgingContext(type="matching",
                                     name="industry",
                                     read_count=1)
     child_industry = IndustryFactory()
     child_industry.parent = IndustryFactory()
     child_industry.save()
     field = "startup__primary_industry"
     context.add_applications(context.scenario.panel_size,
                              field=field,
                              options=[child_industry])
     parent_industry = child_industry.parent
     judge = ExpertFactory(profile__primary_industry=parent_industry)
     context.add_judge(assigned=False, complete=False, judge=judge)
     apps = Application.objects.filter(**{
         field: child_industry
     }).values_list("id", flat=True)
     self.assert_matching_allocation(context.judging_round, judge, apps)
 def test_get_industry_filter(self):
     context = AnalyzeJudgingContext(type="matching",
                                     name="industry",
                                     read_count=1)
     options = [
         app.startup.primary_industry for app in context.applications
     ]
     count = len(options)
     assert (count > 1)
     field = "startup__primary_industry"
     context.add_applications(context.scenario.panel_size * count,
                              field=field,
                              options=options)
     judge_option = options[0]
     judge = ExpertFactory(profile__primary_industry=judge_option)
     context.add_judge(assigned=False, complete=False, judge=judge)
     apps = Application.objects.filter(**{
         field: judge_option
     }).values_list("id", flat=True)
     self.assert_matching_allocation(context.judging_round, judge, apps)
 def test_get_program_filter_multiple_startup_interests(self):
     context = AnalyzeJudgingContext(type="matching",
                                     name="program",
                                     read_count=1)
     count = 4
     options = ProgramFactory.create_batch(count, cycle=context.cycle)
     panel_size = context.scenario.panel_size
     context.add_applications(panel_size * count, programs=options)
     judge_option = options[0].program_family
     judge = ExpertFactory(profile__home_program_family=judge_option)
     context.add_judge(assigned=False, complete=False, judge=judge)
     programs = chain(options[1:], options * panel_size)
     for app, program in zip(context.applications, programs):
         StartupProgramInterestFactory(startup=app.startup,
                                       program=program,
                                       order=2)
     spis = StartupProgramInterest.objects.filter(order=1,
                                                  program__in=options)
     app_filter = {"startup__startupprograminterest__in": spis}
     apps = Application.objects.filter(**app_filter).values_list("id",
                                                                 flat=True)
     self.assert_matching_allocation(context.judging_round, judge, apps)