def test_consumer_only(self, mock_get_bound, mock_find):
        mock_get_bound.return_value = ['repo1', 'repo2']

        releases.view('consumer1', constants.FORGE_NULL_AUTH_VALUE, 'foo/bar')

        mock_get_bound.assert_called_once_with('consumer1')
        mock_find.assert_called_once_with(['repo1', 'repo2'], 'foo/bar')
Ejemplo n.º 2
0
    def test_consumer_only(self, mock_get_bound, mock_find):
        mock_get_bound.return_value = ['repo1', 'repo2']

        releases.view('consumer1', constants.FORGE_NULL_AUTH_VALUE, 'foo/bar')

        mock_get_bound.assert_called_once_with('consumer1')
        mock_find.assert_called_once_with(['repo1', 'repo2'], 'foo/bar')
Ejemplo n.º 3
0
    def test_repo_ids_from_query_string(self, mock_get_data, mock_unit_generator, mock_host):
        mock_get_data.return_value = {
            'repo1': {'db': mock.MagicMock(), 'protocol': 'http'},
        }
        mock_unit_generator.return_value = [unit_generator()]

        releases.view(constants.FORGE_NULL_AUTH_VALUE, 'repo_foo', 'me/mymodule')

        mock_get_data.assert_called_once_with(['repo_foo'])
Ejemplo n.º 4
0
    def test_db_closing(self, mock_get_data, mock_unit_generator, mock_host):
        mock_get_data.return_value = {
            'repo1': {'db': mock.MagicMock(), 'protocol': 'http'},
            'repo2': {'db': mock.MagicMock(), 'protocol': 'http'},
        }
        mock_unit_generator.return_value = [unit_generator()]

        releases.view(constants.FORGE_NULL_AUTH_VALUE, 'repo_foo', 'me/mymodule')
        mock_get_data.return_value['repo1']['db'].close.assert_called_once_with()
        mock_get_data.return_value['repo2']['db'].close.assert_called_once_with()
Ejemplo n.º 5
0
    def test_calculating_deps_default(self, mock_get_data, mock_unit_generator, mock_host):
        mock_get_data.return_value = {
            'repo1': {'db': mock.MagicMock(), 'protocol': 'http'},
        }
        u1 = unit_generator(version='1.0.0')
        mock_unit_generator.return_value = [u1]
        u1_built_data = u1.build_dep_metadata(True)
        u1.build_dep_metadata = mock.Mock(return_value=u1_built_data)

        releases.view(constants.FORGE_NULL_AUTH_VALUE, 'repo_foo', 'me/mymodule')
        u1.build_dep_metadata.assert_called_once_with(True)
Ejemplo n.º 6
0
    def test_repo_ids_from_consumer(self, mock_get_bounds, mock_get_data,
                                    mock_unit_generator, mock_host):
        mock_get_bounds.return_value = ['apple', 'pear']
        mock_get_data.return_value = {
            'repo1': {'db': mock.MagicMock(), 'protocol': 'http'}
        }
        mock_unit_generator.return_value = [unit_generator()]

        releases.view('consumer1', constants.FORGE_NULL_AUTH_VALUE, 'me/mymodule')

        mock_get_bounds.assert_called_once_with('consumer1')
        mock_get_data.assert_called_once_with(['apple', 'pear'])
Ejemplo n.º 7
0
    def GET(self):
        """
        Credentials here are not actually used for authorization, but instead
        are used to identify:

            consumer ID in the username field
            repository ID in the password field

        This is to work around the fact that the "puppet module install"
        command has hard-coded absolute paths, so we cannot put consumer or
        repository IDs in the URL's path.
        """
        credentials = self._get_credentials()
        if not credentials:
            return web.unauthorized()

        module_name = self._get_module_name()
        if not module_name:
            # apparently our version of web.py, 0.36, doesn't take a message
            # parameter for error handlers like this one. Ugh.
            return web.badrequest()
        version =  web.input().get('version')

        web.header('Content-Type', 'application/json')
        data = releases.view(*credentials, module_name=module_name, version=version)
        return json.dumps(data)
Ejemplo n.º 8
0
    def GET(self):
        """
        Credentials here are not actually used for authorization, but instead
        are used to identify:

            consumer ID in the username field
            repository ID in the password field

        This is to work around the fact that the "puppet module install"
        command has hard-coded absolute paths, so we cannot put consumer or
        repository IDs in the URL's path.
        """
        credentials = self._get_credentials()
        if not credentials:
            return web.unauthorized()

        module_name = self._get_module_name()
        if not module_name:
            # apparently our version of web.py, 0.36, doesn't take a message
            # parameter for error handlers like this one. Ugh.
            return web.badrequest()
        version = web.input().get('version')

        web.header('Content-Type', 'application/json')
        data = releases.view(*credentials,
                             module_name=module_name,
                             version=version)
        return json.dumps(data)
Ejemplo n.º 9
0
    def get_releases(self, *args, **kwargs):
        """
        Get the list of matching releases

        :return: The matching modules
        :rtype: dict
        """
        return releases.view(*args, recurse_deps=False, view_all_matching=True, **kwargs)
Ejemplo n.º 10
0
    def get_releases(self, *args, **kwargs):
        """
        Get the list of matching releases

        :return: The matching modules
        :rtype: dict
        """
        return releases.view(*args, **kwargs)
Ejemplo n.º 11
0
    def get_releases(self, *args, **kwargs):
        """
        Get the list of matching releases

        :return: The matching modules
        :rtype: dict
        """
        return releases.view(*args, **kwargs)
Ejemplo n.º 12
0
    def get_releases(self, *args, **kwargs):
        """
        Get the list of matching releases

        :return: The matching modules
        :rtype: dict
        """
        return releases.view(*args, recurse_deps=False, view_all_matching=True, **kwargs)
Ejemplo n.º 13
0
    def test_db_closing_with_exception(self, mock_get_data, mock_unit_generator):
        mock_get_data.return_value = {
            'repo1': {'db': mock.MagicMock(), 'protocol': 'http'},
            'repo2': {'db': mock.MagicMock(), 'protocol': 'http'},
        }
        mock_unit_generator.return_value = []

        data = releases.view(constants.FORGE_NULL_AUTH_VALUE, 'repo_foo', 'me/mymodule')
        self.assertEqual(data.status_code, 404)
        mock_get_data.return_value['repo1']['db'].close.assert_called_once_with()
        mock_get_data.return_value['repo2']['db'].close.assert_called_once_with()
Ejemplo n.º 14
0
    def test_filtering_view_all_true(self, mock_get_data, mock_unit_generator, mock_host):
        mock_get_data.return_value = {
            'repo1': {'db': mock.MagicMock(), 'protocol': 'http'},
        }
        u1 = unit_generator(version='1.0.0')
        u2 = unit_generator(version='2.0.0')
        mock_unit_generator.return_value = [u1, u2]

        result = releases.view(constants.FORGE_NULL_AUTH_VALUE, 'repo_foo', 'me/mymodule',
                               view_all_matching=True)
        self.assertTrue('me/mymodule' in result)
        self.assertEquals(2, len(result['me/mymodule']))
Ejemplo n.º 15
0
    def test_db_closing_with_exception(self, mock_get_data,
                                       mock_unit_generator):
        mock_get_data.return_value = {
            'repo1': {
                'db': mock.MagicMock(),
                'protocol': 'http'
            },
            'repo2': {
                'db': mock.MagicMock(),
                'protocol': 'http'
            },
        }
        mock_unit_generator.return_value = []

        data = releases.view(constants.FORGE_NULL_AUTH_VALUE, 'repo_foo',
                             'me/mymodule')
        self.assertEqual(data.status_code, 404)
        mock_get_data.return_value['repo1'][
            'db'].close.assert_called_once_with()
        mock_get_data.return_value['repo2'][
            'db'].close.assert_called_once_with()
 def test_close_unit_db(self, mock_find):
     result = releases.view(constants.FORGE_NULL_AUTH_VALUE, 'repo1', 'foo/bar')
     mock_find.return_value.db.close.assert_called_once_with()
 def test_with_version(self, mock_find):
     result = releases.view(constants.FORGE_NULL_AUTH_VALUE, 'repo1', 'foo/bar', '1.0.0')
     mock_find.assert_called_once_with(['repo1'], 'foo/bar', '1.0.0')
     self.assertEqual(result, mock_find.return_value.build_dep_metadata.return_value)
Ejemplo n.º 18
0
 def test_with_version(self, mock_find):
     result = releases.view(constants.FORGE_NULL_AUTH_VALUE, 'repo1',
                            'foo/bar', '1.0.0')
     mock_find.assert_called_once_with(['repo1'], 'foo/bar', '1.0.0')
     self.assertEqual(
         result, mock_find.return_value.build_dep_metadata.return_value)
 def test_repo_and_consumer(self, mock_find):
     # should ignore the consumer
     releases.view('consumer1', 'repo1', 'foo/bar')
     mock_find.assert_called_once_with(['repo1'], 'foo/bar')
Ejemplo n.º 20
0
 def test_close_unit_db(self, mock_find):
     result = releases.view(constants.FORGE_NULL_AUTH_VALUE, 'repo1',
                            'foo/bar')
     mock_find.return_value.db.close.assert_called_once_with()
Ejemplo n.º 21
0
 def test_null_auth(self):
     data = releases.view(constants.FORGE_NULL_AUTH_VALUE,
                          constants.FORGE_NULL_AUTH_VALUE, 'foo/bar')
     self.assertEqual(data.status_code, 401)
Ejemplo n.º 22
0
 def test_repo_and_consumer(self, mock_find):
     # should ignore the consumer
     releases.view('consumer1', 'repo1', 'foo/bar')
     mock_find.assert_called_once_with(['repo1'], 'foo/bar')
Ejemplo n.º 23
0
 def test_null_auth(self):
     data = releases.view(constants.FORGE_NULL_AUTH_VALUE, constants.FORGE_NULL_AUTH_VALUE, 'foo/bar')
     self.assertEqual(data.status_code, 401)