Don't join None values in utils.urljoin
This was seen on resources that don't set an id attribute, ending up with request URLs such as /v1/blargablarga/None instead of /v1/blargablarga/. Change-Id: Ib6fa52c6d4b76f6c9d30418277fdd927afb5d102
This commit is contained in:
parent
fe3e9963b2
commit
407f695609
|
@ -60,6 +60,21 @@ class ResourceTests(base.TestTransportBase):
|
||||||
self.auth = fakes.FakeAuthenticator()
|
self.auth = fakes.FakeAuthenticator()
|
||||||
self.session = session.Session(self.transport, self.auth)
|
self.session = session.Session(self.transport, self.auth)
|
||||||
|
|
||||||
|
@httpretty.activate
|
||||||
|
def test_empty_id(self):
|
||||||
|
self.stub_url(httpretty.GET, path=[fake_path], json=fake_body)
|
||||||
|
obj = FakeResource.new()
|
||||||
|
obj.get(self.session)
|
||||||
|
|
||||||
|
self.assertEqual(fake_id, obj.id)
|
||||||
|
self.assertEqual(fake_name, obj['name'])
|
||||||
|
self.assertEqual(fake_attr1, obj['attr1'])
|
||||||
|
self.assertEqual(fake_attr2, obj['attr2'])
|
||||||
|
|
||||||
|
self.assertEqual(fake_name, obj.name)
|
||||||
|
self.assertEqual(fake_attr1, obj.first)
|
||||||
|
self.assertEqual(fake_attr2, obj.second)
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
self.stub_url(httpretty.POST, path=fake_path, json=fake_body)
|
self.stub_url(httpretty.POST, path=fake_path, json=fake_body)
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from openstack import utils
|
||||||
|
|
||||||
|
|
||||||
|
class Test_urljoin(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_strings(self):
|
||||||
|
root = "http://www.example.com"
|
||||||
|
leaves = "foo", "bar"
|
||||||
|
|
||||||
|
result = utils.urljoin(root, *leaves)
|
||||||
|
self.assertEqual(result, "http://www.example.com/foo/bar")
|
||||||
|
|
||||||
|
def test_with_none(self):
|
||||||
|
root = "http://www.example.com"
|
||||||
|
leaves = "foo", None
|
||||||
|
|
||||||
|
result = utils.urljoin(root, *leaves)
|
||||||
|
self.assertEqual(result, "http://www.example.com/foo/")
|
|
@ -18,4 +18,4 @@ def urljoin(*args):
|
||||||
like /path this should be joined to http://host/path as it is an anchored
|
like /path this should be joined to http://host/path as it is an anchored
|
||||||
link. We generally won't care about that in client.
|
link. We generally won't care about that in client.
|
||||||
"""
|
"""
|
||||||
return '/'.join(str(a).strip('/') for a in args)
|
return '/'.join(str(a or '').strip('/') for a in args)
|
||||||
|
|
Loading…
Reference in New Issue