Пример #1
0
    def test_post_with_missing_data(self):
        """Testing the POST review-requests/<id>/diffs/ API
        with Invalid Form Data
        """
        repository = self.create_repository(tool_name="Test")
        review_request = self.create_review_request(repository=repository, submitter=self.user)

        rsp = self.apiPost(get_diff_list_url(review_request), expected_status=400)
        self.assertEqual(rsp["stat"], "fail")
        self.assertEqual(rsp["err"]["code"], INVALID_FORM_DATA.code)
        self.assertTrue("path" in rsp["fields"])

        # Now test with a valid path and an invalid basedir.
        # This is necessary because basedir is "optional" as defined by
        # the resource, but may be required by the form that processes the
        # diff.
        review_request = self.create_review_request(repository=repository, submitter=self.user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__), "testdata", "git_readme.diff")
        f = open(diff_filename, "r")
        rsp = self.apiPost(get_diff_list_url(review_request), {"path": f}, expected_status=400)
        f.close()

        self.assertEqual(rsp["stat"], "fail")
        self.assertEqual(rsp["err"]["code"], INVALID_FORM_DATA.code)
        self.assertTrue("basedir" in rsp["fields"])
Пример #2
0
    def test_post_with_missing_data(self):
        """Testing the POST review-requests/<id>/diffs/ API
        with Invalid Form Data
        """
        repository = self.create_repository(tool_name='Test')
        review_request = self.create_review_request(
            repository=repository,
            submitter=self.user)

        rsp = self.api_post(get_diff_list_url(review_request),
                            expected_status=400)
        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
        self.assertIn('path', rsp['fields'])

        # Now test with a valid path and an invalid basedir.
        # This is necessary because basedir is "optional" as defined by
        # the resource, but may be required by the form that processes the
        # diff.
        review_request = self.create_review_request(
            repository=repository,
            submitter=self.user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                     'testdata', 'git_readme.diff')
        with open(diff_filename, "r") as f:
            rsp = self.api_post(
                get_diff_list_url(review_request),
                {'path': f},
                expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
        self.assertIn('basedir', rsp['fields'])
Пример #3
0
    def test_post_with_missing_data(self):
        """Testing the POST review-requests/<id>/diffs/ API
        with Invalid Form Data
        """
        repository = self.create_repository(tool_name='Test')
        review_request = self.create_review_request(
            repository=repository,
            submitter=self.user)

        rsp = self.api_post(get_diff_list_url(review_request),
                            expected_status=400)
        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
        self.assertIn('path', rsp['fields'])

        # Now test with a valid path and an invalid basedir.
        # This is necessary because basedir is "optional" as defined by
        # the resource, but may be required by the form that processes the
        # diff.
        review_request = self.create_review_request(
            repository=repository,
            submitter=self.user)

        diff = SimpleUploadedFile('diff', self.DEFAULT_GIT_README_DIFF,
                                  content_type='text/x-patch')

        rsp = self.api_post(
            get_diff_list_url(review_request),
            {'path': diff},
            expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
        self.assertIn('basedir', rsp['fields'])
Пример #4
0
    def test_post_with_missing_data(self):
        """Testing the POST review-requests/<id>/diffs/ API
        with Invalid Form Data
        """
        repository = self.create_repository(tool_name='Test')
        review_request = self.create_review_request(repository=repository,
                                                    submitter=self.user)

        rsp = self.api_post(get_diff_list_url(review_request),
                            expected_status=400)
        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
        self.assertIn('path', rsp['fields'])

        # Now test with a valid path and an invalid basedir.
        # This is necessary because basedir is "optional" as defined by
        # the resource, but may be required by the form that processes the
        # diff.
        review_request = self.create_review_request(repository=repository,
                                                    submitter=self.user)

        diff = SimpleUploadedFile('diff',
                                  self.DEFAULT_GIT_README_DIFF,
                                  content_type='text/x-patch')

        rsp = self.api_post(get_diff_list_url(review_request), {'path': diff},
                            expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
        self.assertIn('basedir', rsp['fields'])
Пример #5
0
    def test_post_with_missing_data(self):
        """Testing the POST review-requests/<id>/diffs/ API
        with Invalid Form Data
        """
        repository = self.create_repository(tool_name='Test')
        review_request = self.create_review_request(repository=repository,
                                                    submitter=self.user)

        rsp = self.api_post(get_diff_list_url(review_request),
                            expected_status=400)
        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
        self.assertIn('path', rsp['fields'])

        # Now test with a valid path and an invalid basedir.
        # This is necessary because basedir is "optional" as defined by
        # the resource, but may be required by the form that processes the
        # diff.
        review_request = self.create_review_request(repository=repository,
                                                    submitter=self.user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                     'testdata', 'git_readme.diff')
        with open(diff_filename, "r") as f:
            rsp = self.api_post(get_diff_list_url(review_request), {'path': f},
                                expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
        self.assertIn('basedir', rsp['fields'])
Пример #6
0
    def test_post_adds_default_reviewers(self):
        """Testing the POST <URL> API adds default reviewers"""
        review_request = self.create_review_request(submitter=self.user,
                                                    create_repository=True)

        # Create the state needed for the default reviewer.
        group = self.create_review_group(name='group1')

        default_reviewer = DefaultReviewer.objects.create(
            name='default1',
            file_regex='.')
        default_reviewer.groups.add(group)
        default_reviewer.repository.add(review_request.repository)

        # Post the diff.
        diff = SimpleUploadedFile('diff', self.DEFAULT_GIT_README_DIFF,
                                  content_type='text/x-patch')

        rsp = self.api_post(
            get_diff_list_url(review_request),
            {'path': diff},
            expected_mimetype=diff_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        draft = review_request.get_draft()
        self.assertEqual(list(draft.target_groups.all()), [group])
Пример #7
0
    def test_post(self):
        """Testing the POST review-requests/<id>/diffs/ API"""
        repository = self.create_repository(tool_name='Test')
        review_request = self.create_review_request(
            repository=repository,
            submitter=self.user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                     'testdata', 'git_readme.diff')
        f = open(diff_filename, "r")
        rsp = self.apiPost(
            get_diff_list_url(review_request),
            {
                'path': f,
                'basedir': '/trunk',
                'base_commit_id': '1234',
            },
            expected_mimetype=diff_item_mimetype)
        f.close()

        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['diff']['basedir'], '/trunk')
        self.assertEqual(rsp['diff']['base_commit_id'], '1234')

        diffset = DiffSet.objects.get(pk=rsp['diff']['id'])
        self.assertEqual(diffset.basedir, '/trunk')
        self.assertEqual(diffset.base_commit_id, '1234')
Пример #8
0
    def test_post_adds_default_reviewers_first_time_only(self):
        """Testing the POST <URL> API doesn't add default reviewers a second
        time
        """
        review_request = self.create_review_request(submitter=self.user,
                                                    create_repository=True)

        # Create the initial diffset. This should prevent a default
        # reviewer from being applied, since we're not publishing the first
        # diff on a review request.
        self.create_diffset(review_request=review_request)

        # Create the state needed for the default reviewer.
        group = self.create_review_group(name='group1')

        default_reviewer = DefaultReviewer.objects.create(
            name='default1',
            file_regex='.')
        default_reviewer.groups.add(group)
        default_reviewer.repository.add(review_request.repository)

        # Post the diff.
        diff = SimpleUploadedFile('diff', self.DEFAULT_GIT_README_DIFF,
                                  content_type='text/x-patch')

        rsp = self.api_post(
            get_diff_list_url(review_request),
            {'path': diff},
            expected_mimetype=diff_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        draft = review_request.get_draft()
        self.assertEqual(list(draft.target_groups.all()), [])
Пример #9
0
    def test_put_second_dest_attachment_file_disallowed(self):
        """Testing the PUT review-requests/<id>/diffs/<id>/files/<id>/ API
        disallows setting dest_attachment_file twice
        """
        review_request = self.create_review_request(create_repository=True, submitter=self.user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__), "testdata", "git_binary_image_modified.diff")

        with open(diff_filename, "r") as f:
            rsp = self.apiPost(
                get_diff_list_url(review_request),
                {"path": f, "base_commit_id": "1234"},
                expected_mimetype=diff_item_mimetype,
            )

        diffset = DiffSet.objects.get(pk=rsp["diff"]["id"])
        filediff = diffset.files.all()[0]

        url = get_draft_filediff_item_url(filediff, review_request)
        trophy_filename = self._getTrophyFilename()

        with open(trophy_filename, "r") as f:
            self.apiPut(url, {"dest_attachment_file": f}, expected_mimetype=filediff_item_mimetype)

        with open(trophy_filename, "r") as f:
            rsp = self.apiPut(url, {"dest_attachment_file": f}, expected_status=400)

            self.assertEqual(rsp["stat"], "fail")
            self.assertEqual(rsp["err"]["code"], INVALID_FORM_DATA.code)
            self.assertTrue("fields" in rsp)
            self.assertTrue("dest_attachment_file" in rsp["fields"])
Пример #10
0
    def test_post_too_big(self):
        """Testing the POST review-requests/<id>/diffs/ API
        with diff exceeding max size
        """
        repository = self.create_repository()

        self.siteconfig.set('diffviewer_max_diff_size', 2)
        self.siteconfig.save()

        review_request = self.create_review_request(
            repository=repository,
            submitter=self.user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                     'testdata', 'git_readme.diff')
        with open(diff_filename, "r") as f:
            rsp = self.api_post(
                get_diff_list_url(review_request),
                {
                    'path': f,
                    'basedir': "/trunk",
                },
                expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], DIFF_TOO_BIG.code)
        self.assertIn('reason', rsp)
        self.assertIn('max_size', rsp)
        self.assertEqual(rsp['max_size'],
                         self.siteconfig.get('diffviewer_max_diff_size'))
Пример #11
0
    def test_post_adds_default_reviewers(self):
        """Testing the POST <URL> API adds default reviewers"""
        review_request = self.create_review_request(submitter=self.user,
                                                    create_repository=True)

        # Create the state needed for the default reviewer.
        group = self.create_review_group(name='group1')

        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.')
        default_reviewer.groups.add(group)
        default_reviewer.repository.add(review_request.repository)

        # Post the diff.
        diff = SimpleUploadedFile('diff',
                                  self.DEFAULT_GIT_README_DIFF,
                                  content_type='text/x-patch')

        rsp = self.api_post(get_diff_list_url(review_request), {'path': diff},
                            expected_mimetype=diff_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        draft = review_request.get_draft()
        self.assertEqual(list(draft.target_groups.all()), [group])
Пример #12
0
    def test_post_too_big(self):
        """Testing the POST review-requests/<id>/diffs/ API
        with diff exceeding max size
        """
        repository = self.create_repository()

        self.siteconfig.set('diffviewer_max_diff_size', 2)
        self.siteconfig.save()

        review_request = self.create_review_request(repository=repository,
                                                    submitter=self.user)

        diff = SimpleUploadedFile('diff',
                                  self.DEFAULT_GIT_README_DIFF,
                                  content_type='text/x-patch')

        rsp = self.api_post(get_diff_list_url(review_request), {
            'path': diff,
            'basedir': "/trunk",
        },
                            expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], DIFF_TOO_BIG.code)
        self.assertIn('reason', rsp)
        self.assertIn('max_size', rsp)
        self.assertEqual(rsp['max_size'],
                         self.siteconfig.get('diffviewer_max_diff_size'))
Пример #13
0
    def test_post_with_history(self):
        """Testing the POST <URL> API with a diff and a review request created
        with history support
        """
        review_request = self.create_review_request(submitter=self.user,
                                                    create_repository=True,
                                                    create_with_history=True)

        diff = SimpleUploadedFile('diff',
                                  self.DEFAULT_GIT_FILEDIFF_DATA_DIFF,
                                  content_type='text/x-patch')

        with override_feature_check(dvcs_feature.feature_id, enabled=True):
            rsp = self.api_post(
                get_diff_list_url(review_request),
                {
                    'path': diff,
                },
                expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
        self.assertEqual(
            rsp['reason'],
            'This review request was created with support for multiple '
            'commits.\n\n'
            'Create an empty diff revision and upload commits to that '
            'instead.')
Пример #14
0
    def test_post_too_big(self):
        """Testing the POST review-requests/<id>/diffs/ API
        with diff exceeding max size
        """
        repository = self.create_repository()

        self.siteconfig.set('diffviewer_max_diff_size', 2)
        self.siteconfig.save()

        review_request = self.create_review_request(repository=repository,
                                                    submitter=self.user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                     'testdata', 'git_readme.diff')
        with open(diff_filename, "r") as f:
            rsp = self.api_post(get_diff_list_url(review_request), {
                'path': f,
                'basedir': "/trunk",
            },
                                expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], DIFF_TOO_BIG.code)
        self.assertIn('reason', rsp)
        self.assertIn('max_size', rsp)
        self.assertEqual(rsp['max_size'],
                         self.siteconfig.get('diffviewer_max_diff_size'))
Пример #15
0
    def test_post_with_site(self):
        """Testing the POST review-requests/<id>/diffs/ API
        with a local site
        """
        user = self._login_user(local_site=True)

        repository = self.create_repository(with_local_site=True,
                                            tool_name='Test')

        review_request = self.create_review_request(
            with_local_site=True,
            repository=repository,
            submitter=user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                     'testdata', 'git_readme.diff')
        f = open(diff_filename, 'r')
        rsp = self.apiPost(
            get_diff_list_url(review_request, self.local_site_name),
            {
                'path': f,
                'basedir': '/trunk',
            },
            expected_mimetype=diff_item_mimetype)
        f.close()

        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['diff']['name'], 'git_readme.diff')
Пример #16
0
    def test_post_too_big(self):
        """Testing the POST review-requests/<id>/diffs/ API
        with diff exceeding max size
        """
        repository = self.create_repository()

        self.siteconfig.set('diffviewer_max_diff_size', 2)
        self.siteconfig.save()

        review_request = self.create_review_request(
            repository=repository,
            submitter=self.user)

        diff = SimpleUploadedFile('diff', self.DEFAULT_GIT_README_DIFF,
                                  content_type='text/x-patch')

        rsp = self.api_post(
            get_diff_list_url(review_request),
            {
                'path': diff,
                'basedir': "/trunk",
            },
            expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], DIFF_TOO_BIG.code)
        self.assertIn('reason', rsp)
        self.assertIn('max_size', rsp)
        self.assertEqual(rsp['max_size'],
                         self.siteconfig.get('diffviewer_max_diff_size'))
Пример #17
0
    def test_post_with_history(self):
        """Testing the POST <URL> API with a diff and a review request created
        with history support
        """
        review_request = self.create_review_request(submitter=self.user,
                                                    create_repository=True,
                                                    create_with_history=True)

        diff = SimpleUploadedFile('diff',
                                  self.DEFAULT_GIT_FILEDIFF_DATA_DIFF,
                                  content_type='text/x-patch')

        with override_feature_check(dvcs_feature.feature_id, enabled=True):
            rsp = self.api_post(get_diff_list_url(review_request), {
                'path': diff,
            },
                                expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
        self.assertEqual(
            rsp['reason'],
            'This review request was created with support for multiple '
            'commits.\n\n'
            'Create an empty diff revision and upload commits to that '
            'instead.')
Пример #18
0
    def test_post_adds_default_reviewers_first_time_only(self):
        """Testing the POST <URL> API doesn't add default reviewers a second
        time
        """
        review_request = self.create_review_request(submitter=self.user,
                                                    create_repository=True)

        # Create the initial diffset. This should prevent a default
        # reviewer from being applied, since we're not publishing the first
        # diff on a review request.
        self.create_diffset(review_request=review_request)

        # Create the state needed for the default reviewer.
        group = self.create_review_group(name='group1')

        default_reviewer = DefaultReviewer.objects.create(name='default1',
                                                          file_regex='.')
        default_reviewer.groups.add(group)
        default_reviewer.repository.add(review_request.repository)

        # Post the diff.
        diff = SimpleUploadedFile('diff',
                                  self.DEFAULT_GIT_README_DIFF,
                                  content_type='text/x-patch')

        rsp = self.api_post(get_diff_list_url(review_request), {'path': diff},
                            expected_mimetype=diff_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        draft = review_request.get_draft()
        self.assertEqual(list(draft.target_groups.all()), [])
Пример #19
0
    def test_get_diffs_with_site_no_access(self):
        """Testing the GET review-requests/<id>/diffs API with a local site and Permission Denied error"""
        review_request = self.create_review_request(create_repository=True,
                                                    with_local_site=True,
                                                    publish=True)
        self.create_diffset(review_request)

        self.apiGet(get_diff_list_url(review_request, self.local_site_name),
                    expected_status=403)
Пример #20
0
    def test_get_diffs_with_site_no_access(self):
        """Testing the GET review-requests/<id>/diffs API with a local site and Permission Denied error"""
        review_request = self.create_review_request(create_repository=True,
                                                    with_local_site=True,
                                                    publish=True)
        self.create_diffset(review_request)

        self.apiGet(get_diff_list_url(review_request, self.local_site_name),
                    expected_status=403)
Пример #21
0
    def setup_basic_get_test(self, user, with_local_site, local_site_name, populate_items):
        review_request = self.create_review_request(
            create_repository=True, with_local_site=with_local_site, submitter=user, publish=True
        )

        if populate_items:
            items = [self.create_diffset(review_request)]
        else:
            items = []

        return (get_diff_list_url(review_request, local_site_name), diff_list_mimetype, items)
Пример #22
0
    def test_get_diffs(self):
        """Testing the GET review-requests/<id>/diffs/ API"""
        review_request = self.create_review_request(create_repository=True,
                                                    publish=True)
        diffset = self.create_diffset(review_request)

        rsp = self.apiGet(get_diff_list_url(review_request),
                          expected_mimetype=diff_list_mimetype)

        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['diffs'][0]['id'], diffset.pk)
        self.assertEqual(rsp['diffs'][0]['name'], diffset.name)
Пример #23
0
    def test_get(self):
        """Testing the GET review-requests/<id>/diffs/ API"""
        review_request = self.create_review_request(create_repository=True,
                                                    publish=True)
        diffset = self.create_diffset(review_request)

        rsp = self.apiGet(get_diff_list_url(review_request),
                          expected_mimetype=diff_list_mimetype)

        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['diffs'][0]['id'], diffset.pk)
        self.assertEqual(rsp['diffs'][0]['name'], diffset.name)
Пример #24
0
    def test_post_not_owner(self):
        """Testing the POST review-requests/<id>/diffs/ API
        without owner
        """
        repository = self.create_repository(tool_name="Test")
        review_request = self.create_review_request(repository=repository)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__), "testdata", "git_readme.diff")
        with open(diff_filename, "r") as f:
            rsp = self.apiPost(get_diff_list_url(review_request), {"path": f, "basedir": "/trunk"}, expected_status=403)

        self.assertEqual(rsp["stat"], "fail")
        self.assertEqual(rsp["err"]["code"], PERMISSION_DENIED.code)
Пример #25
0
    def setup_basic_post_test(self, user, with_local_site, local_site_name, post_valid_data):
        repository = self.create_repository(tool_name="Test")
        review_request = self.create_review_request(
            with_local_site=with_local_site, repository=repository, submitter=user
        )

        if post_valid_data:
            diff_filename = os.path.join(os.path.dirname(scmtools.__file__), "testdata", "git_readme.diff")
            post_data = {"path": open(diff_filename, "r"), "basedir": "/trunk", "base_commit_id": "1234"}
        else:
            post_data = {}

        return (get_diff_list_url(review_request, local_site_name), diff_item_mimetype, post_data, [review_request])
Пример #26
0
    def test_put_with_modified_file_and_dest_attachment_file(self):
        """Testing the PUT review-requests/<id>/diffs/<id>/files/<id>/ API
        with modified file and dest_attachment_file
        """
        review_request = self.create_review_request(create_repository=True,
                                                    submitter=self.user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                     'testdata',
                                     'git_binary_image_modified.diff')

        with open(diff_filename, 'r') as f:
            rsp = self.api_post(
                get_diff_list_url(review_request),
                {
                    'path': f,
                    'base_commit_id': '1234',
                },
                expected_mimetype=diff_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        diffset = DiffSet.objects.get(pk=rsp['diff']['id'])
        filediffs = diffset.files.all()

        self.assertEqual(len(filediffs), 1)
        filediff = filediffs[0]
        self.assertEqual(filediff.source_file, 'trophy.png')

        with open(self._getTrophyFilename(), 'r') as f:
            rsp = self.api_put(
                get_draft_filediff_item_url(filediff, review_request) +
                '?expand=dest_attachment',
                {
                    'dest_attachment_file': f,
                },
                expected_mimetype=filediff_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')
        self.assertIn('dest_attachment', rsp['file'])

        attachment = FileAttachment.objects.get(
            pk=rsp['file']['dest_attachment']['id'])

        self.assertTrue(attachment.is_from_diff)
        self.assertEqual(attachment.orig_filename, 'trophy.png')
        self.assertEqual(attachment.added_in_filediff, None)
        self.assertEqual(attachment.repo_path, 'trophy.png')
        self.assertEqual(attachment.repo_revision, '86b520d')
        self.assertEqual(attachment.repository, review_request.repository)
Пример #27
0
    def test_put_with_modified_file_and_dest_attachment_file(self):
        """Testing the PUT review-requests/<id>/diffs/<id>/files/<id>/ API
        with modified file and dest_attachment_file
        """
        review_request = self.create_review_request(create_repository=True,
                                                    submitter=self.user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                     'testdata',
                                     'git_binary_image_modified.diff')

        with open(diff_filename, 'r') as f:
            rsp = self.apiPost(
                get_diff_list_url(review_request),
                {
                    'path': f,
                    'base_commit_id': '1234',
                },
                expected_mimetype=diff_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        diffset = DiffSet.objects.get(pk=rsp['diff']['id'])
        filediffs = diffset.files.all()

        self.assertEqual(len(filediffs), 1)
        filediff = filediffs[0]
        self.assertEqual(filediff.source_file, 'trophy.png')

        with open(self._getTrophyFilename(), 'r') as f:
            rsp = self.apiPut(
                get_draft_filediff_item_url(filediff, review_request) +
                '?expand=dest_attachment',
                {
                    'dest_attachment_file': f,
                },
                expected_mimetype=filediff_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')
        self.assertTrue('dest_attachment' in rsp['file'])

        attachment = FileAttachment.objects.get(
            pk=rsp['file']['dest_attachment']['id'])

        self.assertTrue(attachment.is_from_diff)
        self.assertEqual(attachment.orig_filename, 'trophy.png')
        self.assertEqual(attachment.added_in_filediff, None)
        self.assertEqual(attachment.repo_path, 'trophy.png')
        self.assertEqual(attachment.repo_revision, '86b520d')
        self.assertEqual(attachment.repository, review_request.repository)
Пример #28
0
    def test_get_diffs_with_site(self):
        """Testing the GET review-requests/<id>/diffs API with a local site"""
        review_request = self.create_review_request(create_repository=True,
                                                    with_local_site=True,
                                                    publish=True)
        diffset = self.create_diffset(review_request)

        self._login_user(local_site=True)

        rsp = self.apiGet(get_diff_list_url(review_request,
                                            self.local_site_name),
                          expected_mimetype=diff_list_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['diffs'][0]['id'], diffset.pk)
        self.assertEqual(rsp['diffs'][0]['name'], diffset.name)
Пример #29
0
    def setup_basic_get_test(self, user, with_local_site, local_site_name,
                             populate_items):
        review_request = self.create_review_request(
            create_repository=True,
            with_local_site=with_local_site,
            submitter=user,
            publish=True)

        if populate_items:
            items = [self.create_diffset(review_request)]
        else:
            items = []

        return (get_diff_list_url(review_request,
                                  local_site_name), diff_list_mimetype, items)
Пример #30
0
    def test_get_with_site(self):
        """Testing the GET review-requests/<id>/diffs API with a local site"""
        review_request = self.create_review_request(create_repository=True,
                                                    with_local_site=True,
                                                    publish=True)
        diffset = self.create_diffset(review_request)

        self._login_user(local_site=True)

        rsp = self.apiGet(get_diff_list_url(review_request,
                                            self.local_site_name),
                          expected_mimetype=diff_list_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['diffs'][0]['id'], diffset.pk)
        self.assertEqual(rsp['diffs'][0]['name'], diffset.name)
Пример #31
0
    def test_put_with_modified_file_and_dest_attachment_file(self):
        """Testing the PUT review-requests/<id>/diffs/<id>/files/<id>/ API
        with modified file and dest_attachment_file
        """
        review_request = self.create_review_request(create_repository=True,
                                                    submitter=self.user)

        diff = SimpleUploadedFile('git_binary_image_modified.diff',
                                  self.DEFAULT_GIT_BINARY_IMAGE_DIFF,
                                  content_type='text/x-patch')
        rsp = self.api_post(
            get_diff_list_url(review_request),
            {
                'path': diff,
                'base_commit_id': '1234',
            },
            expected_mimetype=diff_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        diffset = DiffSet.objects.get(pk=rsp['diff']['id'])
        filediffs = diffset.files.all()

        self.assertEqual(len(filediffs), 1)
        filediff = filediffs[0]
        self.assertEqual(filediff.source_file, 'logo.png')

        with open(self.get_sample_image_filename(), 'r') as f:
            rsp = self.api_put(
                get_draft_filediff_item_url(filediff, review_request) +
                '?expand=dest_attachment',
                {
                    'dest_attachment_file': f,
                },
                expected_mimetype=filediff_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')
        self.assertIn('dest_attachment', rsp['file'])

        attachment = FileAttachment.objects.get(
            pk=rsp['file']['dest_attachment']['id'])

        self.assertTrue(attachment.is_from_diff)
        self.assertEqual(attachment.orig_filename, 'logo.png')
        self.assertEqual(attachment.added_in_filediff, None)
        self.assertEqual(attachment.repo_path, 'logo.png')
        self.assertEqual(attachment.repo_revision, '86b520d')
        self.assertEqual(attachment.repository, review_request.repository)
Пример #32
0
    def test_post_empty_dvcs_disabled(self):
        """Testing the POST <URL> API without a diff with the DVCS feature
        disabled
        """
        review_request = self.create_review_request(submitter=self.user,
                                                    create_repository=True,
                                                    create_with_history=False)

        with override_feature_check(dvcs_feature.feature_id, enabled=False):
            rsp = self.api_post(get_diff_list_url(review_request), {},
                                expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
        self.assertEqual(rsp['fields'], {
            'path': ['This field is required.'],
        })
Пример #33
0
    def test_put_second_dest_attachment_file_disallowed(self):
        """Testing the PUT review-requests/<id>/diffs/<id>/files/<id>/ API
        disallows setting dest_attachment_file twice
        """
        review_request = self.create_review_request(create_repository=True,
                                                    submitter=self.user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                     'testdata',
                                     'git_binary_image_modified.diff')

        with open(diff_filename, 'r') as f:
            rsp = self.api_post(
                get_diff_list_url(review_request),
                {
                    'path': f,
                    'base_commit_id': '1234',
                },
                expected_mimetype=diff_item_mimetype)

        diffset = DiffSet.objects.get(pk=rsp['diff']['id'])
        filediff = diffset.files.all()[0]

        url = get_draft_filediff_item_url(filediff, review_request)
        trophy_filename = self._getTrophyFilename()

        with open(trophy_filename, 'r') as f:
            self.api_put(
                url,
                {
                    'dest_attachment_file': f,
                },
                expected_mimetype=filediff_item_mimetype)

        with open(trophy_filename, 'r') as f:
            rsp = self.api_put(
                url,
                {
                    'dest_attachment_file': f,
                },
                expected_status=400)

            self.assertEqual(rsp['stat'], 'fail')
            self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
            self.assertIn('fields', rsp)
            self.assertIn('dest_attachment_file', rsp['fields'])
Пример #34
0
    def test_put_second_dest_attachment_file_disallowed(self):
        """Testing the PUT review-requests/<id>/diffs/<id>/files/<id>/ API
        disallows setting dest_attachment_file twice
        """
        review_request = self.create_review_request(create_repository=True,
                                                    submitter=self.user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                     'testdata',
                                     'git_binary_image_modified.diff')

        with open(diff_filename, 'r') as f:
            rsp = self.apiPost(
                get_diff_list_url(review_request),
                {
                    'path': f,
                    'base_commit_id': '1234',
                },
                expected_mimetype=diff_item_mimetype)

        diffset = DiffSet.objects.get(pk=rsp['diff']['id'])
        filediff = diffset.files.all()[0]

        url = get_draft_filediff_item_url(filediff, review_request)
        trophy_filename = self._getTrophyFilename()

        with open(trophy_filename, 'r') as f:
            self.apiPut(
                url,
                {
                    'dest_attachment_file': f,
                },
                expected_mimetype=filediff_item_mimetype)

        with open(trophy_filename, 'r') as f:
            rsp = self.apiPut(
                url,
                {
                    'dest_attachment_file': f,
                },
                expected_status=400)

            self.assertEqual(rsp['stat'], 'fail')
            self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
            self.assertTrue('fields' in rsp)
            self.assertTrue('dest_attachment_file' in rsp['fields'])
Пример #35
0
    def test_post_no_repository(self):
        """Testing the POST review-requests/<id>/diffs API
        with a ReviewRequest that has no repository
        """
        review_request = self.create_review_request(submitter=self.user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                     'testdata', 'git_readme.diff')
        with open(diff_filename, 'r') as f:
            rsp = self.api_post(get_diff_list_url(review_request), {
                'path': f,
                'basedir': '/trunk',
            },
                                expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_ATTRIBUTE.code)
Пример #36
0
    def test_post_empty_dvcs_disabled(self):
        """Testing the POST <URL> API without a diff with the DVCS feature
        disabled
        """
        review_request = self.create_review_request(submitter=self.user,
                                                    create_repository=True,
                                                    create_with_history=False)

        with override_feature_check(dvcs_feature.feature_id, enabled=False):
            rsp = self.api_post(get_diff_list_url(review_request), {},
                                expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
        self.assertEqual(rsp['fields'], {
            'path': ['This field is required.'],
        })
Пример #37
0
    def test_put_with_modified_file_and_dest_attachment_file(self):
        """Testing the PUT review-requests/<id>/diffs/<id>/files/<id>/ API
        with modified file and dest_attachment_file
        """
        review_request = self.create_review_request(create_repository=True,
                                                    submitter=self.user)

        diff = SimpleUploadedFile('git_binary_image_modified.diff',
                                  self.DEFAULT_GIT_BINARY_IMAGE_DIFF,
                                  content_type='text/x-patch')
        rsp = self.api_post(get_diff_list_url(review_request), {
            'path': diff,
            'base_commit_id': '1234',
        },
                            expected_mimetype=diff_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')

        diffset = DiffSet.objects.get(pk=rsp['diff']['id'])
        filediffs = diffset.files.all()

        self.assertEqual(len(filediffs), 1)
        filediff = filediffs[0]
        self.assertEqual(filediff.source_file, 'logo.png')

        with open(self.get_sample_image_filename(), 'rb') as f:
            rsp = self.api_put(
                get_draft_filediff_item_url(filediff, review_request) +
                '?expand=dest_attachment', {
                    'dest_attachment_file': f,
                },
                expected_mimetype=filediff_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')
        self.assertIn('dest_attachment', rsp['file'])

        attachment = FileAttachment.objects.get(
            pk=rsp['file']['dest_attachment']['id'])

        self.assertTrue(attachment.is_from_diff)
        self.assertEqual(attachment.orig_filename, 'logo.png')
        self.assertEqual(attachment.added_in_filediff, None)
        self.assertEqual(attachment.repo_path, 'logo.png')
        self.assertEqual(attachment.repo_revision, '86b520d')
        self.assertEqual(attachment.repository, review_request.repository)
Пример #38
0
    def test_put_second_dest_attachment_file_disallowed(self):
        """Testing the PUT review-requests/<id>/diffs/<id>/files/<id>/ API
        disallows setting dest_attachment_file twice
        """
        review_request = self.create_review_request(create_repository=True,
                                                    submitter=self.user)

        diff = SimpleUploadedFile('git_binary_image_modified.diff',
                                  self.DEFAULT_GIT_BINARY_IMAGE_DIFF,
                                  content_type='text/x-patch')

        rsp = self.api_post(
            get_diff_list_url(review_request),
            {
                'path': diff,
                'base_commit_id': '1234',
            },
            expected_mimetype=diff_item_mimetype)

        diffset = DiffSet.objects.get(pk=rsp['diff']['id'])
        filediff = diffset.files.all()[0]

        url = get_draft_filediff_item_url(filediff, review_request)
        trophy_filename = self.get_sample_image_filename()

        with open(trophy_filename, 'r') as f:
            self.api_put(
                url,
                {
                    'dest_attachment_file': f,
                },
                expected_mimetype=filediff_item_mimetype)

        with open(trophy_filename, 'r') as f:
            rsp = self.api_put(
                url,
                {
                    'dest_attachment_file': f,
                },
                expected_status=400)

            self.assertEqual(rsp['stat'], 'fail')
            self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
            self.assertIn('fields', rsp)
            self.assertIn('dest_attachment_file', rsp['fields'])
Пример #39
0
    def test_post_no_repository(self):
        """Testing the POST review-requests/<id>/diffs API
        with a ReviewRequest that has no repository
        """
        review_request = self.create_review_request(submitter=self.user)

        diff = SimpleUploadedFile('diff',
                                  self.DEFAULT_GIT_README_DIFF,
                                  content_type='text/x-patch')

        rsp = self.api_post(get_diff_list_url(review_request), {
            'path': diff,
            'basedir': '/trunk',
        },
                            expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_ATTRIBUTE.code)
Пример #40
0
    def test_post_not_owner(self):
        """Testing the POST review-requests/<id>/diffs/ API
        without owner
        """
        repository = self.create_repository(tool_name='Test')
        review_request = self.create_review_request(repository=repository)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                     'testdata', 'git_readme.diff')
        with open(diff_filename, 'r') as f:
            rsp = self.api_post(get_diff_list_url(review_request), {
                'path': f,
                'basedir': '/trunk',
            },
                                expected_status=403)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
Пример #41
0
    def test_post_not_owner(self):
        """Testing the POST review-requests/<id>/diffs/ API
        without owner
        """
        repository = self.create_repository(tool_name='Test')
        review_request = self.create_review_request(repository=repository)

        diff = SimpleUploadedFile('diff',
                                  self.DEFAULT_GIT_README_DIFF,
                                  content_type='text/x-patch')

        rsp = self.api_post(get_diff_list_url(review_request), {
            'path': diff,
            'basedir': '/trunk',
        },
                            expected_status=403)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
Пример #42
0
    def test_post_no_repository(self):
        """Testing the POST review-requests/<id>/diffs API
        with a ReviewRequest that has no repository
        """
        review_request = self.create_review_request(submitter=self.user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                     'testdata', 'git_readme.diff')
        with open(diff_filename, 'r') as f:
            rsp = self.api_post(
                get_diff_list_url(review_request),
                {
                    'path': f,
                    'basedir': '/trunk',
                },
                expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_ATTRIBUTE.code)
Пример #43
0
    def test_post_empty_with_history(self):
        """Testing the POST <URL> API creates an empty DiffSet for a review
        request created with history support with the DVCS feature enabled
        """
        review_request = self.create_review_request(submitter=self.user,
                                                    create_repository=True,
                                                    create_with_history=True)

        with override_feature_check(dvcs_feature.feature_id, enabled=True):
            rsp = self.api_post(get_diff_list_url(review_request), {},
                                expected_mimetype=diff_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')
        item_rsp = rsp['diff']

        diff = DiffSet.objects.get(pk=item_rsp['id'])
        self.compare_item(item_rsp, diff)
        self.assertEqual(diff.files.count(), 0)
        self.assertEqual(diff.revision, 1)
Пример #44
0
    def test_post_empty_with_history(self):
        """Testing the POST <URL> API creates an empty DiffSet for a review
        request created with history support with the DVCS feature enabled
        """
        review_request = self.create_review_request(submitter=self.user,
                                                    create_repository=True,
                                                    create_with_history=True)

        with override_feature_check(dvcs_feature.feature_id, enabled=True):
            rsp = self.api_post(get_diff_list_url(review_request), {},
                                expected_mimetype=diff_item_mimetype)

        self.assertEqual(rsp['stat'], 'ok')
        item_rsp = rsp['diff']

        diff = DiffSet.objects.get(pk=item_rsp['id'])
        self.compare_item(item_rsp, diff)
        self.assertEqual(diff.files.count(), 0)
        self.assertEqual(diff.revision, 1)
Пример #45
0
    def test_post_no_repository(self):
        """Testing the POST review-requests/<id>/diffs API
        with a ReviewRequest that has no repository
        """
        review_request = self.create_review_request(submitter=self.user)

        diff = SimpleUploadedFile('diff', self.DEFAULT_GIT_README_DIFF,
                                  content_type='text/x-patch')

        rsp = self.api_post(
            get_diff_list_url(review_request),
            {
                'path': diff,
                'basedir': '/trunk',
            },
            expected_status=400)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], INVALID_ATTRIBUTE.code)
Пример #46
0
    def test_put_with_modified_file_and_dest_attachment_file(self):
        """Testing the PUT review-requests/<id>/diffs/<id>/files/<id>/ API
        with modified file and dest_attachment_file
        """
        review_request = self.create_review_request(create_repository=True, submitter=self.user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__), "testdata", "git_binary_image_modified.diff")

        with open(diff_filename, "r") as f:
            rsp = self.apiPost(
                get_diff_list_url(review_request),
                {"path": f, "base_commit_id": "1234"},
                expected_mimetype=diff_item_mimetype,
            )

        self.assertEqual(rsp["stat"], "ok")

        diffset = DiffSet.objects.get(pk=rsp["diff"]["id"])
        filediffs = diffset.files.all()

        self.assertEqual(len(filediffs), 1)
        filediff = filediffs[0]
        self.assertEqual(filediff.source_file, "trophy.png")

        with open(self._getTrophyFilename(), "r") as f:
            rsp = self.apiPut(
                get_draft_filediff_item_url(filediff, review_request) + "?expand=dest_attachment",
                {"dest_attachment_file": f},
                expected_mimetype=filediff_item_mimetype,
            )

        self.assertEqual(rsp["stat"], "ok")
        self.assertTrue("dest_attachment" in rsp["file"])

        attachment = FileAttachment.objects.get(pk=rsp["file"]["dest_attachment"]["id"])

        self.assertTrue(attachment.is_from_diff)
        self.assertEqual(attachment.orig_filename, "trophy.png")
        self.assertEqual(attachment.added_in_filediff, None)
        self.assertEqual(attachment.repo_path, "trophy.png")
        self.assertEqual(attachment.repo_revision, "86b520d")
        self.assertEqual(attachment.repository, review_request.repository)
Пример #47
0
    def test_post_not_owner(self):
        """Testing the POST review-requests/<id>/diffs/ API
        without owner
        """
        repository = self.create_repository(tool_name='Test')
        review_request = self.create_review_request(repository=repository)

        diff = SimpleUploadedFile('diff', self.DEFAULT_GIT_README_DIFF,
                                  content_type='text/x-patch')

        rsp = self.api_post(
            get_diff_list_url(review_request),
            {
                'path': diff,
                'basedir': '/trunk',
            },
            expected_status=403)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
Пример #48
0
    def test_post_not_owner(self):
        """Testing the POST review-requests/<id>/diffs/ API
        without owner
        """
        repository = self.create_repository(tool_name='Test')
        review_request = self.create_review_request(repository=repository)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                     'testdata', 'git_readme.diff')
        with open(diff_filename, 'r') as f:
            rsp = self.api_post(
                get_diff_list_url(review_request),
                {
                    'path': f,
                    'basedir': '/trunk',
                },
                expected_status=403)

        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
Пример #49
0
    def setup_basic_post_test(self, user, with_local_site, local_site_name,
                              post_valid_data):
        repository = self.create_repository(tool_name='Test')
        review_request = self.create_review_request(
            with_local_site=with_local_site,
            repository=repository,
            submitter=user)

        if post_valid_data:
            diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                         'testdata', 'git_readme.diff')
            post_data = {
                'path': open(diff_filename, 'r'),
                'basedir': '/trunk',
                'base_commit_id': '1234',
            }
        else:
            post_data = {}

        return (get_diff_list_url(review_request, local_site_name),
                diff_item_mimetype, post_data, [review_request])
Пример #50
0
    def test_post_too_big(self):
        """Testing the POST review-requests/<id>/diffs/ API
        with diff exceeding max size
        """
        repository = self.create_repository()

        self.siteconfig.set("diffviewer_max_diff_size", 2)
        self.siteconfig.save()

        review_request = self.create_review_request(repository=repository, submitter=self.user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__), "testdata", "git_readme.diff")
        f = open(diff_filename, "r")

        rsp = self.apiPost(get_diff_list_url(review_request), {"path": f, "basedir": "/trunk"}, expected_status=400)

        self.assertEqual(rsp["stat"], "fail")
        self.assertEqual(rsp["err"]["code"], DIFF_TOO_BIG.code)
        self.assertTrue("reason" in rsp)
        self.assertTrue("max_size" in rsp)
        self.assertEqual(rsp["max_size"], self.siteconfig.get("diffviewer_max_diff_size"))
Пример #51
0
    def test_put_second_dest_attachment_file_disallowed(self):
        """Testing the PUT review-requests/<id>/diffs/<id>/files/<id>/ API
        disallows setting dest_attachment_file twice
        """
        review_request = self.create_review_request(create_repository=True,
                                                    submitter=self.user)

        diff = SimpleUploadedFile('git_binary_image_modified.diff',
                                  self.DEFAULT_GIT_BINARY_IMAGE_DIFF,
                                  content_type='text/x-patch')

        rsp = self.api_post(get_diff_list_url(review_request), {
            'path': diff,
            'base_commit_id': '1234',
        },
                            expected_mimetype=diff_item_mimetype)

        diffset = DiffSet.objects.get(pk=rsp['diff']['id'])
        filediff = diffset.files.all()[0]

        url = get_draft_filediff_item_url(filediff, review_request)
        trophy_filename = self.get_sample_image_filename()

        with open(trophy_filename, 'rb') as f:
            self.api_put(url, {
                'dest_attachment_file': f,
            },
                         expected_mimetype=filediff_item_mimetype)

        with open(trophy_filename, 'rb') as f:
            rsp = self.api_put(url, {
                'dest_attachment_file': f,
            },
                               expected_status=400)

            self.assertEqual(rsp['stat'], 'fail')
            self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code)
            self.assertIn('fields', rsp)
            self.assertIn('dest_attachment_file', rsp['fields'])
Пример #52
0
    def setup_basic_post_test(self, user, with_local_site, local_site_name,
                              post_valid_data):
        repository = self.create_repository(tool_name='Test')
        review_request = self.create_review_request(
            with_local_site=with_local_site,
            repository=repository,
            submitter=user)

        diff = SimpleUploadedFile('diff',
                                  self.DEFAULT_GIT_README_DIFF,
                                  content_type='text/x-patch')

        if post_valid_data:
            post_data = {
                'path': diff,
                'basedir': '/trunk',
                'base_commit_id': '1234',
            }
        else:
            post_data = {}

        return (get_diff_list_url(review_request, local_site_name),
                diff_item_mimetype, post_data, [review_request])
Пример #53
0
    def setup_basic_post_test(self, user, with_local_site, local_site_name,
                              post_valid_data):
        repository = self.create_repository(tool_name='Test')
        review_request = self.create_review_request(
            with_local_site=with_local_site,
            repository=repository,
            submitter=user)

        if post_valid_data:
            diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                         'testdata', 'git_readme.diff')
            post_data = {
                'path': open(diff_filename, 'r'),
                'basedir': '/trunk',
                'base_commit_id': '1234',
            }
        else:
            post_data = {}

        return (get_diff_list_url(review_request, local_site_name),
                diff_item_mimetype,
                post_data,
                [review_request])
Пример #54
0
    def test_post_diffs_with_site(self):
        """Testing the POST review-requests/<id>/diffs/ API with a local site"""
        user = self._login_user(local_site=True)

        repository = self.create_repository(with_local_site=True,
                                            tool_name='Subversion')

        review_request = self.create_review_request(with_local_site=True,
                                                    repository=repository,
                                                    submitter=user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                     'testdata', 'svn_makefile.diff')
        f = open(diff_filename, 'r')
        rsp = self.apiPost(get_diff_list_url(review_request,
                                             self.local_site_name), {
                                                 'path': f,
                                                 'basedir': '/trunk',
                                             },
                           expected_mimetype=diff_item_mimetype)
        f.close()

        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['diff']['name'], 'svn_makefile.diff')
Пример #55
0
    def test_post_diffs(self):
        """Testing the POST review-requests/<id>/diffs/ API"""
        repository = self.create_repository(tool_name='Subversion')
        review_request = self.create_review_request(repository=repository,
                                                    submitter=self.user)

        diff_filename = os.path.join(os.path.dirname(scmtools.__file__),
                                     'testdata', 'svn_makefile.diff')
        f = open(diff_filename, "r")
        rsp = self.apiPost(get_diff_list_url(review_request), {
            'path': f,
            'basedir': '/trunk',
            'base_commit_id': '1234',
        },
                           expected_mimetype=diff_item_mimetype)
        f.close()

        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(rsp['diff']['basedir'], '/trunk')
        self.assertEqual(rsp['diff']['base_commit_id'], '1234')

        diffset = DiffSet.objects.get(pk=rsp['diff']['id'])
        self.assertEqual(diffset.basedir, '/trunk')
        self.assertEqual(diffset.base_commit_id, '1234')
Пример #56
0
 def setup_review_request_child_test(self, review_request):
     return get_diff_list_url(review_request), diff_list_mimetype