def test_single_item_details(self):
        ref_name = 'ref1'
        ref_id = 'deadbeef'
        refs = {
            ref_name: ref_id
        }

        controller = summary.SummaryController()
        url_patcher = mock.patch.object(
            controller, '_create_files_url', return_value=self.fake_url)
        svn_patcher = mock.patch.object(
            summary.h, 'is_svn', return_value=False)

        with url_patcher as url_mock, svn_patcher:
            result = controller._create_reference_items(
                self.repo, refs, self.ref_type, self._format_function)

        url_mock.assert_called_once_with(self.repo, ref_name, ref_id, False)
        expected_result = [
            {
                'text': ref_name,
                'id': self._format_function(ref_name, ref_id),
                'raw_id': ref_id,
                'type': self.ref_type,
                'files_url': self.fake_url
            }
        ]
        assert result == expected_result
    def test_generates_refs_with_path_for_svn(self, example_refs):
        repo = mock.Mock()
        repo.name = 'test-repo'
        repo.alias = 'svn'
        controller = summary.SummaryController()
        result = controller._create_reference_data(repo, example_refs)

        expected_result = [
            {
                'children': [
                    {
                        'id': 'a@a_id', 'raw_id': 'a_id',
                        'text': 'a', 'type': 't1',
                        'files_url': '/test-repo/files/a_id/a?at=a'
                    },
                    {
                        'id': 'b@b_id', 'raw_id': 'b_id',
                        'text': 'b', 'type': 't1',
                        'files_url': '/test-repo/files/b_id/b?at=b'
                    }
                ],
                'text': 'section_1'
            },
            {
                'children': [
                    {
                        'id': 'c@c_id', 'raw_id': 'c_id',
                        'text': 'c', 'type': 't2',
                        'files_url': '/test-repo/files/c_id/c?at=c'
                    }
                ],
                'text': 'section_2'
            }
        ]
        assert result == expected_result
    def test_generates_refs_based_on_commit_ids(self, example_refs):
        repo = mock.Mock()
        repo.name = 'test-repo'
        repo.alias = 'git'
        controller = summary.SummaryController()

        result = controller._create_reference_data(repo, example_refs)

        expected_result = [
            {
                'children': [
                    {
                        'id': 'a', 'raw_id': 'a_id', 'text': 'a', 'type': 't1',
                        'files_url': '/test-repo/files/a/?at=a'
                    },
                    {
                        'id': 'b', 'raw_id': 'b_id', 'text': 'b', 'type': 't1',
                        'files_url': '/test-repo/files/b/?at=b'
                    }
                ],
                'text': 'section_1'
            },
            {
                'children': [
                    {
                        'id': 'c', 'raw_id': 'c_id', 'text': 'c', 'type': 't2',
                        'files_url': '/test-repo/files/c/?at=c'
                    }
                ],
                'text': 'section_2'
            }]
        assert result == expected_result
 def test_adds_reference_to_path_for_svn(self):
     references = {
         'name/with/slash': 'commit_id',
     }
     controller = summary.SummaryController()
     is_svn = True
     result = controller._switcher_reference_data(
         'repo_name', references, is_svn)
     expected_url = h.url(
         'files_home', repo_name='repo_name', f_path='name/with/slash',
         revision='commit_id', at='name/with/slash')
     assert result[0]['files_url'] == expected_url
 def test_urls_contain_commit_id_if_slash_in_name(self):
     references = {
         'name/with/slash': 'commit_id',
     }
     controller = summary.SummaryController()
     is_svn = False
     result = controller._switcher_reference_data(
         'repo_name', references, is_svn)
     expected_url = h.url(
         'files_home', repo_name='repo_name', revision='commit_id',
         at='name/with/slash')
     assert result[0]['files_url'] == expected_url
 def test_creates_reference_urls_based_on_name(self):
     references = {
         'name': 'commit_id',
     }
     controller = summary.SummaryController()
     is_svn = False
     result = controller._switcher_reference_data(
         'repo_name', references, is_svn)
     expected_url = h.url(
         'files_home', repo_name='repo_name', revision='name',
         at='name')
     assert result[0]['files_url'] == expected_url
    def test_name_has_slashes(self):
        controller = summary.SummaryController()
        repo = mock.Mock()
        repo.name = 'abcde'
        ref_name = 'branch1/branch2'
        raw_id = 'deadbeef0123456789'
        is_svn = False

        with mock.patch.object(summary.h, 'url') as url_mock:
            result = controller._create_files_url(
                repo, ref_name, raw_id, is_svn)
        url_mock.assert_called_once_with(
            'files_home', repo_name=repo.name, f_path='', revision=raw_id,
            at=ref_name)
        assert result == url_mock.return_value
    def test_creates_required_amount_of_items(self):
        amount = 100
        refs = {
            'ref{}'.format(i): '{0:040d}'.format(i)
            for i in range(amount)
        }

        controller = summary.SummaryController()

        url_patcher = mock.patch.object(
            controller, '_create_files_url')
        svn_patcher = mock.patch.object(
            summary.h, 'is_svn', return_value=False)

        with url_patcher as url_mock, svn_patcher:
            result = controller._create_reference_items(
                self.repo, refs, self.ref_type, self._format_function)
        assert len(result) == amount
        assert url_mock.call_count == amount