def testDashboardAsStudentWithEval(self):
        mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
        mentor.createOtherUser('*****@*****.**').createMentor(self.org)
        self.data.createStudentWithProject(self.org, mentor.profile)
        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(url, 3)
        self.assertResponseForbidden(response)

        response = self.get(url)
        self.assertDashboardComponentTemplatesUsed(response)
        self.evaluation = SurveyHelper(self.gsoc, self.dev_test)
        self.evaluation.createStudentEvaluation(
            override={'link_id': 'midterm'})
        response = self.getListResponse(url, 3)
        self.assertIsJsonResponse(response)
        data = json.loads(response.content)
        self.assertEqual(len(data['data']['']), 1)

        self.evaluation.createStudentEvaluation(override={'link_id': 'final'})
        response = self.getListResponse(url, 3)
        self.assertIsJsonResponse(response)
        data = json.loads(response.content)
        self.assertEqual(len(data['data']['']), 2)
Beispiel #2
0
    def testDashboardAsStudentWithEval(self):
        user = profile_utils.seedNDBUser()
        profile_utils.loginNDB(user)
        profile = profile_utils.seedNDBStudent(self.program, user=user)

        project_utils.seedProject(profile, self.program.key())

        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertResponseOK(response)
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(url, 3)
        self.assertResponseForbidden(response)

        response = self.get(url)
        self.assertResponseOK(response)
        self.assertDashboardComponentTemplatesUsed(response)
        self.evaluation = SurveyHelper(self.gsoc, self.dev_test)
        self.evaluation.createStudentEvaluation(
            override={'link_id': 'midterm'})
        response = self.getListResponse(url, 3)
        self.assertIsJsonResponse(response)
        data = json.loads(response.content)
        self.assertEqual(len(data['data']['']), 1)

        self.evaluation.createStudentEvaluation(override={'link_id': 'final'})
        response = self.getListResponse(url, 3)
        self.assertIsJsonResponse(response)
        data = json.loads(response.content)
        self.assertEqual(len(data['data']['']), 2)
Beispiel #3
0
  def testDashboardAsStudentWithEval(self):
    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile = profile_utils.seedNDBStudent(self.program, user=user)

    project_utils.seedProject(profile, self.program.key())

    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertResponseOK(response)
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(url, 3)
    self.assertResponseForbidden(response)

    response = self.get(url)
    self.assertResponseOK(response)
    self.assertDashboardComponentTemplatesUsed(response)
    self.evaluation = SurveyHelper(self.gsoc, self.dev_test)
    self.evaluation.createStudentEvaluation(override={'link_id': 'midterm'})
    response = self.getListResponse(url, 3)
    self.assertIsJsonResponse(response)
    data = json.loads(response.content)
    self.assertEqual(len(data['data']['']), 1)

    self.evaluation.createStudentEvaluation(override={'link_id': 'final'})
    response = self.getListResponse(url, 3)
    self.assertIsJsonResponse(response)
    data = json.loads(response.content)
    self.assertEqual(len(data['data']['']), 2)
  def testDashboardAsStudentWithEval(self):
    mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
    mentor.createOtherUser('*****@*****.**').createMentor(self.org)
    self.data.createStudentWithProject(self.org, mentor.profile)
    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(url, 3)
    self.assertResponseForbidden(response)

    response = self.get(url)
    self.assertDashboardComponentTemplatesUsed(response)
    self.evaluation = SurveyHelper(self.gsoc, self.dev_test)
    self.evaluation.createStudentEvaluation(override={'link_id': 'midterm'})
    response = self.getListResponse(url, 3)
    self.assertIsJsonResponse(response)
    data = json.loads(response.content)
    self.assertEqual(len(data['data']['']), 1)

    self.evaluation.createStudentEvaluation(override={'link_id': 'final'})
    response = self.getListResponse(url, 3)
    self.assertIsJsonResponse(response)
    data = json.loads(response.content)
    self.assertEqual(len(data['data']['']), 2)
Beispiel #5
0
 def setUp(self):
   super(StudentEvaluationTest, self).setUp()
   self.init()
   self.evaluation = SurveyHelper(self.gsoc, self.dev_test)
Beispiel #6
0
class StudentEvaluationTest(GSoCDjangoTestCase):
  """Tests proposal review page.
  """

  def setUp(self):
    super(StudentEvaluationTest, self).setUp()
    self.init()
    self.evaluation = SurveyHelper(self.gsoc, self.dev_test)

  def assertEvaluationCreateTemplateUsed(self, response):
    """Asserts that all the evaluation create/edit templates were used.
    """
    self.assertGSoCTemplatesUsed(response)
    self.assertTemplateUsed(response, 'v2/modules/gsoc/form_base.html')
    self.assertTemplateUsed(response, 'v2/modules/gsoc/_form.html')
    self.assertTemplateUsed(response, 'v2/modules/gsoc/_evaluation.html')

  def assertEvaluationTakeTemplateUsed(self, response):
    """Asserts that all the evaluation take templates were used.
    """
    self.assertGSoCTemplatesUsed(response)
    self.assertTemplateUsed(response, 'v2/modules/gsoc/form_base.html')
    self.assertTemplateUsed(response, 'v2/modules/gsoc/_form.html')
    self.assertTemplateUsed(response, 'v2/modules/gsoc/_evaluation_take.html')

  def assertEvaluationShowTemplateUsed(self, response):
    """Asserts that all the evaluation show templates were used.
    """
    self.assertGSoCTemplatesUsed(response)
    self.assertTemplateUsed(response, 'v2/modules/gsoc/_survey/show.html')

  def assertFieldChoices(self, schema_choices, form_choices):
    """Asserts if the form field has the same choices as defined in the schema.
    """
    choices = [c['value'] for c in schema_choices]
    self.assertEqual(choices.sort(), form_choices.sort())

  def assertFormFromSchema(self, form, schema_json):
    """Asserts if the form built from the schema is same as the schema defined.
    """
    order, fields = json.loads(urllib.unquote(schema_json))

    for field in order:
      field_dict = fields[field]
      form_field = form.fields[field]

      if field_dict['field_type'] == 'checkbox':
        self.assertTrue(isinstance(form_field,
                                   django_forms.MultipleChoiceField))
        self.assertTrue(isinstance(form_field.widget,
                                   forms.CheckboxSelectMultiple))
        self.assertFieldChoices(field_dict['values'], form_field.choices)
      elif field_dict['field_type'] == 'radio':
        self.assertTrue(isinstance(form_field, django_forms.ChoiceField))
        self.assertTrue(isinstance(form_field.widget,
                                   django_forms.RadioSelect))
        self.assertFieldChoices(field_dict['values'], form_field.choices)
      elif field_dict['field_type'] == 'textarea':
        self.assertTrue(isinstance(form_field, django_forms.CharField))
        self.assertTrue(isinstance(form_field.widget, django_forms.Textarea))
      elif field_dict['field_type'] == 'input_text':
        self.assertTrue(isinstance(form_field, django_forms.CharField))

      self.assertEqual(field_dict['label'], form_field.label)
      self.assertEqual(field_dict['required'], form_field.required)

  def createProject(self, override_properties={}):
    properties = {
        'is_featured': False, 'mentors': [],
        'status': 'accepted', 'program': self.gsoc, 'org': self.org,

    }
    properties.update(override_properties)
    return self.seed(GSoCProject, properties)

  def getStudentEvalRecordProperties(self, show=False):
    eval = self.evaluation.createStudentEvaluation()

    mentor_profile = GSoCProfileHelper(self.gsoc, self.dev_test)
    mentor_profile.createOtherUser('*****@*****.**')
    mentor = mentor_profile.createMentor(self.org)

    student_profile = GSoCProfileHelper(self.gsoc, self.dev_test)
    student_profile.createOtherUser('*****@*****.**')
    student_profile.createStudentWithProject(self.org, mentor)

    project = GSoCProject.all().get()

    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), eval.link_id,
        project.parent().link_id, project.key().id())

    base_url = '/gsoc/eval/student'
    if show:
      url = '%s/show/%s' % (base_url, suffix)
    else:
      url = '%s/%s' % (base_url, suffix)

    return (url, eval, mentor)

  def ffPastEval(self, eval):
    eval.survey_start = timeline_utils.past(20)
    eval.survey_end = timeline_utils.past(10)
    eval.put()

  def testCreateEvaluationForStudentWithoutProject(self):
    link_id = LinkIDProvider(ProjectSurvey).getValue()
    suffix = "%s/%s" % (self.gsoc.key().name(), link_id)

    self.data.createStudent()
    # test review GET
    url = '/gsoc/eval/student/edit/' + suffix
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testCreateEvaluationForMentorWithoutProject(self):
    link_id = LinkIDProvider(ProjectSurvey).getValue()
    suffix = "%s/%s" % (self.gsoc.key().name(), link_id)

    self.data.createMentor(self.org)
    # test review GET
    url = '/gsoc/eval/student/edit/' + suffix
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testCreateEvaluationForStudent(self):
    link_id = LinkIDProvider(ProjectSurvey).getValue()
    suffix = "%s/%s" % (self.gsoc.key().name(), link_id)

    mentor_profile = GSoCProfileHelper(self.gsoc, self.dev_test)
    mentor_profile.createOtherUser('*****@*****.**')
    mentor = mentor_profile.createMentor(self.org)

    self.data.createStudentWithProject(self.org, mentor)
    # test review GET
    url = '/gsoc/eval/student/edit/' + suffix
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testCreateEvaluationForMentor(self):
    link_id = LinkIDProvider(ProjectSurvey).getValue()
    suffix = "%s/%s" % (self.gsoc.key().name(), link_id)

    student_profile = GSoCProfileHelper(self.gsoc, self.dev_test)
    student_profile.createOtherUser('*****@*****.**')
    student = student_profile.createStudent()

    self.data.createMentorWithProject(self.org, student)
    # test review GET
    url = '/gsoc/eval/student/edit/' + suffix
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testCreateEvaluationForOrgAdmin(self):
    link_id = LinkIDProvider(ProjectSurvey).getValue()
    suffix = "%s/%s" % (self.gsoc.key().name(), link_id)

    self.data.createOrgAdmin(self.org)
    # test review GET
    url = '/gsoc/eval/student/edit/' + suffix
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testCreateEvaluationForHost(self):
    host = self.data.createHost()

    link_id = LinkIDProvider(ProjectSurvey).getValue()
    suffix = "%s/%s" % (self.gsoc.key().name(), link_id)

    # test student evaluation create/edit GET
    url = '/gsoc/eval/student/edit/' + suffix
    response = self.get(url)
    self.assertEvaluationCreateTemplateUsed(response)

    self.assertContains(
        response, 'Create new student evaluation')
    self.assertContains(
        response, '<input name="schema" type="hidden" id="schema" value="" />')

    self.assertEqual(response.context['page_name'],
                     'Create new student evaluation')
    self.assertEqual(response.context['post_url'], url)
    form = response.context['forms'][0]

    expected_fields = ['author', 'title', 'short_name', 'content',
                       'survey_start', 'survey_end', 'schema'].sort()
    actual_fields = form.fields.keys().sort()
    self.assertEqual(expected_fields, actual_fields)

    # TODO(Madhu): Get rid of scope and author fields once the data
    # conversion is done.
    override = {
        'survey_content': None,
        'author': host.key(),
        'created_by': host.key(),
        'program': self.gsoc.key(),
        'modified_by': host.key(),
        'schema': self.evaluation.evalSchemaString(),
        }
    response, _ = self.modelPost(url, ProjectSurvey, override)
    self.assertResponseRedirect(response, url+'?validated')

    eval = ProjectSurvey.all().get()

    response = self.get(url)
    self.assertEvaluationCreateTemplateUsed(response)

    self.assertContains(
        response, 'Edit - %s' % (eval.title,))
    self.assertContains(
        response,
        '<input name="schema" type="hidden" id="schema" value=%s />'
        % (json.dumps(escape(eval.schema)),))

    self.assertEqual(response.context['page_name'],
                     'Edit - %s' % (eval.title,))
    self.assertEqual(response.context['post_url'], url)
    form = response.context['forms'][0]

    expected_fields = ['author', 'title', 'short_name', 'content',
                       'survey_start', 'survey_end', 'schema'].sort()
    actual_fields = form.fields.keys().sort()
    self.assertEqual(expected_fields, actual_fields)

  def testTakeEvaluationForMentor(self):
    url, eval, _ = self.getStudentEvalRecordProperties()

    mentor = self.data.createMentor(self.org)

    # test student evaluation take GET for a mentor of the same organization
    response = self.get(url)
    self.assertResponseForbidden(response)

    response = self.client.post(url)
    self.assertResponseForbidden(response)

    project = GSoCProject.all().get()
    project.mentors.append(mentor.key())
    project.put()
    # test student evaluation take GET for the mentor of the project
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testTakeEvaluationForAnotherOrgMentor(self):
    url, eval, _ = self.getStudentEvalRecordProperties()

    another_org = self.createOrg()
    self.data.createMentor(another_org)
    # test student evaluation take GET for a mentor of another organization
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testTakeEvaluationForAnotherOrgAdmin(self):
    url, eval, _ = self.getStudentEvalRecordProperties()

    another_org = self.createOrg()
    self.data.createOrgAdmin(another_org)
    # test student evaluation take GET for an org admin of another organization
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testTakeEvaluationForOrgAdmin(self):
    url, eval, _ = self.getStudentEvalRecordProperties()

    project = GSoCProject.all().get()

    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), eval.link_id,
        project.parent().link_id, project.key().id())

    base_url = '/gsoc/eval/student'

    show_url = '%s/show/%s' % (base_url, suffix)
    self.data.createOrgAdmin(self.org)
    response = self.get(url)
    self.assertResponseRedirect(response, show_url)

  def testTakeEvalForStudentWithNoProject(self):
    self.data.createStudent()

    # test student evaluation show GET for a for a student who
    # does not have a project in the program
    url, eval, _ = self.getStudentEvalRecordProperties()
    response = self.get(url)
    self.assertResponseForbidden(response)

    project = GSoCProject.all().get()

    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), eval.link_id,
        project.parent().link_id, project.key().id())

    base_url = '/gsoc/eval/student'

    self.ffPastEval(eval)
    response = self.get(url)
    show_url = '%s/show/%s' % (base_url, suffix)
    self.assertResponseRedirect(response, show_url)

  def testTakeEvalForAnotherStudentWithProject(self):
    url, eval, mentor = self.getStudentEvalRecordProperties()

    self.data.createStudentWithProject(self.org, mentor)
    # test student evaluation show GET for a for a student who
    # has another project in the same org and whose mentor is
    # same as the student whose survey is being accessed
    response = self.get(url)
    self.assertResponseForbidden(response)

    project = GSoCProject.all().get()

    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), eval.link_id,
        project.parent().link_id, project.key().id())

    base_url = '/gsoc/eval/student'

    self.ffPastEval(eval)
    response = self.get(url)
    show_url = '%s/show/%s' % (base_url, suffix)
    self.assertResponseRedirect(response, show_url)

  def testTakeEvalForStudentProjectWithAnotherMentor(self):
    url, eval, _ = self.getStudentEvalRecordProperties()

    mentor_profile = GSoCProfileHelper(self.gsoc, self.dev_test)
    mentor_profile.createOtherUser('*****@*****.**')
    mentor = mentor_profile.createMentor(self.org)

    self.data.createStudentWithProject(self.org, mentor)
    # test student evaluation show GET for a for a student who
    # has another project whose mentor is different than the current
    # mentor but the project is in the same org
    response = self.get(url)
    self.assertResponseForbidden(response)

    project = GSoCProject.all().get()

    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), eval.link_id,
        project.parent().link_id, project.key().id())

    base_url = '/gsoc/eval/student'

    self.ffPastEval(eval)
    response = self.get(url)
    show_url = '%s/show/%s' % (base_url, suffix)
    self.assertResponseRedirect(response, show_url)

  def testTakeEvalForStudentProjectWithAnotherOrg(self):
    url, eval, _ = self.getStudentEvalRecordProperties()
    other_org = self.createOrg()

    mentor_profile = GSoCProfileHelper(self.gsoc, self.dev_test)
    mentor_profile.createOtherUser('*****@*****.**')
    mentor = mentor_profile.createMentor(other_org)

    self.data.createStudentWithProject(other_org, mentor)
    # test student evaluation show GET for a for a student who
    # has another project in a different organization
    response = self.get(url)
    self.assertResponseForbidden(response)

    project = GSoCProject.all().get()

    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), eval.link_id,
        project.parent().link_id, project.key().id())

    base_url = '/gsoc/eval/student'

    self.ffPastEval(eval)
    response = self.get(url)
    show_url = '%s/show/%s' % (base_url, suffix)
    self.assertResponseRedirect(response, show_url)

  def testTakeEvalForStudent(self):
    eval = self.evaluation.createStudentEvaluation()

    mentor_profile = GSoCProfileHelper(self.gsoc, self.dev_test)
    mentor_profile.createOtherUser('*****@*****.**')
    mentor = mentor_profile.createMentor(self.org)

    self.data.createStudentWithProject(self.org, mentor)

    project = GSoCProject.all().get()

    base_url = '/gsoc/eval/student'
    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), eval.link_id,
        project.parent().link_id, project.key().id())

    url = '%s/%s' % (base_url, suffix)

    # test student evaluation show GET for a for a student who
    # has another project in a different organization
    response = self.get(url)
    self.assertEvaluationTakeTemplateUsed(response)

    self.assertContains(response, '%s' % (eval.title))
    self.assertContains(response, 'Project: %s' % (project.title))

    self.assertEqual(response.context['page_name'],
                     '%s' % (eval.title))
    form = response.context['forms'][0]

    self.assertFormFromSchema(form, eval.schema)

    postdata = {
        'frm-t1309871149671-item': 'one line text message',
        'frm-t1309871322655-item': ['Option 2', 'Option 3'],
        'frm-t1309871157535-item': """A quick brown fox jumped over a lazy dog.
        A quick brown fox jumped over a lazy dog. A quick brown fox jumped 
        over a lazy dog. A quick brown fox jumped over a lazy dog.""",
        }
    response = self.post(url, postdata)
    self.assertResponseOK(response)
    self.assertFormError(
        response, 'form', 'frm-t1310822212610-item',
        'This field is required.')

    postdata = {
        'frm-t1309871149671-item': 'one line text message',
        'frm-t1309871322655-item': ['Option 2', 'Option 3'],
        'frm-t1309871157535-item': """A quick brown fox jumped over a lazy dog.
        A quick brown fox jumped over a lazy dog. A quick brown fox jumped 
        over a lazy dog. A quick brown fox jumped over a lazy dog.""",
        'frm-t1310822212610-item': "Wa Wa",
        }
    response = self.post(url, postdata)
    self.assertResponseRedirect(response, '%s?validated' % (url,))

    self.ffPastEval(eval)
    response = self.get(url)
    show_url = '%s/show/%s' % (base_url, suffix)
    self.assertResponseRedirect(response, show_url)

  def testShowEvalForStudentWithNoProject(self):
    self.data.createStudent()

    # test student evaluation show GET for a for a student who
    # does not have a project in the program
    url, eval, _ = self.getStudentEvalRecordProperties(show=True)
    response = self.get(url)
    self.assertResponseForbidden(response)

    self.ffPastEval(eval)
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testShowEvalForAnotherStudentWithProject(self):
    url, eval, mentor = self.getStudentEvalRecordProperties(show=True)

    self.data.createStudentWithProject(self.org, mentor)
    # test student evaluation show GET for a for a student who
    # has another project in the same org and whose mentor is
    # same as the student whose survey is being accessed
    response = self.get(url)
    self.assertResponseForbidden(response)

    self.ffPastEval(eval)
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testShowEvalForStudentProjectWithAnotherMentor(self):
    url, eval, _ = self.getStudentEvalRecordProperties(show=True)

    mentor_profile = GSoCProfileHelper(self.gsoc, self.dev_test)
    mentor_profile.createOtherUser('*****@*****.**')
    mentor = mentor_profile.createMentor(self.org)

    self.data.createStudentWithProject(self.org, mentor)
    # test student evaluation show GET for a for a student who
    # has another project whose mentor is different than the current
    # mentor but the project is in the same org
    response = self.get(url)
    self.assertResponseForbidden(response)

    self.ffPastEval(eval)
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testShowEvalForStudentProjectWithAnotherOrg(self):
    url, eval, _ = self.getStudentEvalRecordProperties(show=True)
    other_org = self.createOrg()

    mentor_profile = GSoCProfileHelper(self.gsoc, self.dev_test)
    mentor_profile.createOtherUser('*****@*****.**')
    mentor = mentor_profile.createMentor(other_org)

    self.data.createStudentWithProject(other_org, mentor)
    # test student evaluation show GET for a for a student who
    # has another project in a different organization
    response = self.get(url)
    self.assertResponseForbidden(response)

    self.ffPastEval(eval)
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testShowEvalForStudent(self):
    eval = self.evaluation.createStudentEvaluation()

    mentor_profile = GSoCProfileHelper(self.gsoc, self.dev_test)
    mentor_profile.createOtherUser('*****@*****.**')
    mentor = mentor_profile.createMentor(self.org)

    self.data.createStudentWithProject(self.org, mentor)

    project = GSoCProject.all().get()

    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), eval.link_id,
        project.parent().link_id, project.key().id())

    url = '/gsoc/eval/student/show/%s' % (suffix,)

    # test student evaluation show GET for a for a student who
    # has another project in a different organization
    response = self.get(url)
    self.assertEvaluationShowTemplateUsed(response)

    self.ffPastEval(eval)
    response = self.get(url)
    self.assertEvaluationShowTemplateUsed(response)

  def testShowEvaluationForMentor(self):
    # test student evaluation show GET for a mentor of the same organization
    url, eval, mentor = self.getStudentEvalRecordProperties(show=True)
    response = self.get(url)
    self.assertResponseForbidden(response)

    project = GSoCProject.all().get()

    project_mentors = project.mentors
    project.mentors.append(mentor.key())
    project.put()
    # test student evaluation show GET for the mentor of the project
    response = self.get(url)
    self.assertResponseForbidden(response)

    self.ffPastEval(eval)
    project.mentors = project_mentors
    project.put()

    response = self.get(url)
    self.assertResponseForbidden(response)

    project.mentors.append(mentor.key())
    project.put()

    response = self.get(url)
    self.assertResponseForbidden(response)

  def testShowEvaluationForOtherOrgMentor(self):
    another_org = self.createOrg()
    self.data.createMentor(another_org)
    url, eval, _ = self.getStudentEvalRecordProperties(show=True)

    # test student evaluation show GET for a mentor of another organization
    response = self.get(url)
    self.assertResponseForbidden(response)

    self.ffPastEval(eval)
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testShowEvaluationForOtherOrgAdmin(self):
    another_org = self.createOrg()
    self.data.createOrgAdmin(another_org)
    url, eval, _ = self.getStudentEvalRecordProperties(show=True)

    # test student evaluation show GET for an org admin of another organization
    response = self.get(url)
    self.assertResponseForbidden(response)

    self.ffPastEval(eval)
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testShowEvaluationForOrgAdmin(self):
    self.data.createOrgAdmin(self.org)
    url, eval, _ = self.getStudentEvalRecordProperties(show=True)
    # test student evaluation show GET for an org admin of the org
    # to which project belongs to
    response = self.get(url)
    self.assertResponseForbidden(response)

    self.ffPastEval(eval)
    response = self.get(url)
    self.assertEvaluationShowTemplateUsed(response)
Beispiel #7
0
 def setUp(self):
   super(GCIOrgAppRecordsPageTest, self).setUp()
   self.init()
   self.record = SurveyHelper(self.gci, self.dev_test, self.org_app)
   self.url = '/gci/org/application/records/%s' % self.gci.key().name()
Beispiel #8
0
class GCIOrgAppRecordsPageTest(MailTestCase, GCIDjangoTestCase):
  """Tests for organization applications edit page.
  """

  def setUp(self):
    super(GCIOrgAppRecordsPageTest, self).setUp()
    self.init()
    self.record = SurveyHelper(self.gci, self.dev_test, self.org_app)
    self.url = '/gci/org/application/records/%s' % self.gci.key().name()

  def assertTemplatesUsed(self, response):
    """Asserts all the templates for edit page were used.
    """
    self.assertGCITemplatesUsed(response)
    self.assertTemplateUsed(response, 'v2/soc/org_app/records.html')

  def dataPostSingle(self, url, record, status):
    return self.dataPost(url, {record: status})

  def dataPost(self, url, changes):
    values = {}

    for record, status in changes.iteritems():
      record_data = {
          'status': status,
      }
      record_id = record.key().id()

      values[record_id] = record_data

    data = simplejson.dumps(values)

    postdata = {
        'data': data,
        'button_id': 'save',
        'idx': 0,
    }

    return self.post(url, postdata)

  def testGetRecords(self):
    self.data.createHost()
    record = self.record.createOrgApp('org1', self.data.user,
                                      {'status': 'needs review'})

    response = self.get(self.url)
    self.assertTemplatesUsed(response)

    list_data = self.getListData(self.url, 0)
    self.assertEqual(1, len(list_data))

    self.dataPostSingle(self.url, record, 'bogus')
    record = db.get(record.key())
    self.assertEqual('needs review', record.status)
    self.assertEmailNotSent()

    self.dataPostSingle(self.url, record, 'pre-accepted')
    record = db.get(record.key())
    self.assertEqual('pre-accepted', record.status)
    self.assertEmailNotSent()

    self.dataPostSingle(self.url, record, 'pre-rejected')
    record = db.get(record.key())
    self.assertEqual('pre-rejected', record.status)
    self.assertEmailNotSent()

    self.dataPostSingle(self.url, record, 'accepted')
    record = db.get(record.key())
    self.assertEqual('accepted', record.status)
    html = 'Organization accepted'
    self.assertEmailSent(n=1, html=html)

    self.dataPostSingle(self.url, record, 'rejected')
    record = db.get(record.key())
    self.assertEqual('rejected', record.status)
    html = 'Organization rejected'
    self.assertEmailSent(n=1, html=html)
    self.assertEmailSent(n=2)
Beispiel #9
0
 def setUp(self):
     self.init()
     self.record = SurveyHelper(self.gci, self.dev_test, self.org_app)
Beispiel #10
0
 def setUp(self):
     super(GCIOrgAppRecordsPageTest, self).setUp()
     self.init()
     self.record = SurveyHelper(self.gci, self.dev_test, self.org_app)
     self.url = '/gci/org/application/records/%s' % self.gci.key().name()
class StudentEvaluationTest(test_utils.GSoCDjangoTestCase):
  """Tests proposal review page.
  """

  def setUp(self):
    super(StudentEvaluationTest, self).setUp()
    self.init()
    self.evaluation = SurveyHelper(self.gsoc, self.dev_test)

  def assertEvaluationCreateTemplateUsed(self, response):
    """Asserts that all the evaluation create/edit templates were used.
    """
    self.assertGSoCTemplatesUsed(response)
    self.assertTemplateUsed(response, 'modules/gsoc/form_base.html')
    self.assertTemplateUsed(response, 'modules/gsoc/_form.html')
    self.assertTemplateUsed(response, 'modules/gsoc/_evaluation.html')

  def assertEvaluationTakeTemplateUsed(self, response):
    """Asserts that all the evaluation take templates were used.
    """
    self.assertGSoCTemplatesUsed(response)
    self.assertTemplateUsed(response, 'modules/gsoc/form_base.html')
    self.assertTemplateUsed(response, 'modules/gsoc/_form.html')
    self.assertTemplateUsed(response, 'modules/gsoc/_evaluation_take.html')

  def assertEvaluationShowTemplateUsed(self, response):
    """Asserts that all the evaluation show templates were used.
    """
    self.assertGSoCTemplatesUsed(response)
    self.assertTemplateUsed(response, 'modules/gsoc/_survey/show.html')

  def assertFieldChoices(self, schema_choices, form_choices):
    """Asserts if the form field has the same choices as defined in the schema.
    """
    choices = [c['value'] for c in schema_choices]
    self.assertEqual(choices.sort(), form_choices.sort())

  def assertFormFromSchema(self, form, schema_json):
    """Asserts if the form built from the schema is same as the schema defined.
    """
    order, fields = json.loads(urllib.unquote(schema_json))

    for field in order:
      field_dict = fields[field]
      form_field = form.fields[field]

      if field_dict['field_type'] == 'checkbox':
        self.assertTrue(isinstance(form_field,
                                   django_forms.MultipleChoiceField))
        self.assertTrue(isinstance(form_field.widget,
                                   forms.CheckboxSelectMultiple))
        self.assertFieldChoices(field_dict['values'], form_field.choices)
      elif field_dict['field_type'] == 'radio':
        self.assertTrue(isinstance(form_field, django_forms.ChoiceField))
        self.assertTrue(isinstance(form_field.widget,
                                   django_forms.RadioSelect))
        self.assertFieldChoices(field_dict['values'], form_field.choices)
      elif field_dict['field_type'] == 'textarea':
        self.assertTrue(isinstance(form_field, django_forms.CharField))
        self.assertTrue(isinstance(form_field.widget, django_forms.Textarea))
      elif field_dict['field_type'] == 'input_text':
        self.assertTrue(isinstance(form_field, django_forms.CharField))

      self.assertEqual(field_dict['label'], form_field.label)
      self.assertEqual(field_dict['required'], form_field.required)

  def createProject(self, override_properties=None):
    properties = {
        'is_featured': False,
        'mentors': [],
        'status': project_model.STATUS_ACCEPTED,
        'program': self.gsoc,
        'org': self.org,
        }
    properties.update(override_properties or {})
    return self.seed(project_model.GSoCProject, properties)

  def getStudentEvalRecordProperties(self, show=False):
    evaluation = self.evaluation.createStudentEvaluation()

    self.mentor = profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[self.org.key])

    self.student = profile_utils.seedSOCStudent(self.program)
    project = project_utils.seedProject(self.student, self.program.key(),
        org_key=self.org.key, mentor_key=self.mentor.key)

    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), evaluation.link_id,
        self.student.profile_id, project.key().id())

    base_url = '/gsoc/eval/student'
    if show:
      url = '%s/show/%s' % (base_url, suffix)
    else:
      url = '%s/%s' % (base_url, suffix)

    return (url, evaluation, self.mentor)

  def ffPastEval(self, evaluation):
    evaluation.survey_start = timeline_utils.past(20)
    evaluation.survey_end = timeline_utils.past(10)
    evaluation.put()

  def setEvaluationPeriodToFuture(self, evaluation):
    evaluation.survey_start = timeline_utils.future(delta=10)
    evaluation.survey_end = timeline_utils.future(delta=20)
    evaluation.put()

  def testCreateEvaluationForStudentWithoutProject(self):
    link_id = LinkIDProvider(ProjectSurvey).getValue()
    suffix = "%s/%s" % (self.gsoc.key().name(), link_id)

    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile_utils.seedNDBStudent(self.program, user=user)

    # test review GET
    url = '/gsoc/eval/student/edit/' + suffix
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testCreateEvaluationForMentorWithoutProject(self):
    link_id = LinkIDProvider(ProjectSurvey).getValue()
    suffix = "%s/%s" % (self.gsoc.key().name(), link_id)

    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile_utils.seedNDBProfile(
        self.program.key(), user=user, mentor_for=[self.org.key])

    # test review GET
    url = '/gsoc/eval/student/edit/' + suffix
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testCreateEvaluationForStudent(self):
    link_id = LinkIDProvider(ProjectSurvey).getValue()
    suffix = "%s/%s" % (self.gsoc.key().name(), link_id)

    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    student = profile_utils.seedNDBStudent(self.program, user=user)
    project_utils.seedProject(student, self.program.key(), org_key=self.org.key)

    # test review GET
    url = '/gsoc/eval/student/edit/' + suffix
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testCreateEvaluationForMentor(self):
    link_id = LinkIDProvider(ProjectSurvey).getValue()
    suffix = "%s/%s" % (self.gsoc.key().name(), link_id)

    student = profile_utils.seedNDBStudent(self.program)

    mentor = profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[self.org.key])
    project_utils.seedProject(
        student, self.program.key(), mentor_key=mentor.key)

    # test review GET
    url = '/gsoc/eval/student/edit/' + suffix
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testCreateEvaluationForOrgAdmin(self):
    link_id = LinkIDProvider(ProjectSurvey).getValue()
    suffix = "%s/%s" % (self.gsoc.key().name(), link_id)

    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile_utils.seedNDBProfile(
        self.program.key(), user=user, admin_for=[self.org.key])

    # test review GET
    url = '/gsoc/eval/student/edit/' + suffix
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testCreateEvaluationForHost(self):
    user = profile_utils.seedNDBUser(host_for=[self.program])
    profile_utils.loginNDB(user)

    link_id = LinkIDProvider(ProjectSurvey).getValue()
    suffix = "%s/%s" % (self.gsoc.key().name(), link_id)

    # test student evaluation create/edit GET
    url = '/gsoc/eval/student/edit/' + suffix
    response = self.get(url)
    self.assertResponseOK(response)
    self.assertEvaluationCreateTemplateUsed(response)

    self.assertContains(
        response, 'Create new student evaluation')
    self.assertContains(
        response, '<input name="schema" type="hidden" id="schema" value="" />',
        html=True)

    self.assertEqual(response.context['page_name'],
                     'Create new student evaluation')
    self.assertEqual(response.context['post_url'], url)
    form = response.context['forms'][0]

    expected_fields = ['author', 'title', 'short_name', 'content',
                       'survey_start', 'survey_end', 'schema'].sort()
    actual_fields = form.fields.keys().sort()
    self.assertEqual(expected_fields, actual_fields)

    # TODO(Madhu): Get rid of scope and author fields once the data
    # conversion is done.
    override = {
        'survey_content': None,
        'author': user.key.to_old_key(),
        'created_by': user.key.to_old_key(),
        'program': self.gsoc.key(),
        'modified_by': user.key.to_old_key(),
        'schema': self.evaluation.evalSchemaString(),
        }
    response, _ = self.modelPost(url, ProjectSurvey, override)
    self.assertResponseRedirect(response, url + '?validated')

    evaluation = ProjectSurvey.all().get()

    response = self.get(url)
    self.assertResponseOK(response)
    self.assertEvaluationCreateTemplateUsed(response)

    self.assertContains(
        response, 'Edit - %s' % (evaluation.title,))
    self.assertContains(
        response,
        '<input name="schema" type="hidden" id="schema" value=%s />'
            % (json.dumps(html.escape(evaluation.schema)),), html=True)

    self.assertEqual(response.context['page_name'],
                     'Edit - %s' % (evaluation.title,))
    self.assertEqual(response.context['post_url'], url)
    form = response.context['forms'][0]

    expected_fields = ['author', 'title', 'short_name', 'content',
                       'survey_start', 'survey_end', 'schema'].sort()
    actual_fields = form.fields.keys().sort()
    self.assertEqual(expected_fields, actual_fields)

  def testTakeEvaluationForMentor(self):
    url, _, _ = self.getStudentEvalRecordProperties()

    mentor = profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[self.org.key])

    # test student evaluation take GET for a mentor of the same organization
    response = self.get(url)
    self.assertResponseForbidden(response)

    response = self.client.post(url)
    self.assertResponseForbidden(response)

    project = project_model.GSoCProject.all().get()
    project.mentors.append(mentor.key.to_old_key())
    project.put()
    # test student evaluation take GET for the mentor of the project
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testTakeEvaluationForAnotherOrgMentor(self):
    url, _, _ = self.getStudentEvalRecordProperties()

    another_org = self.createOrg()

    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile_utils.seedNDBProfile(
        self.program.key(), user=user, mentor_for=[another_org.key])

    # test student evaluation take GET for a mentor of another organization
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testTakeEvaluationForAnotherOrgAdmin(self):
    url, _, _ = self.getStudentEvalRecordProperties()

    another_org = self.createOrg()
    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile_utils.seedNDBProfile(
        self.program.key(), user=user, admin_for=[another_org.key])

    # test student evaluation take GET for an org admin of another organization
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testTakeEvaluationForOrgAdmin(self):
    """Test that if an org admin attempts to visit a student evaluation,
    they are redirected.
    """
    url, evaluation, _ = self.getStudentEvalRecordProperties()

    project = project_model.GSoCProject.all().get()

    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), evaluation.link_id,
        self.student.profile_id, project.key().id())

    base_url = '/gsoc/eval/student'

    show_url = '%s/show/%s' % (base_url, suffix)
    user = profile_utils.seedNDBUser()
    profile_utils.seedNDBProfile(
        self.program.key(), admin_for=[self.org.key], user=user)
    profile_utils.loginNDB(user)

    response = self.get(url)
    self.assertResponseRedirect(response, show_url)

  def testTakeEvalForStudentWithNoProject(self):
    """Test that if a student without a project attempts to visit the
    evaluation page, they will be redirected.
    """

    student = profile_utils.seedSOCStudent(self.program)
    # test student evaluation show GET for a for a student who
    # does not have a project in the program
    url, evaluation, _ = self.getStudentEvalRecordProperties()
    response = self.get(url)
    self.assertResponseForbidden(response)

    project = project_model.GSoCProject.all().get()

    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), evaluation.link_id,
        self.student.profile_id, project.key().id())

    base_url = '/gsoc/eval/student'

    self.ffPastEval(evaluation)
    response = self.get(url)
    show_url = '%s/show/%s' % (base_url, suffix)
    self.assertResponseRedirect(response, show_url)

  def testTakeEvalForAnotherStudentWithProject(self):
    url, evaluation, mentor = self.getStudentEvalRecordProperties()

    student = profile_utils.seedSOCStudent(self.program)
    project_utils.seedProject(
        student, self.program.key(), mentor_key=mentor.key)
    # test student evaluation show GET for a for a student who
    # has another project in the same org and whose mentor is
    # same as the student whose survey is being accessed
    response = self.get(url)
    self.assertResponseForbidden(response)

    project = project_model.GSoCProject.all().get()

    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), evaluation.link_id,
        self.student.profile_id, project.key().id())

    base_url = '/gsoc/eval/student'

    self.ffPastEval(evaluation)
    response = self.get(url)
    show_url = '%s/show/%s' % (base_url, suffix)
    self.assertResponseRedirect(response, show_url)

  def testTakeEvalForStudentProjectWithAnotherMentor(self):
    """Test that a student with a project in the same org but with a
    different mentor than the current mentor will be redirected.
    """
    url, evaluation, _ = self.getStudentEvalRecordProperties()

    mentor = profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[self.org.key])

    student = profile_utils.seedSOCStudent(self.program)
    project_utils.seedProject(
        student, self.program.key(), mentor_key=mentor.key)

    response = self.get(url)
    self.assertResponseForbidden(response)

    project = project_model.GSoCProject.all().get()

    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), evaluation.link_id,
        self.student.profile_id, project.key().id())

    base_url = '/gsoc/eval/student'

    self.ffPastEval(evaluation)
    response = self.get(url)
    show_url = '%s/show/%s' % (base_url, suffix)
    self.assertResponseRedirect(response, show_url)

  def testTakeEvalForStudentProjectWithAnotherOrg(self):
    """Test that if a student with a project for an org attempts to take
    an evaluation for a different org, they will be redirected.
    """
    url, evaluation, _ = self.getStudentEvalRecordProperties()
    other_org = self.createOrg()

    project = project_model.GSoCProject.all().get()

    mentor = profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[other_org.key])
    other_student = profile_utils.seedSOCStudent(self.program)
    other_project = project_utils.seedProject(other_student,
        self.program.key(), org_key=other_org.key, mentor_key=mentor.key)

    response = self.get(url)
    self.assertResponseForbidden(response)

    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), evaluation.link_id,
        self.student.profile_id, project.key().id())

    self.ffPastEval(evaluation)
    response = self.get(url)
    show_url = '/gsoc/eval/student/show/%s' % suffix
    self.assertResponseRedirect(response, show_url)

  def testAccessBeforeEvaluationStarts(self):
    """Tests that student cannot access the page before survey starts."""
    evaluation = self.evaluation.createStudentEvaluation()
    self.setEvaluationPeriodToFuture(evaluation)

    mentor = profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[self.org.key])

    user = profile_utils.seedNDBUser()

    student = profile_utils.seedSOCStudent(self.program, user=user)
    project = project_utils.seedProject(student, self.program.key(),
        org_key=self.org.key, mentor_key=mentor.key)
    profile_utils.loginNDB(user)

    base_url = '/gsoc/eval/student'
    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), evaluation.link_id,
        student.profile_id, project.key().id())

    url = '%s/%s' % (base_url, suffix)
    response = self.get(url)

    # response is forbidden as the evaluation period has yet to start
    self.assertResponseForbidden(response)

    # TODO(daniel): NDB migration
    ndb_survey_key = ndb.Key.from_old_key(evaluation.key())
    start_date = timeline_utils.past()

    extension = survey_model.PersonalExtension(
        parent=student.key, survey=ndb_survey_key, start_date=start_date)
    extension.put()

    response = self.get(url)

    # with extension it should be possible to access the evaluation
    self.assertResponseOK(response)

  def testTakeEvalForStudent(self):
    """Test that given that the current student is the student for the
    current project and mentor then they can take the evaluation.
    """
    evaluation = self.evaluation.createStudentEvaluation()

    mentor = profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[self.org.key])

    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)

    student = profile_utils.seedSOCStudent(self.program, user=user)
    project = project_utils.seedProject(
        student, self.program.key(), mentor_key=mentor.key)

    base_url = '/gsoc/eval/student'
    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), evaluation.link_id,
        student.profile_id, project.key().id())

    url = '%s/%s' % (base_url, suffix)

    project = project_model.GSoCProject.all().get()

    # test student evaluation show GET for a for a student who
    # has another project in a different organization
    response = self.get(url)
    self.assertResponseOK(response)
    self.assertEvaluationTakeTemplateUsed(response)

    self.assertContains(response, '%s' % (evaluation.title))
    self.assertContains(response, 'Project: %s' % (project.title))

    self.assertEqual(response.context['page_name'], '%s' % (evaluation.title))
    form = response.context['forms'][0]

    self.assertFormFromSchema(form, evaluation.schema)

    postdata = {
        'frm-t1309871149671-item': 'one line text message',
        'frm-t1309871322655-item': ['Option 2', 'Option 3'],
        'frm-t1309871157535-item': """A quick brown fox jumped over a lazy dog.
        A quick brown fox jumped over a lazy dog. A quick brown fox jumped
        over a lazy dog. A quick brown fox jumped over a lazy dog.""",
        }
    response = self.post(url, postdata)
    self.assertResponseOK(response)
    self.assertFormError(
        response, 'form', 'frm-t1310822212610-item',
        'This field is required.')

    postdata = {
        'frm-t1309871149671-item': 'one line text message',
        'frm-t1309871322655-item': ['Option 2', 'Option 3'],
        'frm-t1309871157535-item': """A quick brown fox jumped over a lazy dog.
        A quick brown fox jumped over a lazy dog. A quick brown fox jumped
        over a lazy dog. A quick brown fox jumped over a lazy dog.""",
        'frm-t1310822212610-item': "Wa Wa",
        }
    response = self.post(url, postdata)
    self.assertResponseRedirect(response, '%s?validated' % (url,))

    self.ffPastEval(evaluation)
    response = self.get(url)
    show_url = '%s/show/%s' % (base_url, suffix)
    self.assertResponseRedirect(response, show_url)

  def testShowEvalForStudentWithNoProject(self):
    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile_utils.seedNDBStudent(self.program, user=user)

    # test student evaluation show GET for a for a student who
    # does not have a project in the program
    url, evaluation, _ = self.getStudentEvalRecordProperties(show=True)
    response = self.get(url)
    self.assertResponseForbidden(response)

    self.ffPastEval(evaluation)
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testShowEvalForAnotherStudentWithProject(self):
    url, evaluation, _ = self.getStudentEvalRecordProperties(show=True)

    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    student = profile_utils.seedNDBStudent(self.program, user=user)
    project_utils.seedProject(student, self.program.key(), org_key=self.org.key)

    # test student evaluation show GET for a for a student who
    # has another project in the same org and whose mentor is
    # same as the student whose survey is being accessed
    response = self.get(url)
    self.assertResponseForbidden(response)

    self.ffPastEval(evaluation)
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testShowEvalForStudentProjectWithAnotherMentor(self):
    url, evaluation, _ = self.getStudentEvalRecordProperties(show=True)

    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    student = profile_utils.seedNDBStudent(self.program, user=user)
    project_utils.seedProject(student, self.program.key(), org_key=self.org.key)

    # test student evaluation show GET for a for a student who
    # has another project whose mentor is different than the current
    # mentor but the project is in the same org
    response = self.get(url)
    self.assertResponseForbidden(response)

    self.ffPastEval(evaluation)
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testShowEvalForStudentProjectWithAnotherOrg(self):
    url, evaluation, _ = self.getStudentEvalRecordProperties(show=True)
    other_org = self.createOrg()

    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    student = profile_utils.seedNDBStudent(self.program, user=user)
    project_utils.seedProject(
        student, self.program.key(), org_key=other_org.key)

    # test student evaluation show GET for a for a student who
    # has another project in a different organization
    response = self.get(url)
    self.assertResponseForbidden(response)

    self.ffPastEval(evaluation)
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testShowEvalForStudent(self):
    """Test that a student can view their mentor evaluation."""
    evaluation = self.evaluation.createStudentEvaluation()

    mentor = profile_utils.seedNDBProfile(
        self.program.key(), mentor_for=[self.org.key])

    user = profile_utils.seedNDBUser()
    student = profile_utils.seedSOCStudent(self.program, user=user)
    project = project_utils.seedProject(student, self.program.key())
    profile_utils.loginNDB(user)

    suffix = "%s/%s/%s/%s" % (
        self.gsoc.key().name(), evaluation.link_id,
        student.profile_id, project.key().id())

    url = '/gsoc/eval/student/show/%s' % suffix

    self.ffPastEval(evaluation)
    response = self.get(url)
    self.assertResponseOK(response)
    self.assertEvaluationShowTemplateUsed(response)

  def testShowEvaluationForMentor(self):
    # test student evaluation show GET for a mentor of the same organization
    url, evaluation, mentor = self.getStudentEvalRecordProperties(show=True)
    response = self.get(url)
    self.assertResponseForbidden(response)

    project = project_model.GSoCProject.all().get()

    project_mentors = project.mentors
    project.mentors.append(mentor.key.to_old_key())
    project.put()
    # test student evaluation show GET for the mentor of the project
    response = self.get(url)
    self.assertResponseForbidden(response)

    self.ffPastEval(evaluation)
    project.mentors = project_mentors
    project.put()

    response = self.get(url)
    self.assertResponseForbidden(response)

    project.mentors.append(mentor.key.to_old_key())
    project.put()

    response = self.get(url)
    self.assertResponseForbidden(response)

  def testShowEvaluationForOtherOrgMentor(self):
    another_org = self.createOrg()

    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile_utils.seedNDBProfile(
        self.program.key(), user=user, mentor_for=[another_org.key])

    url, evaluation, _ = self.getStudentEvalRecordProperties(show=True)

    # test student evaluation show GET for a mentor of another organization
    response = self.get(url)
    self.assertResponseForbidden(response)

    self.ffPastEval(evaluation)
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testShowEvaluationForOtherOrgAdmin(self):
    another_org = self.createOrg()
    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile_utils.seedNDBProfile(
        self.program.key(), user=user, admin_for=[another_org.key])

    url, evaluation, _ = self.getStudentEvalRecordProperties(show=True)

    # test student evaluation show GET for an org admin of another organization
    response = self.get(url)
    self.assertResponseForbidden(response)

    self.ffPastEval(evaluation)
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testShowEvaluationForOrgAdmin(self):
    """Test that an org admin can access a project for the org of
    which they are an admin.
    """
    user = profile_utils.seedNDBUser()
    org_admin = profile_utils.seedNDBProfile(
        self.program.key(), user=user, admin_for=[self.org.key])
    profile_utils.loginNDB(user)

    url, evaluation, _ = self.getStudentEvalRecordProperties(show=True)
    response = self.get(url)
    self.assertResponseForbidden(response)

    self.ffPastEval(evaluation)
    response = self.get(url)
    self.assertResponseOK(response)
    self.assertEvaluationShowTemplateUsed(response)
Beispiel #12
0
 def setUp(self):
   self.init()
   self.record = SurveyHelper(self.gci, self.dev_test, self.org_app)
Beispiel #13
0
class OrgProfilePageTest(GCIDjangoTestCase):
  """Tests the view for organization profile page.
  """

  def setUp(self):
    self.init()
    self.record = SurveyHelper(self.gci, self.dev_test, self.org_app)

  def assertOrgProfilePageTemplatesUsed(self, response):
    self.assertGCITemplatesUsed(response)
    self.assertTemplateUsed(response, 'v2/modules/gci/org_profile/base.html')

  def testCreateOrgNoLinkid(self):
    url = '/gci/profile/organization/' + self.gci.key().name()
    response = self.get(url)
    self.assertResponseBadRequest(response)

  def testCreateOrgWrongLinkId(self):
    url = '/gci/profile/organization/' + self.gci.key().name()
    response = self.get(url + '?org_id=no_matching_proposal')
    self.assertResponseNotFound(response)

  def testCreateOrgRejectedApp(self):
    self.data.createUser()
    self.record.createOrgApp('rejected', self.data.user,
                             override={'status': 'rejected'})

    url = '/gci/profile/organization/' + self.gci.key().name()
    response = self.get(url + '?org_id=rejected')
    self.assertResponseForbidden(response)

  def testCreateOrgNoProfile(self):
    self.data.createUser()
    self.record.createOrgApp('new_org', self.data.user)

    url = '/gci/profile/organization/' + self.gci.key().name()
    response = self.get(url + '?org_id=new_org')

    self.assertResponseRedirect(response)

  def testCreateOrg(self):
    """Tests that only the assigned org admin for an organization can edit the
    org profile.
    """
    self.timeline.orgSignup()
    self.data.createProfile()
    self.record.createOrgApp('new_org', self.data.user)

    url = '/gci/profile/organization/' + self.gci.key().name()
    create_url = url + '?org_id=new_org'
    response = self.get(create_url)
    self.assertResponseOK(response)
    self.assertOrgProfilePageTemplatesUsed(response)
    
    postdata = {
        'founder': self.data.user, 'home': self.createDocument().key(),
        'scope': self.gci, 'irc_channel': 'irc://example.com',
        'pub_mailing_list': 'http://example.com',
    }
    response, properties = self.modelPost(create_url, GCIOrganization, postdata)
    self.assertResponseRedirect(response, url + '/new_org?validated')
    profile = db.get(self.data.profile.key())
    self.assertEqual(1, len(profile.org_admin_for))
class DashboardTest(GSoCDjangoTestCase):
  """Tests dashboard page.
  """

  def setUp(self):
    self.init()

  def assertDashboardTemplatesUsed(self, response):
    """Asserts that all the templates from the dashboard were used.
    """
    self.assertGSoCTemplatesUsed(response)
    self.assertTemplateUsed(response, 'v2/modules/gsoc/dashboard/base.html')

  def assertDashboardComponentTemplatesUsed(self, response):
    """Asserts that all the templates to render a component were used.
    """
    self.assertDashboardTemplatesUsed(response)
    self.assertTemplateUsed(response, 'v2/modules/gsoc/dashboard/list_component.html')
    self.assertTemplateUsed(response, 'v2/modules/gsoc/dashboard/component.html')
    self.assertTemplateUsed(response, 'v2/soc/list/lists.html')
    self.assertTemplateUsed(response, 'v2/soc/list/list.html')

  def testDasbhoardNoRole(self):
    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertDashboardTemplatesUsed(response)

  def testDashboardAsLoneUser(self):
    self.data.createProfile()
    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertDashboardTemplatesUsed(response)

  def testDashboardAsStudent(self):
    self.data.createStudent()
    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(url, 1)
    self.assertIsJsonResponse(response)

  def testDashboardAsStudentWithProposal(self):
    mentor = GSoCProfileHelper(
        self.gsoc, self.dev_test).createOtherUser(
        '*****@*****.**').createMentor(self.org)
    self.data.createStudentWithProject(self.org, mentor)
    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(url, 1)
    self.assertIsJsonResponse(response)

  def testDashboardAsStudentWithProject(self):
    mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
    mentor.createOtherUser('*****@*****.**').createMentor(self.org)
    self.data.createStudentWithProject(self.org, mentor.profile)
    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(url, 2)
    self.assertIsJsonResponse(response)

  def testDashboardAsStudentWithEval(self):
    mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
    mentor.createOtherUser('*****@*****.**').createMentor(self.org)
    self.data.createStudentWithProject(self.org, mentor.profile)
    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(url, 3)
    self.assertResponseForbidden(response)

    response = self.get(url)
    self.assertDashboardComponentTemplatesUsed(response)
    self.evaluation = SurveyHelper(self.gsoc, self.dev_test)
    self.evaluation.createStudentEvaluation(override={'link_id': 'midterm'})
    response = self.getListResponse(url, 3)
    self.assertIsJsonResponse(response)
    data = json.loads(response.content)
    self.assertEqual(len(data['data']['']), 1)

    self.evaluation.createStudentEvaluation(override={'link_id': 'final'})
    response = self.getListResponse(url, 3)
    self.assertIsJsonResponse(response)
    data = json.loads(response.content)
    self.assertEqual(len(data['data']['']), 2)

  def testDashboardAsHost(self):
    self.data.createHost()
    mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
    mentor.createOtherUser('*****@*****.**').createMentor(self.org)
    student = GSoCProfileHelper(self.gsoc, self.dev_test)
    student.createOtherUser('*****@*****.**')
    student.createStudentWithProject(self.org, mentor.profile)

    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertDashboardTemplatesUsed(response)

  def testDashboardAsOrgAdmin(self):
    self.data.createOrgAdmin(self.org)
    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(url, 5)
    self.assertIsJsonResponse(response)

  def testDashboardAsMentor(self):
    self.data.createMentor(self.org)
    self.timeline.studentsAnnounced()
    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(url, 4)
    self.assertIsJsonResponse(response)

  def testDashboardAsMentorWithProject(self):
    self.timeline.studentsAnnounced()
    student = GSoCProfileHelper(self.gsoc, self.dev_test)
    student.createOtherUser('*****@*****.**').createStudent()
    self.data.createMentorWithProject(self.org, student.profile)
    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(url, 4)
    self.assertIsJsonResponse(response)

  def testDashboardRequest(self):
    self.data.createHost()
    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.getListResponse(url, 7)
    self.assertIsJsonResponse(response)
    response = self.getListResponse(url, 8)
    self.assertIsJsonResponse(response)
class DashboardTest(GSoCDjangoTestCase):
    """Tests dashboard page.
  """
    def setUp(self):
        self.init()

    def assertDashboardTemplatesUsed(self, response):
        """Asserts that all the templates from the dashboard were used.
    """
        self.assertGSoCTemplatesUsed(response)
        self.assertTemplateUsed(response,
                                'v2/modules/gsoc/dashboard/base.html')

    def assertDashboardComponentTemplatesUsed(self, response):
        """Asserts that all the templates to render a component were used.
    """
        self.assertDashboardTemplatesUsed(response)
        self.assertTemplateUsed(
            response, 'v2/modules/gsoc/dashboard/list_component.html')
        self.assertTemplateUsed(response,
                                'v2/modules/gsoc/dashboard/component.html')
        self.assertTemplateUsed(response, 'v2/soc/list/lists.html')
        self.assertTemplateUsed(response, 'v2/soc/list/list.html')

    def testDasbhoardNoRole(self):
        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertDashboardTemplatesUsed(response)

    def testDashboardAsLoneUser(self):
        self.data.createProfile()
        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertDashboardTemplatesUsed(response)

    def testDashboardAsStudent(self):
        self.data.createStudent()
        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(url, 1)
        self.assertIsJsonResponse(response)

    def testDashboardAsStudentWithProposal(self):
        mentor = GSoCProfileHelper(
            self.gsoc,
            self.dev_test).createOtherUser('*****@*****.**').createMentor(
                self.org)
        self.data.createStudentWithProject(self.org, mentor)
        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(url, 1)
        self.assertIsJsonResponse(response)

    def testDashboardAsStudentWithProject(self):
        mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
        mentor.createOtherUser('*****@*****.**').createMentor(self.org)
        self.data.createStudentWithProject(self.org, mentor.profile)
        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(url, 2)
        self.assertIsJsonResponse(response)

    def testDashboardAsStudentWithEval(self):
        mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
        mentor.createOtherUser('*****@*****.**').createMentor(self.org)
        self.data.createStudentWithProject(self.org, mentor.profile)
        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(url, 3)
        self.assertResponseForbidden(response)

        response = self.get(url)
        self.assertDashboardComponentTemplatesUsed(response)
        self.evaluation = SurveyHelper(self.gsoc, self.dev_test)
        self.evaluation.createStudentEvaluation(
            override={'link_id': 'midterm'})
        response = self.getListResponse(url, 3)
        self.assertIsJsonResponse(response)
        data = json.loads(response.content)
        self.assertEqual(len(data['data']['']), 1)

        self.evaluation.createStudentEvaluation(override={'link_id': 'final'})
        response = self.getListResponse(url, 3)
        self.assertIsJsonResponse(response)
        data = json.loads(response.content)
        self.assertEqual(len(data['data']['']), 2)

    def testDashboardAsHost(self):
        self.data.createHost()
        mentor = GSoCProfileHelper(self.gsoc, self.dev_test)
        mentor.createOtherUser('*****@*****.**').createMentor(self.org)
        student = GSoCProfileHelper(self.gsoc, self.dev_test)
        student.createOtherUser('*****@*****.**')
        student.createStudentWithProject(self.org, mentor.profile)

        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertDashboardTemplatesUsed(response)

    def testDashboardAsOrgAdmin(self):
        self.data.createOrgAdmin(self.org)
        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(url, 5)
        self.assertIsJsonResponse(response)

    def testDashboardAsMentor(self):
        self.data.createMentor(self.org)
        self.timeline.studentsAnnounced()
        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(url, 4)
        self.assertIsJsonResponse(response)

    def testDashboardAsMentorWithProject(self):
        self.timeline.studentsAnnounced()
        student = GSoCProfileHelper(self.gsoc, self.dev_test)
        student.createOtherUser('*****@*****.**').createStudent()
        self.data.createMentorWithProject(self.org, student.profile)
        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(url, 4)
        self.assertIsJsonResponse(response)

    def testDashboardRequest(self):
        self.data.createHost()
        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.getListResponse(url, 7)
        self.assertIsJsonResponse(response)
        response = self.getListResponse(url, 8)
        self.assertIsJsonResponse(response)
Beispiel #16
0
class DashboardTest(GSoCDjangoTestCase):
  """Tests dashboard page.
  """

  def setUp(self):
    self.init()

  def assertDashboardTemplatesUsed(self, response):
    """Asserts that all the templates from the dashboard were used.
    """
    self.assertGSoCTemplatesUsed(response)
    self.assertTemplateUsed(response, 'modules/gsoc/dashboard/base.html')

  def assertDashboardComponentTemplatesUsed(self, response):
    """Asserts that all the templates to render a component were used.
    """
    self.assertDashboardTemplatesUsed(response)
    self.assertTemplateUsed(response, 'modules/gsoc/dashboard/list_component.html')
    self.assertTemplateUsed(response, 'modules/gsoc/dashboard/component.html')
    self.assertTemplateUsed(response, 'soc/list/lists.html')
    self.assertTemplateUsed(response, 'soc/list/list.html')

  def testDasbhoardNoRole(self):
    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertErrorTemplatesUsed(response)
    self.assertResponseForbidden(response)

  def testDashboardAsLoneUser(self):
    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile_utils.seedNDBProfile(self.program.key(), user=user)

    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertResponseOK(response)
    self.assertDashboardTemplatesUsed(response)

  def testDashboardAsStudent(self):
    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile_utils.seedNDBStudent(self.program, user=user)

    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertResponseOK(response)
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(url, 1)
    self.assertIsJsonResponse(response)

  def testDashboardAsStudentWithProposal(self):
    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile = profile_utils.seedNDBStudent(self.program, user=user)

    proposal_utils.seedProposal(profile.key, self.program.key())

    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertResponseOK(response)
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(url, 1)
    self.assertIsJsonResponse(response)

  def testDashboardAsStudentWithProject(self):
    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile = profile_utils.seedNDBStudent(self.program, user=user)

    project_utils.seedProject(profile, self.program.key())

    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertResponseOK(response)
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(url, 2)
    self.assertIsJsonResponse(response)

  def testDashboardAsStudentWithEval(self):
    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile = profile_utils.seedNDBStudent(self.program, user=user)

    project_utils.seedProject(profile, self.program.key())

    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertResponseOK(response)
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(url, 3)
    self.assertResponseForbidden(response)

    response = self.get(url)
    self.assertResponseOK(response)
    self.assertDashboardComponentTemplatesUsed(response)
    self.evaluation = SurveyHelper(self.gsoc, self.dev_test)
    self.evaluation.createStudentEvaluation(override={'link_id': 'midterm'})
    response = self.getListResponse(url, 3)
    self.assertIsJsonResponse(response)
    data = json.loads(response.content)
    self.assertEqual(len(data['data']['']), 1)

    self.evaluation.createStudentEvaluation(override={'link_id': 'final'})
    response = self.getListResponse(url, 3)
    self.assertIsJsonResponse(response)
    data = json.loads(response.content)
    self.assertEqual(len(data['data']['']), 2)

  def testDashboardAsOrgAdmin(self):
    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile_utils.seedNDBProfile(
        self.program.key(), user=user, admin_for=[self.org.key])

    self.timeline_helper.studentsAnnounced()
    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertResponseOK(response)
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(url, 5)
    self.assertIsJsonResponse(response)

  def testDashboardAsMentor(self):
    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile_utils.seedNDBProfile(
        self.program.key(), user=user, mentor_for=[self.org.key])

    self.timeline_helper.studentsAnnounced()
    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertResponseOK(response)
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(url, 4)
    self.assertIsJsonResponse(response)

  def testDashboardAsMentorWithProject(self):
    self.timeline_helper.studentsAnnounced()

    user = profile_utils.seedNDBUser()
    profile_utils.loginNDB(user)
    profile = profile_utils.seedNDBProfile(
        self.program.key(), user=user, mentor_for=[self.org.key])

    student = profile_utils.seedSOCStudent(self.program)
    project_utils.seedProject(
        student, self.program.key(), org_key=self.org.key,
        mentor_key=profile.key)

    url = '/gsoc/dashboard/' + self.gsoc.key().name()
    response = self.get(url)
    self.assertResponseOK(response)
    self.assertDashboardComponentTemplatesUsed(response)
    response = self.getListResponse(url, 4)
    self.assertIsJsonResponse(response)
Beispiel #17
0
class OrgProfilePageTest(GCIDjangoTestCase):
    """Tests the view for organization profile page.
  """
    def setUp(self):
        self.init()
        self.record = SurveyHelper(self.gci, self.dev_test, self.org_app)

    def assertOrgProfilePageTemplatesUsed(self, response):
        self.assertGCITemplatesUsed(response)
        self.assertTemplateUsed(response,
                                'v2/modules/gci/org_profile/base.html')

    def testCreateOrgNoLinkid(self):
        url = '/gci/profile/organization/' + self.gci.key().name()
        response = self.get(url)
        self.assertResponseBadRequest(response)

    def testCreateOrgWrongLinkId(self):
        url = '/gci/profile/organization/' + self.gci.key().name()
        response = self.get(url + '?org_id=no_matching_proposal')
        self.assertResponseNotFound(response)

    def testCreateOrgRejectedApp(self):
        self.data.createUser()
        self.record.createOrgApp('rejected',
                                 self.data.user,
                                 override={'status': 'rejected'})

        url = '/gci/profile/organization/' + self.gci.key().name()
        response = self.get(url + '?org_id=rejected')
        self.assertResponseForbidden(response)

    def testCreateOrgNoProfile(self):
        self.data.createUser()
        self.record.createOrgApp('new_org', self.data.user)

        url = '/gci/profile/organization/' + self.gci.key().name()
        response = self.get(url + '?org_id=new_org')

        self.assertResponseRedirect(response)

    def testCreateOrg(self):
        """Tests that only the assigned org admin for an organization can edit the
    org profile.
    """
        self.timeline.orgSignup()
        self.data.createProfile()
        self.record.createOrgApp('new_org', self.data.user)

        url = '/gci/profile/organization/' + self.gci.key().name()
        create_url = url + '?org_id=new_org'
        response = self.get(create_url)
        self.assertResponseOK(response)
        self.assertOrgProfilePageTemplatesUsed(response)

        postdata = {
            'founder': self.data.user,
            'home': self.createDocument().key(),
            'scope': self.gci,
            'irc_channel': 'irc://example.com',
            'pub_mailing_list': 'http://example.com',
        }
        response, properties = self.modelPost(create_url, GCIOrganization,
                                              postdata)
        self.assertResponseRedirect(response, url + '/new_org?validated')
        profile = db.get(self.data.profile.key())
        self.assertEqual(1, len(profile.org_admin_for))
Beispiel #18
0
class DashboardTest(GSoCDjangoTestCase):
    """Tests dashboard page.
  """
    def setUp(self):
        self.init()

    def assertDashboardTemplatesUsed(self, response):
        """Asserts that all the templates from the dashboard were used.
    """
        self.assertGSoCTemplatesUsed(response)
        self.assertTemplateUsed(response, 'modules/gsoc/dashboard/base.html')

    def assertDashboardComponentTemplatesUsed(self, response):
        """Asserts that all the templates to render a component were used.
    """
        self.assertDashboardTemplatesUsed(response)
        self.assertTemplateUsed(response,
                                'modules/gsoc/dashboard/list_component.html')
        self.assertTemplateUsed(response,
                                'modules/gsoc/dashboard/component.html')
        self.assertTemplateUsed(response, 'soc/list/lists.html')
        self.assertTemplateUsed(response, 'soc/list/list.html')

    def testDasbhoardNoRole(self):
        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertErrorTemplatesUsed(response)
        self.assertResponseForbidden(response)

    def testDashboardAsLoneUser(self):
        user = profile_utils.seedNDBUser()
        profile_utils.loginNDB(user)
        profile_utils.seedNDBProfile(self.program.key(), user=user)

        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertResponseOK(response)
        self.assertDashboardTemplatesUsed(response)

    def testDashboardAsStudent(self):
        user = profile_utils.seedNDBUser()
        profile_utils.loginNDB(user)
        profile_utils.seedNDBStudent(self.program, user=user)

        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertResponseOK(response)
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(url, 1)
        self.assertIsJsonResponse(response)

    def testDashboardAsStudentWithProposal(self):
        user = profile_utils.seedNDBUser()
        profile_utils.loginNDB(user)
        profile = profile_utils.seedNDBStudent(self.program, user=user)

        proposal_utils.seedProposal(profile.key, self.program.key())

        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertResponseOK(response)
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(url, 1)
        self.assertIsJsonResponse(response)

    def testDashboardAsStudentWithProject(self):
        user = profile_utils.seedNDBUser()
        profile_utils.loginNDB(user)
        profile = profile_utils.seedNDBStudent(self.program, user=user)

        project_utils.seedProject(profile, self.program.key())

        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertResponseOK(response)
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(url, 2)
        self.assertIsJsonResponse(response)

    def testDashboardAsStudentWithEval(self):
        user = profile_utils.seedNDBUser()
        profile_utils.loginNDB(user)
        profile = profile_utils.seedNDBStudent(self.program, user=user)

        project_utils.seedProject(profile, self.program.key())

        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertResponseOK(response)
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(url, 3)
        self.assertResponseForbidden(response)

        response = self.get(url)
        self.assertResponseOK(response)
        self.assertDashboardComponentTemplatesUsed(response)
        self.evaluation = SurveyHelper(self.gsoc, self.dev_test)
        self.evaluation.createStudentEvaluation(
            override={'link_id': 'midterm'})
        response = self.getListResponse(url, 3)
        self.assertIsJsonResponse(response)
        data = json.loads(response.content)
        self.assertEqual(len(data['data']['']), 1)

        self.evaluation.createStudentEvaluation(override={'link_id': 'final'})
        response = self.getListResponse(url, 3)
        self.assertIsJsonResponse(response)
        data = json.loads(response.content)
        self.assertEqual(len(data['data']['']), 2)

    def testDashboardAsOrgAdmin(self):
        user = profile_utils.seedNDBUser()
        profile_utils.loginNDB(user)
        profile_utils.seedNDBProfile(self.program.key(),
                                     user=user,
                                     admin_for=[self.org.key])

        self.timeline_helper.studentsAnnounced()
        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertResponseOK(response)
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(url, 5)
        self.assertIsJsonResponse(response)

    def testDashboardAsMentor(self):
        user = profile_utils.seedNDBUser()
        profile_utils.loginNDB(user)
        profile_utils.seedNDBProfile(self.program.key(),
                                     user=user,
                                     mentor_for=[self.org.key])

        self.timeline_helper.studentsAnnounced()
        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertResponseOK(response)
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(url, 4)
        self.assertIsJsonResponse(response)

    def testDashboardAsMentorWithProject(self):
        self.timeline_helper.studentsAnnounced()

        user = profile_utils.seedNDBUser()
        profile_utils.loginNDB(user)
        profile = profile_utils.seedNDBProfile(self.program.key(),
                                               user=user,
                                               mentor_for=[self.org.key])

        student = profile_utils.seedSOCStudent(self.program)
        project_utils.seedProject(student,
                                  self.program.key(),
                                  org_key=self.org.key,
                                  mentor_key=profile.key)

        url = '/gsoc/dashboard/' + self.gsoc.key().name()
        response = self.get(url)
        self.assertResponseOK(response)
        self.assertDashboardComponentTemplatesUsed(response)
        response = self.getListResponse(url, 4)
        self.assertIsJsonResponse(response)
Beispiel #19
0
class GCIOrgAppRecordsPageTest(MailTestCase, GCIDjangoTestCase):
    """Tests for organization applications edit page.
  """
    def setUp(self):
        super(GCIOrgAppRecordsPageTest, self).setUp()
        self.init()
        self.record = SurveyHelper(self.gci, self.dev_test, self.org_app)
        self.url = '/gci/org/application/records/%s' % self.gci.key().name()

    def assertTemplatesUsed(self, response):
        """Asserts all the templates for edit page were used.
    """
        self.assertGCITemplatesUsed(response)
        self.assertTemplateUsed(response, 'v2/soc/org_app/records.html')

    def dataPostSingle(self, url, record, status):
        return self.dataPost(url, {record: status})

    def dataPost(self, url, changes):
        values = {}

        for record, status in changes.iteritems():
            record_data = {
                'status': status,
            }
            record_id = record.key().id()

            values[record_id] = record_data

        data = simplejson.dumps(values)

        postdata = {
            'data': data,
            'button_id': 'save',
            'idx': 0,
        }

        return self.post(url, postdata)

    def testGetRecords(self):
        self.data.createHost()
        record = self.record.createOrgApp('org1', self.data.user,
                                          {'status': 'needs review'})

        response = self.get(self.url)
        self.assertTemplatesUsed(response)

        list_data = self.getListData(self.url, 0)
        self.assertEqual(1, len(list_data))

        self.dataPostSingle(self.url, record, 'bogus')
        record = db.get(record.key())
        self.assertEqual('needs review', record.status)
        self.assertEmailNotSent()

        self.dataPostSingle(self.url, record, 'pre-accepted')
        record = db.get(record.key())
        self.assertEqual('pre-accepted', record.status)
        self.assertEmailNotSent()

        self.dataPostSingle(self.url, record, 'pre-rejected')
        record = db.get(record.key())
        self.assertEqual('pre-rejected', record.status)
        self.assertEmailNotSent()

        self.dataPostSingle(self.url, record, 'accepted')
        record = db.get(record.key())
        self.assertEqual('accepted', record.status)
        html = 'Organization accepted'
        self.assertEmailSent(n=1, html=html)

        self.dataPostSingle(self.url, record, 'rejected')
        record = db.get(record.key())
        self.assertEqual('rejected', record.status)
        html = 'Organization rejected'
        self.assertEmailSent(n=1, html=html)
        self.assertEmailSent(n=2)