mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-25 01:16:14 +01:00
Merge pull request #1432 from dmach/fix-vc_export_env
Fix retrieving config values in core.vc_export_env()
This commit is contained in:
commit
bf0bbf3398
@ -9113,12 +9113,12 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
"""
|
"""
|
||||||
Show fullname and email of a buildservice user
|
Show fullname and email of a buildservice user
|
||||||
"""
|
"""
|
||||||
usernames = opts.user
|
|
||||||
apiurl = self.get_api_url()
|
apiurl = self.get_api_url()
|
||||||
if len(usernames) < 1:
|
usernames = opts.user
|
||||||
if 'user' not in conf.config['api_host_options'][apiurl]:
|
|
||||||
raise oscerr.WrongArgs('your oscrc does not have your user name.')
|
if not usernames:
|
||||||
usernames = (conf.config['api_host_options'][apiurl]['user'],)
|
usernames = [conf.config["api_host_options"][apiurl]["user"]]
|
||||||
|
|
||||||
for name in usernames:
|
for name in usernames:
|
||||||
user = get_user_data(apiurl, name, 'login', 'realname', 'email')
|
user = get_user_data(apiurl, name, 'login', 'realname', 'email')
|
||||||
if len(user) == 3:
|
if len(user) == 3:
|
||||||
|
@ -8905,7 +8905,7 @@ def vc_export_env(apiurl: str, quiet=False):
|
|||||||
|
|
||||||
for (tag, envs) in tag2envs.items():
|
for (tag, envs) in tag2envs.items():
|
||||||
env_present = [env for env in envs if env in os.environ]
|
env_present = [env for env in envs if env in os.environ]
|
||||||
config_present = tag in conf.config['api_host_options'][apiurl]
|
config_present = bool(conf.config['api_host_options'][apiurl].get(tag, None))
|
||||||
if not env_present and not config_present:
|
if not env_present and not config_present:
|
||||||
missing_tags.append(tag)
|
missing_tags.append(tag)
|
||||||
elif config_present:
|
elif config_present:
|
||||||
|
85
tests/test_vc.py
Normal file
85
tests/test_vc.py
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
import importlib
|
||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import osc.conf
|
||||||
|
from osc.core import vc_export_env
|
||||||
|
|
||||||
|
from .common import GET
|
||||||
|
from .common import patch
|
||||||
|
|
||||||
|
|
||||||
|
class TestVC(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
importlib.reload(osc.conf)
|
||||||
|
|
||||||
|
config = osc.conf.config
|
||||||
|
host_options = osc.conf.HostOptions(
|
||||||
|
config, apiurl="http://localhost", username="Admin"
|
||||||
|
)
|
||||||
|
config.api_host_options[host_options["apiurl"]] = host_options
|
||||||
|
config["apiurl"] = host_options["apiurl"]
|
||||||
|
self.host_options = host_options
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
importlib.reload(osc.conf)
|
||||||
|
|
||||||
|
@patch.dict(os.environ, {}, clear=True)
|
||||||
|
def test_vc_export_env_conf(self):
|
||||||
|
self.host_options.realname = "<REALNAME>"
|
||||||
|
self.host_options.email = "<EMAIL>"
|
||||||
|
vc_export_env("http://localhost")
|
||||||
|
expected = {
|
||||||
|
"VC_REALNAME": "<REALNAME>",
|
||||||
|
"VC_MAILADDR": "<EMAIL>",
|
||||||
|
"mailaddr": "<EMAIL>",
|
||||||
|
}
|
||||||
|
self.assertEqual(os.environ, expected)
|
||||||
|
|
||||||
|
@patch.dict(os.environ, {}, clear=True)
|
||||||
|
@GET(
|
||||||
|
"http://localhost/person/Admin",
|
||||||
|
text="<person><login>Admin</login><email>root@localhost</email><realname>OBS Instance Superuser</realname></person>",
|
||||||
|
)
|
||||||
|
def test_vc_export_env_conf_realname(self):
|
||||||
|
self.host_options.realname = "<REALNAME>"
|
||||||
|
vc_export_env("http://localhost")
|
||||||
|
expected = {
|
||||||
|
"VC_REALNAME": "<REALNAME>",
|
||||||
|
"VC_MAILADDR": "root@localhost",
|
||||||
|
"mailaddr": "root@localhost",
|
||||||
|
}
|
||||||
|
self.assertEqual(os.environ, expected)
|
||||||
|
|
||||||
|
@patch.dict(os.environ, {}, clear=True)
|
||||||
|
@GET(
|
||||||
|
"http://localhost/person/Admin",
|
||||||
|
text="<person><login>Admin</login><email>root@localhost</email><realname>OBS Instance Superuser</realname></person>",
|
||||||
|
)
|
||||||
|
def test_vc_export_env_conf_email(self):
|
||||||
|
self.host_options.email = "<EMAIL>"
|
||||||
|
vc_export_env("http://localhost")
|
||||||
|
expected = {
|
||||||
|
"VC_REALNAME": "OBS Instance Superuser",
|
||||||
|
"VC_MAILADDR": "<EMAIL>",
|
||||||
|
"mailaddr": "<EMAIL>",
|
||||||
|
}
|
||||||
|
self.assertEqual(os.environ, expected)
|
||||||
|
|
||||||
|
@patch.dict(os.environ, {}, clear=True)
|
||||||
|
@GET(
|
||||||
|
"http://localhost/person/Admin",
|
||||||
|
text="<person><login>Admin</login><email>root@localhost</email><realname>OBS Instance Superuser</realname></person>",
|
||||||
|
)
|
||||||
|
def test_vc_export_env_api_call(self):
|
||||||
|
vc_export_env("http://localhost")
|
||||||
|
expected = {
|
||||||
|
"VC_REALNAME": "OBS Instance Superuser",
|
||||||
|
"VC_MAILADDR": "root@localhost",
|
||||||
|
"mailaddr": "root@localhost",
|
||||||
|
}
|
||||||
|
self.assertEqual(os.environ, expected)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user