Exemplo n.º 1
0
    def test_determine_merge_order(self):
        p1 = self.get_person_no_user()
        p2 = PersonFactory()
        p3 = self.get_person_no_user()
        p4 = PersonFactory()

        # target has User
        results = determine_merge_order(p1, p2)
        self.assertEqual(results, (p1, p2))

        # source has User
        results = determine_merge_order(p2, p1)
        self.assertEqual(results, (p1, p2))

        # neither have User
        results = determine_merge_order(p1, p3)
        self.assertEqual(results, (p1, p3))

        # both have User
        today = datetime.datetime.today()
        p2.user.last_login = today
        p2.user.save()
        p4.user.last_login = today - datetime.timedelta(days=30)
        p4.user.save()
        results = determine_merge_order(p2, p4)
        self.assertEqual(results, (p4, p2))
Exemplo n.º 2
0
    def test_handle_users(self):
        source1 = self.get_person_no_user()
        target1 = self.get_person_no_user()
        source2 = self.get_person_no_user()
        target2 = PersonFactory()
        source3 = PersonFactory()
        target3 = self.get_person_no_user()
        source4 = PersonFactory()
        target4 = PersonFactory()

        # no Users
        result = handle_users(source1, target1)
        self.assertTrue('DATATRACKER LOGIN ACTION: none' in result)

        # target user
        result = handle_users(source2, target2)
        self.assertTrue("DATATRACKER LOGIN ACTION: retaining login {}".format(
            target2.user) in result)

        # source user
        user = source3.user
        result = handle_users(source3, target3)
        self.assertTrue("DATATRACKER LOGIN ACTION: retaining login {}".format(
            user) in result)
        self.assertTrue(target3.user == user)

        # both have user
        source_user = source4.user
        target_user = target4.user
        result = handle_users(source4, target4)
        self.assertTrue(
            "DATATRACKER LOGIN ACTION: retaining login: {}, removing login: {}"
            .format(target_user, source_user) in result)
        self.assertTrue(target4.user == target_user)
        self.assertTrue(source4.user == None)
Exemplo n.º 3
0
 def test_edit_replace_user(self):
     person = PersonFactory()
     user = UserFactory()
     url = reverse('ietf.secr.rolodex.views.edit', kwargs={'id': person.id})
     redirect_url = reverse('ietf.secr.rolodex.views.view',
                            kwargs={'id': person.id})
     self.client.login(username="******", password="******")
     response = self.client.get(url)
     self.assertEqual(response.status_code, 200)
     post_data = {
         'name': person.name,
         'ascii': person.ascii,
         'ascii_short': person.ascii_short,
         'affiliation': person.affiliation,
         'address': person.address,
         'user': user.username,
         'email-0-person': person.pk,
         'email-0-address': person.email_address(),
         'email-TOTAL_FORMS': 1,
         'email-INITIAL_FORMS': 1,
         'email-MIN_NUM_FORMS': 0,
         'email-MAX_NUM_FORMS': 1000,
         'submit': 'Submit',
     }
     original_user = person.user
     person_id = person.pk
     response = self.client.post(url, post_data, follow=True)
     person = Person.objects.get(id=person_id)
     original_user = User.objects.get(id=original_user.id)
     self.assertRedirects(response, redirect_url)
     self.assertEqual(person.user, user)
     self.assertTrue(not original_user.is_active)
Exemplo n.º 4
0
 def test_merge_nominees(self):
     nomcom_test_data()
     nomcom = NomCom.objects.first()
     source = PersonFactory()
     source.nominee_set.create(nomcom=nomcom, email=source.email())
     target = PersonFactory()
     merge_nominees(source, target)
     self.assertTrue(target.nominee_set.all())
Exemplo n.º 5
0
 def test_move_related_objects(self):
     source = PersonFactory()
     target = PersonFactory()
     source_email = source.email_set.first()
     source_alias = source.alias_set.first()
     move_related_objects(source, target, file=StringIO())
     self.assertTrue(source_email in target.email_set.all())
     self.assertTrue(source_alias in target.alias_set.all())
Exemplo n.º 6
0
 def test_merge_persons(self):
     source = PersonFactory()
     target = PersonFactory()
     source_id = source.pk
     source_email = source.email_set.first()
     source_alias = source.alias_set.first()
     source_user = source.user
     merge_persons(source, target, file=StringIO())
     self.assertTrue(source_email in target.email_set.all())
     self.assertTrue(source_alias in target.alias_set.all())
     self.assertFalse(Person.objects.filter(id=source_id))
     self.assertFalse(source_user.is_active)
Exemplo n.º 7
0
 def test_dedupe_aliases(self):
     person = PersonFactory()
     Alias.objects.create(person=person, name='Joe')
     Alias.objects.create(person=person, name='Joe')
     self.assertEqual(person.alias_set.filter(name='Joe').count(), 2)
     dedupe_aliases(person)
     self.assertEqual(person.alias_set.filter(name='Joe').count(), 1)
Exemplo n.º 8
0
 def test_send_merge_notification(self):
     person = PersonFactory()
     len_before = len(outbox)
     send_merge_notification(person, ['Record Merged'])
     self.assertEqual(len(outbox), len_before + 1)
     self.assertTrue(
         'IETF Datatracker records merged' in outbox[-1]['Subject'])
Exemplo n.º 9
0
    def test_profile(self):
        person = PersonFactory(with_bio=True)

        self.assertTrue(person.photo is not None)
        self.assertTrue(person.photo.name is not None)

        url = urlreverse("ietf.person.views.profile",
                         kwargs={"email_or_name": person.plain_name()})
        r = self.client.get(url)
        #debug.show('person.name')
        #debug.show('person.plain_name()')
        #debug.show('person.photo_name()')
        self.assertContains(r, person.photo_name(), status_code=200)
        q = PyQuery(r.content)
        self.assertIn("Photo of %s" % person,
                      q("div.bio-text img.bio-photo").attr("alt"))

        bio_text = q("div.bio-text").text()
        self.assertIsNotNone(bio_text)

        photo_url = q("div.bio-text img.bio-photo").attr("src")
        r = self.client.get(photo_url)
        self.assertEqual(r.status_code, 200)
Exemplo n.º 10
0
    def test_manage_group_list(self):
        draft = make_test_data()

        url = urlreverse(ietf.community.views.manage_list, kwargs={ "acronym": draft.group.acronym })
        setup_default_community_list_for_group(draft.group)
        login_testing_unauthorized(self, "marschairman", url)

        # test GET, rest is tested with personal list
        r = self.client.get(url)
        self.assertEqual(r.status_code, 200)

        # Verify GET also works with non-WG and RG groups
        for gtype in ['area','program']:
            g = GroupFactory.create(type_id=gtype)
            # make sure the group's features have been initialized to improve coverage
            _ = g.features # pyflakes:ignore
            p = PersonFactory()
            g.role_set.create(name_id={'area':'ad','program':'lead'}[gtype],person=p, email=p.email())
            url = urlreverse(ietf.community.views.manage_list, kwargs={ "acronym": g.acronym })
            setup_default_community_list_for_group(g)
            self.client.login(username=p.user.username,password=p.user.username+"+password")
            r = self.client.get(url)
            self.assertEqual(r.status_code, 200)
Exemplo n.º 11
0
 def populate_personnel(obj, create, extracted, **kwargs):  # pylint: disable=no-self-argument
     '''
     Create a default set of role holders, unless the factory is called
     with populate_personnel=False
     '''
     if extracted is None:
         extracted = True
     if create and extracted:
         #roles= ['chair', 'advisor'] + ['member']*10
         roles = ['chair', 'advisor', 'member']
         for role in roles:
             p = PersonFactory()
             obj.group.role_set.create(name_id=role,
                                       person=p,
                                       email=p.email_set.first())
Exemplo n.º 12
0
    def test_merge_users(self):
        make_test_data()

        person = PersonFactory()
        source = person.user
        target = UserFactory()
        mars = Group.objects.get(acronym='mars')
        communitylist = CommunityList.objects.create(user=source, group=mars)
        nomcom = NomComFactory()
        position = PositionFactory(nomcom=nomcom)
        nominee = NomineeFactory(nomcom=nomcom, person=mars.get_chair().person)
        feedback = FeedbackFactory(user=source, author=person, nomcom=nomcom)
        feedback.nominees.add(nominee)
        nomination = NominationFactory(nominee=nominee,
                                       user=source,
                                       position=position,
                                       comments=feedback)

        merge_users(source, target)
        self.assertIn(communitylist, target.communitylist_set.all())
        self.assertIn(feedback, target.feedback_set.all())
        self.assertIn(nomination, target.nomination_set.all())
Exemplo n.º 13
0
 def get_person_no_user(self):
     person = PersonFactory()
     person.user = None
     person.save()
     return person
Exemplo n.º 14
0
    def test_name_methods(self):
        person = PersonFactory(name=u"Dr. Jens F. Möller", )

        self.assertEqual(person.name, u"Dr. Jens F. Möller")
        self.assertEqual(person.ascii_name(), u"Dr. Jens F. Moller")
        self.assertEqual(person.plain_name(), u"Jens Möller")
        self.assertEqual(person.plain_ascii(), u"Jens Moller")
        self.assertEqual(person.initials(), u"J. F.")
        self.assertEqual(person.first_name(), u"Jens")
        self.assertEqual(person.last_name(), u"Möller")

        person = PersonFactory(name=u"吴建平")
        # The following are probably incorrect because the given name should
        # be Jianping and the surname should be Wu ...
        # TODO: Figure out better handling for names with CJK characters.
        # Maybe use ietf.person.cjk.*
        self.assertEqual(person.ascii_name(), u"Wu Jian Ping")
Exemplo n.º 15
0
 def test_default_email(self):
     person = PersonFactory()
     primary = EmailFactory(person=person, primary=True, active=True)
     EmailFactory(person=person, primary=False, active=True)
     EmailFactory(person=person, primary=False, active=False)
     self.assertTrue(primary.address in person.formatted_email())
Exemplo n.º 16
0
 def test_get_extra_primary(self):
     source = PersonFactory()
     target = PersonFactory()
     extra = get_extra_primary(source, target)
     self.assertTrue(extra == list(source.email_set.filter(primary=True)))
Exemplo n.º 17
0
    def test_manage_review_requests(self):
        doc = make_test_data()
        review_req1 = make_review_data(doc)

        group = review_req1.team

        url = urlreverse(ietf.group.views.manage_review_requests, kwargs={ 'acronym': group.acronym, "assignment_status": "assigned" })

        login_testing_unauthorized(self, "secretary", url)

        assigned_url = urlreverse(ietf.group.views.manage_review_requests, kwargs={ 'acronym': group.acronym, 'group_type': group.type_id, "assignment_status": "assigned" })
        unassigned_url = urlreverse(ietf.group.views.manage_review_requests, kwargs={ 'acronym': group.acronym, 'group_type': group.type_id, "assignment_status": "unassigned" })

        review_req2 = ReviewRequest.objects.create(
            doc=review_req1.doc,
            team=review_req1.team,
            type_id="early",
            deadline=datetime.date.today() + datetime.timedelta(days=30),
            state_id="accepted",
            reviewer=review_req1.reviewer,
            requested_by=Person.objects.get(user__username="******"),
        )

        review_req3 = ReviewRequest.objects.create(
            doc=review_req1.doc,
            team=review_req1.team,
            type_id="early",
            deadline=datetime.date.today() + datetime.timedelta(days=30),
            state_id="requested",
            requested_by=Person.objects.get(user__username="******"),
        )

        # previous reviews
        ReviewRequest.objects.create(
            time=datetime.datetime.now() - datetime.timedelta(days=100),
            requested_by=Person.objects.get(name="(System)"),
            doc=doc,
            type=ReviewTypeName.objects.get(slug="early"),
            team=review_req1.team,
            state=ReviewRequestStateName.objects.get(slug="completed"),
            result=ReviewResultName.objects.get(slug="ready-nits"),
            reviewed_rev="01",
            deadline=datetime.date.today() - datetime.timedelta(days=80),
            reviewer=review_req1.reviewer,
        )

        ReviewRequest.objects.create(
            time=datetime.datetime.now() - datetime.timedelta(days=100),
            requested_by=Person.objects.get(name="(System)"),
            doc=doc,
            type=ReviewTypeName.objects.get(slug="early"),
            team=review_req1.team,
            state=ReviewRequestStateName.objects.get(slug="completed"),
            result=ReviewResultName.objects.get(slug="ready"),
            reviewed_rev="01",
            deadline=datetime.date.today() - datetime.timedelta(days=80),
            reviewer=review_req1.reviewer,
        )

        # Need one more person in review team one so we can test incrementing skip_count without immediately decrementing it
        another_reviewer = PersonFactory.create(name = u"Extra TestReviewer") # needs to be lexically greater than the exsting one
        another_reviewer.role_set.create(name_id='reviewer', email=another_reviewer.email(), group=review_req1.team)
        
        # get
        r = self.client.get(assigned_url)
        self.assertEqual(r.status_code, 200)
        self.assertTrue(review_req1.doc.name in unicontent(r))

        # can't save assigned: conflict
        new_reviewer = Email.objects.get(role__name="reviewer", role__group=group, person__user__username="******")
        # provoke conflict by posting bogus data
        r = self.client.post(assigned_url, {
            "reviewrequest": [str(review_req1.pk), str(review_req2.pk), str(123456)],

            # close
            "r{}-existing_reviewer".format(review_req1.pk): "123456",
            "r{}-action".format(review_req1.pk): "close",
            "r{}-close".format(review_req1.pk): "no-response",

            # assign
            "r{}-existing_reviewer".format(review_req2.pk): "123456",
            "r{}-action".format(review_req2.pk): "assign",
            "r{}-reviewer".format(review_req2.pk): new_reviewer.pk,

            "action": "save-continue",
        })
        self.assertEqual(r.status_code, 200)
        content = unicontent(r).lower()
        self.assertTrue("1 request closed" in content)
        self.assertTrue("2 requests changed assignment" in content)

        # can't save unassigned: conflict
        r = self.client.post(unassigned_url, {
            "reviewrequest": [str(123456)],
            "action": "save-continue",
        })
        self.assertEqual(r.status_code, 200)
        content = unicontent(r).lower()
        self.assertTrue("1 request opened" in content)

        # close and reassign assigned
        new_reviewer = Email.objects.get(role__name="reviewer", role__group=group, person__user__username="******")
        r = self.client.post(assigned_url, {
            "reviewrequest": [str(review_req1.pk), str(review_req2.pk)],

            # close
            "r{}-existing_reviewer".format(review_req1.pk): review_req1.reviewer_id or "",
            "r{}-action".format(review_req1.pk): "close",
            "r{}-close".format(review_req1.pk): "no-response",

            # assign
            "r{}-existing_reviewer".format(review_req2.pk): review_req2.reviewer_id or "",
            "r{}-action".format(review_req2.pk): "assign",
            "r{}-reviewer".format(review_req2.pk): new_reviewer.pk,
            "r{}-add_skip".format(review_req2.pk) : 1,

            "action": "save",
        })
        self.assertEqual(r.status_code, 302)

        # no change on unassigned
        r = self.client.post(unassigned_url, {
            "reviewrequest": [str(review_req3.pk)],

            # no change
            "r{}-existing_reviewer".format(review_req3.pk): review_req3.reviewer_id or "",
            "r{}-action".format(review_req3.pk): "",
            "r{}-close".format(review_req3.pk): "no-response",
            "r{}-reviewer".format(review_req3.pk): "",
            
            "action": "save",
        })
        self.assertEqual(r.status_code, 302)

        review_req1, review_req2, review_req3 = reload_db_objects(review_req1, review_req2, review_req3)
        self.assertEqual(review_req1.state_id, "no-response")
        self.assertEqual(review_req2.state_id, "requested")
        self.assertEqual(review_req2.reviewer, new_reviewer)
        settings = ReviewerSettings.objects.filter(team=review_req2.team, person=new_reviewer.person).first()
        self.assertEqual(settings.skip_next,1)
        self.assertEqual(review_req3.state_id, "requested")