Merge "Don't join None values in utils.urljoin"
This commit is contained in:
commit
c873ef693b
openstack
@ -60,6 +60,21 @@ class ResourceTests(base.TestTransportBase):
|
||||
self.auth = fakes.FakeAuthenticator()
|
||||
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
|
||||
def test_create(self):
|
||||
self.stub_url(httpretty.POST, path=fake_path, json=fake_body)
|
||||
|
32
openstack/tests/test_utils.py
Normal file
32
openstack/tests/test_utils.py
Normal file
@ -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
|
||||
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
Block a user