mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-10 22:56:15 +01:00
Merge pull request #1190 from dmach/apiurl-no-trailing-slash
store: Remove trailing slash from apiurl
This commit is contained in:
commit
6ddb8e4122
13
osc/store.py
13
osc/store.py
@ -174,13 +174,22 @@ class Store:
|
|||||||
assert node.tag == node_name
|
assert node.tag == node_name
|
||||||
api.write_xml_node_to_file(node, path)
|
api.write_xml_node_to_file(node, path)
|
||||||
|
|
||||||
|
def _sanitize_apiurl(self, value):
|
||||||
|
# apiurl shouldn't end with a slash, strip it so we can use apiurl without modifications
|
||||||
|
# in config['api_host_options'][apiurl] and other places
|
||||||
|
if isinstance(value, str):
|
||||||
|
value = value.strip("/")
|
||||||
|
elif isinstance(value, bytes):
|
||||||
|
value = value.strip(b"/")
|
||||||
|
return value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def apiurl(self):
|
def apiurl(self):
|
||||||
return self.read_string("_apiurl")
|
return self._sanitize_apiurl(self.read_string("_apiurl"))
|
||||||
|
|
||||||
@apiurl.setter
|
@apiurl.setter
|
||||||
def apiurl(self, value):
|
def apiurl(self, value):
|
||||||
self.write_string("_apiurl", value)
|
self.write_string("_apiurl", self._sanitize_apiurl(value))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def project(self):
|
def project(self):
|
||||||
|
@ -98,6 +98,14 @@ class TestStore(unittest.TestCase):
|
|||||||
store2 = Store(self.tmpdir)
|
store2 = Store(self.tmpdir)
|
||||||
self.assertEqual(store2.apiurl, "https://example.com")
|
self.assertEqual(store2.apiurl, "https://example.com")
|
||||||
|
|
||||||
|
def test_apiurl_no_trailing_slash(self):
|
||||||
|
self.store.apiurl = "https://example.com/"
|
||||||
|
self.fileEquals("_apiurl", "https://example.com\n")
|
||||||
|
|
||||||
|
self.store.write_string("_apiurl", "https://example.com/")
|
||||||
|
self.fileEquals("_apiurl", "https://example.com/\n")
|
||||||
|
self.assertEqual(self.store.apiurl, "https://example.com")
|
||||||
|
|
||||||
def test_package(self):
|
def test_package(self):
|
||||||
self.fileEquals("_package", "package name\n")
|
self.fileEquals("_package", "package name\n")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user