コード例 #1
0
ファイル: test_person.py プロジェクト: stephenfin/patchwork
    def test_list_anonymous(self):
        """List people as anonymous user."""
        create_person()

        # anonymous user
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)
コード例 #2
0
ファイル: test_completion.py プロジェクト: alialnu/patchwork
 def test_name_complete(self):
     people = [create_person(name='Test name'), create_person(name=None)]
     response = self.client.get(reverse('api-submitters'), {'q': 'name'})
     self.assertEqual(response.status_code, 200)
     data = json.loads(response.content.decode())
     self.assertEqual(len(data), 1)
     self.assertEqual(data[0]['name'], people[0].name)
コード例 #3
0
 def test_name_complete(self):
     people = [create_person(name='Test name'), create_person(name=None)]
     response = self.client.get(reverse('api-submitters'), {'q': 'name'})
     self.assertEqual(response.status_code, 200)
     data = json.loads(response.content.decode())
     self.assertEqual(len(data), 1)
     self.assertEqual(data[0]['name'], people[0].name)
コード例 #4
0
    def test_update_authorized(self):
        """Update an existing cover letter comment as an authorized user.

        To be authorized users must meet at least one of the following:
        - project maintainer, cover letter submitter, or cover letter
          comment submitter

        Ensure updates can only be performed by authorized users.
        """
        # Update as maintainer
        person = create_person(user=self.user)
        resp = self._test_update(person=person)
        self.assertEqual(1, CoverComment.objects.all().count())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertTrue(resp.data['addressed'])

        # Update as cover letter submitter
        person = create_person(name='cover-submitter', user=create_user())
        cover = create_cover(submitter=person)
        resp = self._test_update(person=person, cover=cover)
        self.assertEqual(2, CoverComment.objects.all().count())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertTrue(resp.data['addressed'])

        # Update as cover letter comment submitter
        person = create_person(name='comment-submitter', user=create_user())
        cover = create_cover()
        resp = self._test_update(person=person, cover=cover, submitter=person)
        self.assertEqual(3, CoverComment.objects.all().count())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertTrue(resp.data['addressed'])
コード例 #5
0
    def test_list_anonymous(self):
        """List people as anonymous user."""
        create_person()

        # anonymous user
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)
コード例 #6
0
ファイル: test_completion.py プロジェクト: alialnu/patchwork
 def test_email_complete(self):
     people = [create_person(email='*****@*****.**'),
               create_person(email='*****@*****.**')]
     response = self.client.get(reverse('api-submitters'), {'q': 'test2'})
     self.assertEqual(response.status_code, 200)
     data = json.loads(response.content.decode())
     self.assertEqual(len(data), 1)
     self.assertEqual(data[0]['email'], people[1].email)
コード例 #7
0
ファイル: test_completion.py プロジェクト: alialnu/patchwork
 def test_param_limit(self):
     for i in range(10):
         create_person()
     response = self.client.get(reverse('api-submitters'),
                                {'q': 'test', 'l': 5})
     self.assertEqual(response.status_code, 200)
     data = json.loads(response.content.decode())
     self.assertEqual(len(data), 5)
コード例 #8
0
 def test_email_complete(self):
     people = [
         create_person(email='*****@*****.**'),
         create_person(email='*****@*****.**')
     ]
     response = self.client.get(reverse('api-submitters'), {'q': 'test2'})
     self.assertEqual(response.status_code, 200)
     data = json.loads(response.content.decode())
     self.assertEqual(len(data), 1)
     self.assertEqual(data[0]['email'], people[1].email)
コード例 #9
0
 def test_param_limit(self):
     for i in range(10):
         create_person()
     response = self.client.get(reverse('api-submitters'), {
         'q': 'test',
         'l': 5
     })
     self.assertEqual(response.status_code, 200)
     data = json.loads(response.content.decode())
     self.assertEqual(len(data), 5)
コード例 #10
0
    def test_update_not_authorized(self):
        """Update an existing patch comment when not signed in and not authorized.

        To be authorized users must meet at least one of the following:
        - project maintainer, patch submitter, patch delegate, or
          patch comment submitter

        Ensure updates can only be performed by authorized users.
        """
        person = create_person(user=self.user)
        resp = self._test_update(person=person, authenticate=False)
        self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)

        person = create_person()  # normal user without edit permissions
        resp = self._test_update(person=person)  # signed-in
        self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)
コード例 #11
0
ファイル: test_person.py プロジェクト: stephenfin/patchwork
    def test_detail_anonymous(self):
        """Show person as anonymous user."""
        person = create_person()

        # anonymous user
        resp = self.client.get(self.api_url(person.id))
        self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)
コード例 #12
0
    def test_detail_anonymous(self):
        """Show person as anonymous user."""
        person = create_person()

        # anonymous user
        resp = self.client.get(self.api_url(person.id))
        self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)
コード例 #13
0
ファイル: test_list.py プロジェクト: alialnu/patchwork
    def setUp(self):
        self.project = create_project()

        for name, email, date in self.patchmeta:
            person = create_person(name=name, email=email)
            create_patch(submitter=person, project=self.project,
                         date=date)
コード例 #14
0
    def setUp(self):
        self.project = create_project()

        for name, email, date in self.patchmeta:
            person = create_person(name=name, email=email)
            create_patch(submitter=person, project=self.project,
                         date=date)
コード例 #15
0
 def test_secondary_email_optin_form(self):
     person = create_person(email=self.secondary_email, user=self.user)
     EmailOptout(email=person.email).save()
     form_re = self._form_re(reverse('mail-optin'), person.email)
     response = self.client.get(reverse('user-profile'))
     self.assertEqual(response.status_code, 200)
     self.assertIsNotNone(form_re.search(response.content.decode()))
コード例 #16
0
    def test_valid_relations(self):
        test_submitter = utils.create_person()
        utils.create_patches(8, submitter=test_submitter)
        patch_ids = models.Patch.objects.filter(
            submitter=test_submitter).values_list('id', flat=True)

        with tempfile.NamedTemporaryFile(delete=False, mode='w+') as f1:
            for i in range(0, len(patch_ids), 3):
                # we write out the patch IDs this way so that we can
                # have a mix of 3-patch and 2-patch lines without special
                # casing the format string.
                f1.write('%s\n' % ' '.join(map(str, patch_ids[i:(i + 3)])))

        out = StringIO()
        call_command('replacerelations', f1.name, stdout=out)
        self.assertEqual(models.PatchRelation.objects.count(), 3)
        os.unlink(f1.name)

        patch_ids_with_missing = list(patch_ids) + [
            i for i in range(max(patch_ids),
                             max(patch_ids) + 3)
        ]
        with tempfile.NamedTemporaryFile(delete=False, mode='w+') as f2:
            for i in range(0, len(patch_ids_with_missing), 3):
                f2.write('%s\n' %
                         ' '.join(map(str, patch_ids_with_missing[i:(i + 3)])))

        call_command('replacerelations', f2.name, stdout=out)
        self.assertEqual(models.PatchRelation.objects.count(), 3)
        os.unlink(f2.name)
コード例 #17
0
    def _create_series(self):
        project_obj = create_project(linkname='myproject')
        person_obj = create_person(email='*****@*****.**')
        series_obj = create_series(project=project_obj, submitter=person_obj)
        create_cover(series=series_obj)
        create_patch(series=series_obj)

        return series_obj
コード例 #18
0
    def _create_patch(self, **kwargs):
        person_obj = create_person(email='*****@*****.**')
        project_obj = create_project(linkname='myproject')
        state_obj = create_state(name='Under Review')
        patch_obj = create_patch(state=state_obj, project=project_obj,
                                 submitter=person_obj, **kwargs)

        return patch_obj
コード例 #19
0
ファイル: test_patch.py プロジェクト: stephenfin/patchwork
    def _create_patch(self, **kwargs):
        person_obj = create_person(email='*****@*****.**')
        project_obj = create_project(linkname='myproject')
        state_obj = create_state(name='Under Review')
        patch_obj = create_patch(state=state_obj, project=project_obj,
                                 submitter=person_obj, **kwargs)

        return patch_obj
コード例 #20
0
ファイル: test_series.py プロジェクト: stephenfin/patchwork
    def _create_series(self):
        project_obj = create_project(linkname='myproject')
        person_obj = create_person(email='*****@*****.**')
        series_obj = create_series(project=project_obj, submitter=person_obj)
        create_cover(series=series_obj)
        create_patch(series=series_obj)

        return series_obj
コード例 #21
0
    def test_detail_unlinked(self):
        """Show unlinked person as authenticted user."""
        person = create_person()
        user = create_user(link_person=False)
        self.client.force_authenticate(user=user)

        resp = self.client.get(self.api_url(person.id))
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertSerialized(person, resp.data, has_user=False)
コード例 #22
0
ファイル: test_person.py プロジェクト: stephenfin/patchwork
    def test_detail_unlinked(self):
        """Show unlinked person as authenticted user."""
        person = create_person()
        user = create_user(link_person=False)
        self.client.force_authenticate(user=user)

        resp = self.client.get(self.api_url(person.id))
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertSerialized(person, resp.data, has_user=False)
コード例 #23
0
 def setUp(self):
     project = create_project()
     self.person = create_person()
     self.patch = create_patch(project=project,
                               submitter=self.person,
                               content='comment 1 text\nAcked-by: 1\n')
     self.comment = create_comment(submission=self.patch,
                                   submitter=self.person,
                                   content='comment 2 text\nAcked-by: 2\n')
コード例 #24
0
    def test_list_authenticated(self):
        """List people as an authenticated user."""
        person = create_person()
        user = create_user(link_person=False)

        self.client.force_authenticate(user=user)
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        self.assertSerialized(person, resp.data[0])
コード例 #25
0
ファイル: test_person.py プロジェクト: stephenfin/patchwork
    def test_list_authenticated(self):
        """List people as an authenticated user."""
        person = create_person()
        user = create_user(link_person=False)

        self.client.force_authenticate(user=user)
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        self.assertSerialized(person, resp.data[0])
コード例 #26
0
ファイル: test_mboxviews.py プロジェクト: daxtens/patchwork
    def test_patchwork_from_header(self):
        """Validate inclusion of generated 'X-Patchwork-From' header."""
        email = '*****@*****.**'
        from_header = 'From: Jon Doe <%s>\n' % email

        person = create_person(name='Jonathon Doe', email=email)
        patch = create_patch(submitter=person, headers=from_header)
        response = self.client.get(reverse('patch-mbox', args=[patch.id]))
        self.assertContains(response, from_header)
        self.assertContains(response, 'X-Patchwork-Submitter: %s <%s>' % (
            person.name, email))
コード例 #27
0
    def test_unlinked_user(self):
        person = create_person()
        user = create_user()
        self.client.force_authenticate(user=user)

        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(2, len(resp.data))
        self.assertEqual(person.name,
                         resp.data[0]['name'])
        self.assertIsNone(resp.data[0]['user_url'])
コード例 #28
0
ファイル: test_mboxviews.py プロジェクト: ajdlinux/patchwork
    def test_patchwork_from_header(self):
        """Validate inclusion of generated 'X-Patchwork-From' header."""
        email = '*****@*****.**'
        from_header = 'From: Jon Doe <%s>\n' % email

        person = create_person(name='Jonathon Doe', email=email)
        patch = create_patch(submitter=person, headers=from_header)
        response = self.client.get(reverse('patch-mbox', args=[patch.id]))
        self.assertContains(response, from_header)
        self.assertContains(response, 'X-Patchwork-Submitter: %s <%s>' % (
            person.name, email))
コード例 #29
0
 def setUp(self):
     project = create_project()
     self.person = create_person()
     self.patch = create_patch(
         project=project,
         submitter=self.person,
         content='comment 1 text\nAcked-by: 1\n')
     self.comment = create_comment(
         submission=self.patch,
         submitter=self.person,
         content='comment 2 text\nAcked-by: 2\n')
コード例 #30
0
ファイル: test_mboxviews.py プロジェクト: wangxi11/patchwork
 def setUp(self):
     self.project = create_project()
     self.person = create_person()
     self.patch = create_patch(
         project=self.project,
         submitter=self.person,
         diff='',
         content='comment 1 text\nAcked-by: 1\n---\nupdate\n')
     self.comment = create_patch_comment(
         patch=self.patch,
         submitter=self.person,
         content='comment 2 text\nAcked-by: 2\n')
コード例 #31
0
    def test_anonymous_create(self):
        """Ensure anonymous "POST" operations are rejected."""
        patch = {
            'project': create_project().id,
            'submitter': create_person().id,
            'msgid': make_msgid(),
            'name': 'test-create-patch',
            'diff': 'patch diff',
        }

        resp = self.client.post(self.api_url(), patch)
        self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)
コード例 #32
0
    def test_list(self):
        """Validate we can list a patch."""
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(0, len(resp.data))

        person_obj = create_person(email='*****@*****.**')
        state_obj = create_state(name='Under Review')
        project_obj = create_project(linkname='myproject')
        patch_obj = create_patch(state=state_obj,
                                 project=project_obj,
                                 submitter=person_obj)

        # anonymous user
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        patch_rsp = resp.data[0]
        self.assertSerialized(patch_obj, patch_rsp)
        self.assertNotIn('headers', patch_rsp)
        self.assertNotIn('content', patch_rsp)
        self.assertNotIn('diff', patch_rsp)

        # authenticated user
        user = create_user()
        self.client.force_authenticate(user=user)
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        patch_rsp = resp.data[0]
        self.assertSerialized(patch_obj, patch_rsp)

        # test filtering by state
        resp = self.client.get(self.api_url(), {'state': 'under-review'})
        self.assertEqual([patch_obj.id], [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(), {'state': 'missing-state'})
        self.assertEqual(0, len(resp.data))

        # test filtering by project
        resp = self.client.get(self.api_url(), {'project': 'myproject'})
        self.assertEqual([patch_obj.id], [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(), {'project': 'invalidproject'})
        self.assertEqual(0, len(resp.data))

        # test filtering by submitter, both ID and email
        resp = self.client.get(self.api_url(), {'submitter': person_obj.id})
        self.assertEqual([patch_obj.id], [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(),
                               {'submitter': '*****@*****.**'})
        self.assertEqual([patch_obj.id], [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(),
                               {'submitter': '*****@*****.**'})
        self.assertEqual(0, len(resp.data))
コード例 #33
0
    def test_patchwork_submitter_header(self):
        """Validate inclusion of generated 'X-Patchwork-Submitter' header."""
        email = '*****@*****.**'
        from_header = f'From: Jon Doe <{email}>\n'
        person = create_person(name='Jonathon Doe', email=email)
        submitter_header = f'X-Patchwork-Submitter: {person.name} <{email}>'

        patch = create_patch(submitter=person, headers=from_header)

        mbox = utils.patch_to_mbox(patch)
        self.assertIn(from_header, mbox)
        self.assertIn(submitter_header, mbox)
コード例 #34
0
ファイル: test_rest_api.py プロジェクト: alialnu/patchwork
    def test_list(self):
        """Validate we can list a patch."""
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(0, len(resp.data))

        person_obj = create_person(email='*****@*****.**')
        state_obj = create_state(name='Under Review')
        project_obj = create_project(linkname='myproject')
        patch_obj = create_patch(state=state_obj, project=project_obj,
                                 submitter=person_obj)

        # anonymous user
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        patch_rsp = resp.data[0]
        self.assertSerialized(patch_obj, patch_rsp)
        self.assertNotIn('headers', patch_rsp)
        self.assertNotIn('content', patch_rsp)
        self.assertNotIn('diff', patch_rsp)

        # authenticated user
        user = create_user()
        self.client.force_authenticate(user=user)
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        patch_rsp = resp.data[0]
        self.assertSerialized(patch_obj, patch_rsp)

        # test filtering by state
        resp = self.client.get(self.api_url(), {'state': 'under-review'})
        self.assertEqual([patch_obj.id], [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(), {'state': 'missing-state'})
        self.assertEqual(0, len(resp.data))

        # test filtering by project
        resp = self.client.get(self.api_url(), {'project': 'myproject'})
        self.assertEqual([patch_obj.id], [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(), {'project': 'invalidproject'})
        self.assertEqual(0, len(resp.data))

        # test filtering by submitter, both ID and email
        resp = self.client.get(self.api_url(), {'submitter': person_obj.id})
        self.assertEqual([patch_obj.id], [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(), {
            'submitter': '*****@*****.**'})
        self.assertEqual([patch_obj.id], [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(), {
            'submitter': '*****@*****.**'})
        self.assertEqual(0, len(resp.data))
コード例 #35
0
    def test_from_header(self):
        """Validate non-ascii 'From' header.

        Test that a person with characters outside ASCII in his name do
        produce correct From header. As RFC 2822 state we must retain
        the <*****@*****.**> format for the mail while the name part
        may be coded in some ways.
        """
        person = create_person(name=u'©ool guŷ')
        patch = create_patch(submitter=person)
        from_email = f'<{person.email}>'
        mbox = utils.patch_to_mbox(patch)
        self.assertIn(from_email, mbox)
コード例 #36
0
ファイル: test_mboxviews.py プロジェクト: ajdlinux/patchwork
    def test_from_header(self):
        """Validate non-ascii 'From' header.

        Test that a person with characters outside ASCII in his name do
        produce correct From header. As RFC 2822 state we must retain
        the <*****@*****.**> format for the mail while the name part
        may be coded in some ways.
        """
        person = create_person(name=u'©ool guŷ')
        patch = create_patch(submitter=person)
        from_email = '<' + person.email + '>'
        response = self.client.get(reverse('patch-mbox', args=[patch.id]))
        self.assertContains(response, from_email)
コード例 #37
0
ファイル: test_mboxviews.py プロジェクト: daxtens/patchwork
    def test_from_header(self):
        """Validate non-ascii 'From' header.

        Test that a person with characters outside ASCII in his name do
        produce correct From header. As RFC 2822 state we must retain
        the <*****@*****.**> format for the mail while the name part
        may be coded in some ways.
        """
        person = create_person(name=u'©ool guŷ')
        patch = create_patch(submitter=person)
        from_email = '<' + person.email + '>'
        response = self.client.get(reverse('patch-mbox', args=[patch.id]))
        self.assertContains(response, from_email)
コード例 #38
0
    def test_update_authorized(self):
        """Update an existing patch comment as an authorized user.

        To be authorized users must meet at least one of the following:
        - project maintainer, patch submitter, patch delegate, or
          patch comment submitter

        Ensure updates can only be performed by authorized users.
        """
        # Update as maintainer
        person = create_person(user=self.user)
        resp = self._test_update(person=person)
        self.assertEqual(1, PatchComment.objects.all().count())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertTrue(resp.data['addressed'])

        # Update as patch submitter
        person = create_person(name='patch-submitter', user=create_user())
        patch = create_patch(submitter=person)
        resp = self._test_update(person=person, patch=patch)
        self.assertEqual(2, PatchComment.objects.all().count())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertTrue(resp.data['addressed'])

        # Update as patch delegate
        person = create_person(name='patch-delegate', user=create_user())
        patch = create_patch(delegate=person.user)
        resp = self._test_update(person=person, patch=patch)
        self.assertEqual(3, PatchComment.objects.all().count())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertTrue(resp.data['addressed'])

        # Update as patch comment submitter
        person = create_person(name='comment-submitter', user=create_user())
        patch = create_patch()
        resp = self._test_update(person=person, patch=patch, submitter=person)
        self.assertEqual(4, PatchComment.objects.all().count())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertTrue(resp.data['addressed'])
コード例 #39
0
    def test_list_bug_335(self):
        """Ensure we retrieve the embedded cover letter project in O(1)."""
        project_obj = create_project(linkname='myproject')
        person_obj = create_person(email='*****@*****.**')
        for i in range(10):
            series_obj = create_series(
                project=project_obj, submitter=person_obj,
            )
            create_cover(series=series_obj)
            create_patch(series=series_obj)

        with self.assertNumQueries(6):
            self.client.get(self.api_url())
コード例 #40
0
    def test_update_invalid_addressed(self):
        """Update an existing patch comment using invalid values.

        Ensure we handle invalid patch comment addressed values.
        """
        person = create_person(name='patch-submitter', user=create_user())
        patch = create_patch(submitter=person)
        resp = self._test_update(person=person,
                                 patch=patch,
                                 addressed='not-valid',
                                 validate_request=False)
        self.assertEqual(status.HTTP_400_BAD_REQUEST, resp.status_code)
        self.assertFalse(
            getattr(PatchComment.objects.all().first(), 'addressed'))
コード例 #41
0
ファイル: test_rest_api.py プロジェクト: seanfarley/patchwork
    def test_list(self):
        """This API requires authenticated users."""
        person = create_person()

        # anonymous user
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)

        # authenticated user
        user = create_user(link_person=False)
        self.client.force_authenticate(user=user)

        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        self.assertSerialized(person, resp.data[0])
コード例 #42
0
ファイル: test_rest_api.py プロジェクト: alialnu/patchwork
    def test_list(self):
        """This API requires authenticated users."""
        person = create_person()

        # anonymous user
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)

        # authenticated user
        user = create_user(link_person=False)
        self.client.force_authenticate(user=user)

        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        self.assertSerialized(person, resp.data[0])
コード例 #43
0
    def test_dmarc_from_header(self):
        """Validate 'From' header is rewritten correctly when DMARC-munged.

        Test that when an email with a DMARC-munged From header is processed,
        the From header will be unmunged and the munged address will be saved
        as 'X-Patchwork-Original-From'.
        """
        orig_from_header = 'Person via List <*****@*****.**>'
        rewritten_from_header = 'Person <*****@*****.**>'
        project = create_project(listemail='*****@*****.**')
        person = create_person(name='Person', email='*****@*****.**')
        patch = create_patch(project=project,
                             headers='From: ' + orig_from_header,
                             submitter=person)
        mbox = utils.patch_to_mbox(patch)
        mail = email.message_from_string(mbox)
        self.assertEqual(mail['From'], rewritten_from_header)
        self.assertEqual(mail['X-Patchwork-Original-From'], orig_from_header)
コード例 #44
0
ファイル: test_series.py プロジェクト: Aleks1966/patchwork
    def test_list(self):
        """Validate we can list series."""
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(0, len(resp.data))

        project_obj = create_project(linkname='myproject')
        person_obj = create_person(email='*****@*****.**')
        cover_obj = create_cover()
        series_obj = create_series(project=project_obj, submitter=person_obj)
        series_obj.add_cover_letter(cover_obj)
        create_series_patch(series=series_obj)

        # anonymous users
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        series_rsp = resp.data[0]
        self.assertSerialized(series_obj, series_rsp)

        # authenticated user
        user = create_user()
        self.client.force_authenticate(user=user)
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        series_rsp = resp.data[0]
        self.assertSerialized(series_obj, series_rsp)

        # test filtering by project
        resp = self.client.get(self.api_url(), {'project': 'myproject'})
        self.assertEqual([series_obj.id], [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(), {'project': 'invalidproject'})
        self.assertEqual(0, len(resp.data))

        # test filtering by owner, both ID and email
        resp = self.client.get(self.api_url(), {'submitter': person_obj.id})
        self.assertEqual([series_obj.id], [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(),
                               {'submitter': '*****@*****.**'})
        self.assertEqual([series_obj.id], [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(),
                               {'submitter': '*****@*****.**'})
        self.assertEqual(0, len(resp.data))
コード例 #45
0
    def test_create(self):
        """Ensure creations are rejected."""
        submitter = create_person()
        project = create_project()
        user = create_maintainer(project)
        user.is_superuser = True
        user.save()
        self.client.force_authenticate(user=user)

        patch = {
            'project': project.id,
            'submitter': submitter.id,
            'msgid': make_msgid(),
            'name': 'test-create-patch',
            'diff': 'patch diff',
        }

        resp = self.client.post(self.api_url(), patch)
        self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)
コード例 #46
0
ファイル: test_series.py プロジェクト: daxtens/patchwork
    def test_list(self):
        """Validate we can list series."""
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(0, len(resp.data))

        project_obj = create_project(linkname='myproject')
        person_obj = create_person(email='*****@*****.**')
        series_obj = create_series(project=project_obj, submitter=person_obj)
        create_cover(series=series_obj)
        create_patch(series=series_obj)

        # anonymous users
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        series_rsp = resp.data[0]
        self.assertSerialized(series_obj, series_rsp)

        # authenticated user
        user = create_user()
        self.client.force_authenticate(user=user)
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        series_rsp = resp.data[0]
        self.assertSerialized(series_obj, series_rsp)

        # test filtering by project
        resp = self.client.get(self.api_url(), {'project': 'myproject'})
        self.assertEqual([series_obj.id], [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(), {'project': 'invalidproject'})
        self.assertEqual(0, len(resp.data))

        # test filtering by owner, both ID and email
        resp = self.client.get(self.api_url(), {'submitter': person_obj.id})
        self.assertEqual([series_obj.id], [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(), {
            'submitter': '*****@*****.**'})
        self.assertEqual([series_obj.id], [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(), {
            'submitter': '*****@*****.**'})
        self.assertEqual(0, len(resp.data))
コード例 #47
0
ファイル: test_rest_api.py プロジェクト: alialnu/patchwork
    def test_create(self):
        """Ensure creations are rejected."""
        project = create_project()
        patch = {
            'project': project,
            'submitter': create_person().id,
            'msgid': make_msgid(),
            'name': 'test-create-patch',
            'diff': 'patch diff',
        }

        # anonymous user
        resp = self.client.post(self.api_url(), patch)
        self.assertEqual(status.HTTP_405_METHOD_NOT_ALLOWED, resp.status_code)

        # superuser
        user = create_maintainer(project)
        user.is_superuser = True
        user.save()
        self.client.force_authenticate(user=user)
        resp = self.client.post(self.api_url(), patch)
        self.assertEqual(status.HTTP_405_METHOD_NOT_ALLOWED, resp.status_code)
コード例 #48
0
ファイル: test_rest_api.py プロジェクト: alialnu/patchwork
    def test_detail(self):
        person = create_person()

        # anonymous user
        resp = self.client.get(self.api_url(person.id))
        self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)

        # authenticated, unlinked user
        user = create_user(link_person=False)
        self.client.force_authenticate(user=user)

        resp = self.client.get(self.api_url(person.id))
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertSerialized(person, resp.data, has_user=False)

        # authenticated, linked user
        user = create_user(link_person=True)
        person = user.person_set.all().first()
        self.client.force_authenticate(user=user)

        resp = self.client.get(self.api_url(person.id))
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertSerialized(person, resp.data, has_user=True)
コード例 #49
0
 def setUp(self):
     author = create_person(name=u'P\xe4tch Author')
     patch_content = read_patch('0002-utf-8.patch', encoding='utf-8')
     self.patch = create_patch(submitter=author, diff=patch_content)
コード例 #50
0
ファイル: test_mboxviews.py プロジェクト: daxtens/patchwork
 def setUp(self):
     self.project = create_project()
     self.person = create_person()