Пример #1
0
def test_enrich_release_release_target(api_request_factory, archive_data,
                                       release):

    release_data = archive_data.release_get(release)
    release_data["target_type"] = "release"

    url = reverse("api-1-release", url_args={"sha1_git": release})
    request = api_request_factory.get(url)

    actual_release = utils.enrich_release(release_data, request)

    release_data["target_url"] = reverse(
        "api-1-release",
        url_args={"sha1_git": release_data["target"]},
        request=request)

    assert actual_release == release_data
Пример #2
0
    def test_enrich_release_1(self, mock_django_reverse):
        # given

        def reverse_test_context(view_name, url_args):
            if view_name == 'api-content':
                id = url_args['q']
                return '/api/1/content/%s/' % id
            elif view_name == 'api-person':
                id = url_args['person_id']
                return '/api/1/person/%s/' % id
            else:
                raise ValueError(
                    'This should not happened so fail if it does.')

        mock_django_reverse.side_effect = reverse_test_context

        # when
        actual_release = utils.enrich_release({
            'target': '123',
            'target_type': 'content',
            'author': {
                'id': 100,
                'name': 'author release name',
                'email': 'author@email',
            },
        })

        # then
        self.assertEqual(
            actual_release, {
                'target': '123',
                'target_type': 'content',
                'target_url': '/api/1/content/sha1_git:123/',
                'author_url': '/api/1/person/100/',
                'author': {
                    'id': 100,
                    'name': 'author release name',
                    'email': 'author@email',
                },
            })

        mock_django_reverse.assert_has_calls([
            call('api-content', url_args={'q': 'sha1_git:123'}),
            call('api-person', url_args={'person_id': 100})
        ])
Пример #3
0
    def test_enrich_release_4(self, mock_django_reverse):
        # given
        mock_django_reverse.return_value = '/api/1/rev/4/'

        # when
        actual_release = utils.enrich_release({
            'target': '4',
            'target_type': 'release'
        })

        # then
        self.assertEqual(actual_release, {
            'target': '4',
            'target_type': 'release',
            'target_url': '/api/1/rev/4/'
        })

        mock_django_reverse.assert_called_once_with('api-release',
                                                    url_args={'sha1_git': '4'})
Пример #4
0
    def test_enrich_release_2(self, mock_django_reverse):
        # given
        mock_django_reverse.return_value = '/api/1/dir/23/'

        # when
        actual_release = utils.enrich_release({
            'target': '23',
            'target_type': 'directory'
        })

        # then
        self.assertEqual(
            actual_release, {
                'target': '23',
                'target_type': 'directory',
                'target_url': '/api/1/dir/23/'
            })

        mock_django_reverse.assert_called_once_with(
            'api-directory', url_args={'sha1_git': '23'})  # noqa
Пример #5
0
def test_enrich_release_empty():
    actual_release = utils.enrich_release({})

    assert actual_release == {}
Пример #6
0
    def test_enrich_release_0(self):
        # when
        actual_release = utils.enrich_release({})

        # then
        self.assertEqual(actual_release, {})