コード例 #1
0
 def testSecondaryEmailOptoutForm(self):
     p = Person(email=self.secondary_email, user=self.user)
     p.save()
     form_re = self._form_re(self.optout_url, p.email)
     response = self.client.get(self.url)
     self.assertEqual(response.status_code, 200)
     self.assertTrue(form_re.search(response.content.decode()) is not None)
コード例 #2
0
 def testCompleteLimit(self):
     for i in range(3,10):
         person = Person(email = '*****@*****.**' % i)
         person.save()
     response = self.client.get('/submitter/', {'q': 'test', 'l': 5})
     self.assertEquals(response.status_code, 200)
     data = json.loads(response.content)
     self.assertEquals(len(data), 5)
コード例 #3
0
ファイル: test_series.py プロジェクト: anderco/patchwork
    def setUp(self):
        # Create a 'chris' User and Person
        mail = '*****@*****.**'
        self.user = User.objects.create_user('chris', mail, 'securepass')
        person = Person(email=mail)
        person.link_to_user(self.user)
        person.save()

        super(EventLogTest, self).setUp()
コード例 #4
0
ファイル: test_list.py プロジェクト: lsandoval/patchwork
    def setUp(self):
        defaults.project.save()

        for (name, email, date) in self.patchmeta:
            patch_name = 'testpatch' + name
            person = Person(name = name, email = email)
            person.save()
            patch = Patch(project = defaults.project, msgid = patch_name,
                        submitter = person, content = '', date = date)
            patch.save()
コード例 #5
0
ファイル: utils.py プロジェクト: lsandoval/patchwork
def create_user():
    global _user_idx
    userid = "test%d" % _user_idx
    email = "*****@*****.**" % userid
    _user_idx += 1

    user = User.objects.create_user(userid, email, userid)
    user.save()

    person = Person(email=email, name=userid, user=user)
    person.save()

    return user
コード例 #6
0
ファイル: user.py プロジェクト: computersforpeace/patchwork
def register_confirm(request, conf):
    conf.user.is_active = True
    conf.user.save()
    conf.deactivate()
    try:
        person = Person.objects.get(email__iexact = conf.user.email)
    except Person.DoesNotExist:
        person = Person(email = conf.user.email,
                name = conf.user.profile.name())
    person.user = conf.user
    person.save()

    return render_to_response('patchwork/registration-confirm.html')
コード例 #7
0
ファイル: user.py プロジェクト: asl/llvm-patchwork
def link_confirm(request, conf):
    context = PatchworkRequestContext(request)

    try:
        person = Person.objects.get(email__iexact = conf.email)
    except Person.DoesNotExist:
        person = Person(email = conf.email)

    person.link_to_user(conf.user)
    person.save()
    conf.deactivate()

    context['person'] = person

    return render_to_response('patchwork/user-link-confirm.html', context)
コード例 #8
0
ファイル: utils.py プロジェクト: nickglobal/patchwork
def create_person(**kwargs):
    """Create a 'Person' object."""
    num = Person.objects.count()

    values = {
        'email': '*****@*****.**' % num,
        'name': 'test_person_%d' % num,
        'user': None,
    }
    values.update(kwargs)

    person = Person(**values)
    person.save()

    return person
コード例 #9
0
ファイル: user.py プロジェクト: getpatchwork/patchwork
def link_confirm(request, conf):
    try:
        person = Person.objects.get(email__iexact=conf.email)
    except Person.DoesNotExist:
        person = Person(email=conf.email)

    person.link_to_user(conf.user)
    person.save()
    conf.deactivate()

    context = {
        'person': person,
    }

    return render(request, 'patchwork/user-link-confirm.html', context)
コード例 #10
0
    def test_existing_person_unmodified(self):
        """Check that an unconfirmed registration can't modify an existing
           Person object."""
        person = Person(name=self.user.fullname, email=self.user.email)
        person.save()

        # register
        data = self.default_data.copy()
        data['first_name'] = 'invalid'
        data['last_name'] = 'invalid'
        self.assertEqual(data['email'], person.email)
        response = self.client.post('/register/', data)
        self.assertEqual(response.status_code, 200)

        self.assertEqual(Person.objects.get(pk=person.pk).name,
                         self.user.fullname)
コード例 #11
0
    def test_existing_person_unmodified(self):
        """Check that an unconfirmed registration can't modify an existing
           Person object."""
        person = Person(name=self.user.fullname, email=self.user.email)
        person.save()

        # register
        data = self.default_data.copy()
        data['first_name'] = 'invalid'
        data['last_name'] = 'invalid'
        self.assertEqual(data['email'], person.email)
        response = self.client.post('/register/', data)
        self.assertEqual(response.status_code, 200)

        self.assertEqual(
            Person.objects.get(pk=person.pk).name, self.user.fullname)
コード例 #12
0
    def test_existing_person_unmodified(self):
        """Ensure an existing person is not linked until registration is done.

        Create an account for a user using an email we've previously seen but
        don't confirm it. Check that the person object is not updated yet.
        """
        person = Person(name=self.user.fullname, email=self.user.email)
        person.save()

        # register
        data = self.default_data.copy()
        data['first_name'] = 'invalid'
        data['last_name'] = 'invalid'
        self.assertEqual(data['email'], person.email)
        response = self.client.post('/register/', data)
        self.assertEqual(response.status_code, 200)

        self.assertEqual(
            Person.objects.get(pk=person.pk).name, self.user.fullname)
コード例 #13
0
    def test_existing_person_setup(self):
        """ Check that the person object created after registration has the
            correct details """
        person = Person(name=self.user.fullname, email=self.user.email)
        person.save()

        # register
        self.assertEqual(EmailConfirmation.objects.count(), 0)
        response = self.client.post('/register/', self.default_data)
        self.assertEqual(response.status_code, 200)

        # confirm
        conf = EmailConfirmation.objects.filter()[0]
        response = self.client.get(_confirmation_url(conf))
        self.assertEqual(response.status_code, 200)

        person = Person.objects.get(email=self.user.email)

        self.assertEqual(person.name, self.user.fullname)
コード例 #14
0
    def test_existing_person_setup(self):
        """ Check that the person object created after registration has the
            correct details """
        person = Person(name=self.user.fullname, email=self.user.email)
        person.save()

        # register
        self.assertEqual(EmailConfirmation.objects.count(), 0)
        response = self.client.post('/register/', self.default_data)
        self.assertEqual(response.status_code, 200)

        # confirm
        conf = EmailConfirmation.objects.filter()[0]
        response = self.client.get(_confirmation_url(conf))
        self.assertEqual(response.status_code, 200)

        person = Person.objects.get(email=self.user.email)

        self.assertEqual(person.name, self.user.fullname)
コード例 #15
0
ファイル: test_rest.py プロジェクト: dlespiau/patchwork
    def testPullRequestEvent(self):
        submitter = Person()
        submitter.save()

        patch = Patch(project=self.project,
                      pull_url="git://foo.bar master",
                      submitter=submitter)
        patch.save()

        # n events for n series, +1 for the pull request above
        events = self.get_json('/projects/%(project_id)s/events/')
        self.assertEqual(events['count'], self.n_series + 1)

        prs = filter(lambda r: r['name'] == 'pull-request-new',
                     events['results'])
        prs = list(prs)
        self.assertEqual(len(prs), 1)

        self.assertEqual(prs[0]['patch'], patch.id)
        self.assertEqual(prs[0]['parameters']['pull_url'], patch.pull_url)
コード例 #16
0
ファイル: test_encodings.py プロジェクト: lsandoval/patchwork
 def setUp(self):
     defaults.project.save()
     self.patch_author = Person(name = self.patch_author_name,
         email = defaults.patch_author_person.email)
     self.patch_author.save()
     self.patch_content = read_patch(self.patch_filename,
             encoding = self.patch_encoding)
     self.patch = Patch(project = defaults.project,
                        msgid = 'x', name = defaults.patch_name,
                        submitter = self.patch_author,
                        content = self.patch_content)
     self.patch.save()
     self.client = Client()
コード例 #17
0
    def test_existing_person_setup(self):
        """Ensure an existing person is linked after account setup.

        Create an account for a user using an email we've previously seen.
        Check that the person object is updated after registration with the
        correct details.
        """
        person = Person(name=self.user.fullname, email=self.user.email)
        person.save()

        # register
        self.assertEqual(EmailConfirmation.objects.count(), 0)
        response = self.client.post('/register/', self.default_data)
        self.assertEqual(response.status_code, 200)

        # confirm
        conf = EmailConfirmation.objects.filter()[0]
        response = self.client.get(_confirmation_url(conf))
        self.assertEqual(response.status_code, 200)

        person = Person.objects.get(email=self.user.email)

        self.assertEqual(person.name, self.user.fullname)
コード例 #18
0
ファイル: encodings.py プロジェクト: asl/llvm-patchwork
class UTF8HeaderPatchViewTest(UTF8PatchViewTest):
    patch_filename = '0002-utf-8.patch'
    patch_encoding = 'utf-8'
    patch_author_name = u'P\xe4tch Author'

    def setUp(self):
        defaults.project.save()
        self.patch_author = Person(name = self.patch_author_name,
            email = defaults.patch_author_person.email)
        self.patch_author.save()
        self.patch_content = read_patch(self.patch_filename,
                encoding = self.patch_encoding)
        self.patch = Patch(project = defaults.project,
                           msgid = 'x', name = defaults.patch_name,
                           submitter = self.patch_author,
                           content = self.patch_content)
        self.patch.save()
        self.client = Client()

    def tearDown(self):
        self.patch.delete()
        self.patch_author.delete()
        defaults.project.delete()
コード例 #19
0
    def setUp(self):
        # Create a 'chris' User and Person
        mail = '*****@*****.**'
        self.user = User.objects.create_user('chris', mail, 'securepass')
        person = Person(email=mail)
        person.link_to_user(self.user)
        person.save()

        super(EventLogTest, self).setUp()
コード例 #20
0
def find_author(mail):
    from_header = clean_header(mail.get('From'))

    if not from_header:
        raise ValueError("Invalid 'From' header")

    name, email = (None, None)

    # tuple of (regex, fn)
    #  - where fn returns a (name, email) tuple from the match groups resulting
    #    from re.match().groups()
    # TODO(stephenfin): Perhaps we should check for "real" email addresses
    # instead of anything ('.*?')
    from_res = [
        # for "Firstname Lastname" <*****@*****.**> style addresses
        (re.compile(r'"?(.*?)"?\s*<([^>]+)>'), (lambda g: (g[0], g[1]))),

        # for example at example.com (Firstname Lastname) style addresses
        (re.compile(r'(.*?)\sat\s(.*?)\s*\(([^\)]+)\)'),
         (lambda g: (g[2], '@'.join(g[0:2])))),

        # for [email protected] (Firstname Lastname) style addresses
        (re.compile(r'"?(.*?)"?\s*\(([^\)]+)\)'), (lambda g: (g[1], g[0]))),

        # everything else
        (re.compile(r'(.*)'), (lambda g: (None, g[0]))),
    ]

    for regex, fn in from_res:
        match = regex.match(from_header)
        if match:
            (name, email) = fn(match.groups())
            break

    if not email:
        raise ValueError("Invalid 'From' header")

    email = email.strip()[:255]
    if name is not None:
        name = name.strip()[:255]

    try:
        person = Person.objects.get(email__iexact=email)
        if name:  # use the latest provided name
            person.name = name
    except Person.DoesNotExist:
        person = Person(name=name, email=email)

    return person
コード例 #21
0
def link_confirm(request, conf):
    try:
        person = Person.objects.get(email__iexact=conf.email)
    except Person.DoesNotExist:
        person = Person(email=conf.email)

    person.link_to_user(conf.user)
    person.save()
    conf.deactivate()

    return render(request, 'patchwork/user-link-confirm.html',
                  {'person': person})
コード例 #22
0
ファイル: parsemail.py プロジェクト: ykhuat/patchwork
def find_author(mail):

    from_header = clean_header(mail.get('From'))
    (name, email) = (None, None)

    # tuple of (regex, fn)
    #  - where fn returns a (name, email) tuple from the match groups resulting
    #    from re.match().groups()
    from_res = [
        # for "Firstname Lastname" <*****@*****.**> style addresses
        (re.compile(r'"?(.*?)"?\s*<([^>]+)>'), (lambda g: (g[0], g[1]))),

        # for [email protected] (Firstname Lastname) style addresses
        (re.compile(r'"?(.*?)"?\s*\(([^\)]+)\)'), (lambda g: (g[1], g[0]))),

        # everything else
        (re.compile(r'(.*)'), (lambda g: (None, g[0]))),
    ]

    for regex, fn in from_res:
        match = regex.match(from_header)
        if match:
            (name, email) = fn(match.groups())
            break

    if email is None:
        raise Exception("Could not parse From: header")

    email = email.strip()
    if name is not None:
        name = name.strip()

    save_required = False

    try:
        person = Person.objects.get(email__iexact=email)
        if person.name != name:
            person.name = name
            save_required = True
    except Person.DoesNotExist:
        person = Person(name=name, email=email)
        save_required = True

    return (person, save_required)
コード例 #23
0
def link_confirm(request, conf):
    context = PatchworkRequestContext(request)

    try:
        person = Person.objects.get(email__iexact=conf.email)
    except Person.DoesNotExist:
        person = Person(email=conf.email)

    person.link_to_user(conf.user)
    person.save()
    conf.deactivate()

    context['person'] = person

    return render_to_response('patchwork/user-link-confirm.html', context)
コード例 #24
0
ファイル: test_person.py プロジェクト: ykhuat/patchwork
 def testEmailNameQuoted(self):
     p = Person(name="Name, Test", email="*****@*****.**")
     self.assertEqual(p.email_name(), '"Name, Test" <*****@*****.**>')
コード例 #25
0
 def setUp(self):
     self.people = [
         Person(name = "Test Name", email = "*****@*****.**"),
         Person(email = "*****@*****.**"),
     ]
     map(lambda p: p.save(), self.people)