Exemplo n.º 1
0
    def test_authenticate_success(self):
        cs = client.Client("username", "password", "project_id")
        management_url = 'https://servers.api.rackspacecloud.com/v1.0/443470'
        auth_response = httplib2.Response({
            'status':
            204,
            'x-server-management-url':
            management_url,
            'x-auth-token':
            '1b751d74-de0c-46ae-84f0-915744b582d1',
        })
        mock_request = mock.Mock(return_value=(auth_response, None))

        @mock.patch.object(httplib2.Http, "request", mock_request)
        def test_auth_call():
            cs.client.authenticate()
            headers = {
                'X-Auth-User': '******',
                'X-Auth-Key': 'password',
                'X-Auth-Project-Id': 'project_id',
                'User-Agent': cs.client.USER_AGENT
            }
            mock_request.assert_called_with(cs.client.auth_url,
                                            'GET',
                                            headers=headers)
            self.assertEqual(cs.client.management_url,
                             auth_response['x-server-management-url'])
            self.assertEqual(cs.client.auth_token,
                             auth_response['x-auth-token'])

        test_auth_call()
Exemplo n.º 2
0
    def test_auth_manual(self):
        cs = client.Client("username", "password", "project_id")

        @mock.patch.object(cs.client, 'authenticate')
        def test_auth_call(m):
            cs.authenticate()
            m.assert_called()

        test_auth_call()
Exemplo n.º 3
0
    def test_authenticate_failure(self):
        cs = client.Client("username", "password", "project_id")
        auth_response = httplib2.Response({'status': 401})
        mock_request = mock.Mock(return_value=(auth_response, None))

        @mock.patch.object(httplib2.Http, "request", mock_request)
        def test_auth_call():
            self.assertRaises(exceptions.Unauthorized, cs.client.authenticate)

        test_auth_call()
Exemplo n.º 4
0
def main():
    (opts, args) = parse_args()
    auth_url = opts.uk and "https://lon.auth.api.rackspacecloud.com/v1.0" \
                       or "https://auth.api.rackspacecloud.com/v1.0"
    api = nova.Client(args[0], args[1], None, auth_url)
    servers = parse_hosts(api.servers.list(), opts.public)

    if opts.stdout:
        for (name, ip) in servers:
            print "%s\t%s" % (ip, name)
    else:
        write_new_hosts(servers)
Exemplo n.º 5
0
    def test_auth_automatic(self):
        cs = client.Client("username", "password", "project_id")
        http_client = cs.client
        http_client.management_url = ''
        mock_request = mock.Mock(return_value=(None, None))

        @mock.patch.object(http_client, 'request', mock_request)
        @mock.patch.object(http_client, 'authenticate')
        def test_auth_call(m):
            http_client.get('/')
            m.assert_called()
            mock_request.assert_called()

        test_auth_call()