Example #1
0
    def __call__(self, prefix, parsed_args, **kwargs):
        self.httpClient = HttpClient(hostname=parsed_args.hostname,
                                     port=parsed_args.port)
        response = self.httpClient.get_archs(parsed_args.reponame)
        archs = json.load(response)

        if not '/' in prefix:
            archs = [
                item['name'] for item in archs['items'] if
                item['name'].startswith(prefix) and item['name'] != 'repodata'
            ]
        else:
            prefix_parts = prefix.split('/')
            archs = [prefix_parts[0]]

        paths = []
        for arch in archs:
            response = self.httpClient.get_files(parsed_args.reponame, arch)
            files = json.load(response)
            for item in files['items']:
                path = arch + '/' + item['filename']
                if path.endswith('.rpm') and path.startswith(prefix):
                    paths.append(path)

        return paths
Example #2
0
 def __call__(self, prefix, parsed_args, **kwargs):
     self.httpClient = HttpClient(hostname=parsed_args.hostname,
                                  port=parsed_args.port)
     response = self.httpClient.queryVirtual({})
     repo_str = response.read()
     return (reponame for reponame in repo_str.splitlines()
             if reponame.startswith(prefix))
    def test_should_add_leading_slash_to_context_if_missing(self, http_lib):
        mock_connection = Mock()
        http_lib.HTTPConnection.return_value = mock_connection
        self.client = HttpClient("any-host.invalid", 42, context="any/context")

        self.client.doHttpPost('/repo/mutatestuff')

        mock_connection.request.assert_called_with(
            'POST', '/any/context/repo/mutatestuff', '', default_headers())
    def test_should_post_without_context(self, http_lib):
        mock_connection = Mock()
        http_lib.HTTPConnection.return_value = mock_connection
        self.client = HttpClient("any-host.invalid", 42, context=None)

        self.client.doHttpPost('/repo/mutatestuff')

        mock_connection.request.assert_called_with('POST', '/repo/mutatestuff',
                                                   '', default_headers())
    def test_should_delete_without_context(self, http_lib):
        mock_connection = Mock()
        http_lib.HTTPConnection.return_value = mock_connection
        self.client = HttpClient("any-host.invalid", 42, context=None)

        self.client.doHttpDelete('/repo/deletestuff')

        mock_connection.request.assert_called_with('DELETE',
                                                   '/repo/deletestuff', None,
                                                   default_headers())
    def test_should_get_with_context(self, http_lib):
        mock_connection = Mock()
        http_lib.HTTPConnection.return_value = mock_connection
        self.client = HttpClient("any-host.invalid",
                                 42,
                                 context="/any/context")

        self.client.doHttpGet('/repo/querystuff')

        mock_connection.request.assert_called_with(
            'GET', '/any/context/repo/querystuff', None, default_headers())
class StaticRepoCompleter(object):

    def __call__(self, prefix, parsed_args, **kwargs):
        self.httpClient = HttpClient(hostname=parsed_args.hostname, port=parsed_args.port)
        response = self.httpClient.queryStatic({})
        repo_str = response.read()
        return (reponame for reponame in repo_str.splitlines() if reponame.startswith(prefix))
class RepoTagCompleter(object):

    def __call__(self, prefix, parsed_args, **kwargs):
        self.httpClient = HttpClient(hostname=parsed_args.hostname, port=parsed_args.port)
        response = self.httpClient.tagList(parsed_args.reponame)
        tag_str = response.read()
        return (tag for tag in tag_str.splitlines() if tag.startswith(prefix))
Example #9
0
class RepoTagCompleter(object):
    def __call__(self, prefix, parsed_args, **kwargs):
        self.httpClient = HttpClient(hostname=parsed_args.hostname,
                                     port=parsed_args.port)
        response = self.httpClient.tagList(parsed_args.reponame)
        tag_str = response.read()
        return (tag for tag in tag_str.splitlines() if tag.startswith(prefix))
    def test_should_post_without_context(self, http_lib):
        mock_connection = Mock()
        http_lib.HTTPConnection.return_value = mock_connection
        self.client = HttpClient("any-host.invalid", 42, context=None)

        self.client.doHttpPost('/repo/mutatestuff')

        mock_connection.request.assert_called_with('POST', '/repo/mutatestuff', '', default_headers())
    def test_should_delete_with_context(self, http_lib):
        mock_connection = Mock()
        http_lib.HTTPConnection.return_value = mock_connection
        self.client = HttpClient("any-host.invalid", 42, context="/any/context")

        self.client.doHttpDelete('/repo/deletestuff')

        mock_connection.request.assert_called_with('DELETE', '/any/context/repo/deletestuff', None, default_headers())
    def test_should_add_leading_slash_to_context_if_missing(self, http_lib):
        mock_connection = Mock()
        http_lib.HTTPConnection.return_value = mock_connection
        self.client = HttpClient("any-host.invalid", 42, context="any/context")

        self.client.doHttpPost('/repo/mutatestuff')

        mock_connection.request.assert_called_with('POST', '/any/context/repo/mutatestuff', '', default_headers())
Example #13
0
class StaticRepoCompleter(object):
    def __call__(self, prefix, parsed_args, **kwargs):
        self.httpClient = HttpClient(hostname=parsed_args.hostname,
                                     port=parsed_args.port)
        response = self.httpClient.queryStatic({})
        repo_str = response.read()
        return (reponame for reponame in repo_str.splitlines()
                if reponame.startswith(prefix))
Example #14
0
 def run(self, args):
     self.httpClient = HttpClient(hostname=args.hostname,
                                  port=args.port,
                                  context=args.context,
                                  message=args.message)
     if args.username is not None:
         self.httpClient.username = args.username
         if args.password is None:
             self.httpClient.password = self._readPassword()
         else:
             self.httpClient.password = args.password
     return self.doRun(args)
class HttpCallWithoutContextTests(TestCase):

    @patch("yum_repo_client.repoclient.httplib")
    def test_should_get_without_context(self, http_lib):
        mock_connection = Mock()
        http_lib.HTTPConnection.return_value = mock_connection
        self.client = HttpClient("any-host.invalid", 42, context=None)

        self.client.doHttpGet('/repo/querystuff')

        mock_connection.request.assert_called_with('GET', '/repo/querystuff', None, default_headers())

    @patch("yum_repo_client.repoclient.httplib")
    def test_should_delete_without_context(self, http_lib):
        mock_connection = Mock()
        http_lib.HTTPConnection.return_value = mock_connection
        self.client = HttpClient("any-host.invalid", 42, context=None)

        self.client.doHttpDelete('/repo/deletestuff')

        mock_connection.request.assert_called_with('DELETE', '/repo/deletestuff', None, default_headers())

    @patch("yum_repo_client.repoclient.httplib")
    def test_should_post_without_context(self, http_lib):
        mock_connection = Mock()
        http_lib.HTTPConnection.return_value = mock_connection
        self.client = HttpClient("any-host.invalid", 42, context=None)

        self.client.doHttpPost('/repo/mutatestuff')

        mock_connection.request.assert_called_with('POST', '/repo/mutatestuff', '', default_headers())
class HttpCallWithContextTests(TestCase):
    @patch("yum_repo_client.repoclient.httplib")
    def test_should_get_with_context(self, http_lib):
        mock_connection = Mock()
        http_lib.HTTPConnection.return_value = mock_connection
        self.client = HttpClient("any-host.invalid",
                                 42,
                                 context="/any/context")

        self.client.doHttpGet('/repo/querystuff')

        mock_connection.request.assert_called_with(
            'GET', '/any/context/repo/querystuff', None, default_headers())

    @patch("yum_repo_client.repoclient.httplib")
    def test_should_delete_with_context(self, http_lib):
        mock_connection = Mock()
        http_lib.HTTPConnection.return_value = mock_connection
        self.client = HttpClient("any-host.invalid",
                                 42,
                                 context="/any/context")

        self.client.doHttpDelete('/repo/deletestuff')

        mock_connection.request.assert_called_with(
            'DELETE', '/any/context/repo/deletestuff', None, default_headers())

    @patch("yum_repo_client.repoclient.httplib")
    def test_should_post_with_context(self, http_lib):
        mock_connection = Mock()
        http_lib.HTTPConnection.return_value = mock_connection
        self.client = HttpClient("any-host.invalid",
                                 42,
                                 context="/any/context")

        self.client.doHttpPost('/repo/mutatestuff')

        mock_connection.request.assert_called_with(
            'POST', '/any/context/repo/mutatestuff', '', default_headers())

    @patch("yum_repo_client.repoclient.httplib")
    def test_should_add_leading_slash_to_context_if_missing(self, http_lib):
        mock_connection = Mock()
        http_lib.HTTPConnection.return_value = mock_connection
        self.client = HttpClient("any-host.invalid", 42, context="any/context")

        self.client.doHttpPost('/repo/mutatestuff')

        mock_connection.request.assert_called_with(
            'POST', '/any/context/repo/mutatestuff', '', default_headers())
Example #17
0
 def test_remote_server(self):
     repoclient = HttpClient(self.HOST_NAME, self.PORT) 
     
     helper = IntegrationTestHelper(self.HOST_NAME, self.PORT)
     self.assertEquals(httplib.OK, helper.do_http_get('/repo/').status, 'returned response was not ok (200).')
     
     repo_name = unique_repo_name()
     repoclient.createStaticRepo(repo_name)
     repoclient.uploadRpm(repo_name, 'src/test/resources/test-artifact.rpm')
     
     path_to_rpm = "/repo/%s/noarch/test-artifact-1.2-1.noarch.rpm" % (repo_name)
     self.assertEquals(httplib.OK, helper.do_http_get(path_to_rpm).status)
     
     repoclient.generateMetadata(repo_name)
     self.assertEquals(httplib.OK, helper.do_http_get('/repo/%s/repodata/repomd.xml' % repo_name).status)
class PathCompleter(object):

    def __call__(self, prefix, parsed_args, **kwargs):
        self.httpClient = HttpClient(hostname=parsed_args.hostname, port=parsed_args.port)
        response = self.httpClient.get_archs(parsed_args.reponame)
        archs = json.load(response)

        if not '/' in prefix:
            archs = [item['name'] for item in archs['items'] if item['name'].startswith(prefix) and item['name'] != 'repodata']
        else:
            prefix_parts = prefix.split('/')
            archs = [prefix_parts[0]]

        paths = []
        for arch in archs:
            response = self.httpClient.get_files(parsed_args.reponame, arch)
            files = json.load(response)
            for item in files['items']:
                path = arch + '/' + item['filename']
                if path.endswith('.rpm') and path.startswith(prefix):
                    paths.append(path)

        return paths
Example #19
0
 def repoclient(self):
     return HttpClient(self.live_server_host, self.live_server_port,
                       "Integration Test")
 def __call__(self, prefix, parsed_args, **kwargs):
     self.httpClient = HttpClient(hostname=parsed_args.hostname, port=parsed_args.port)
     response = self.httpClient.queryVirtual({})
     repo_str = response.read()
     return (reponame for reponame in repo_str.splitlines() if reponame.startswith(prefix))