2017-05-01 17:33:31 -05:00
|
|
|
import unittest
|
|
|
|
from osc import conf
|
2018-01-08 21:08:00 -06:00
|
|
|
from osclib.conf import DEFAULT
|
2017-05-01 17:33:31 -05:00
|
|
|
from osclib.conf import Config
|
2018-08-16 21:46:05 -05:00
|
|
|
from osclib.core import attribute_value_save
|
2018-08-16 23:32:36 -05:00
|
|
|
from osclib.memoize import memoize_session_reset
|
2017-05-01 17:33:31 -05:00
|
|
|
from osclib.stagingapi import StagingAPI
|
2019-05-04 16:11:51 +02:00
|
|
|
from . import OBSLocal
|
2017-05-01 17:33:31 -05:00
|
|
|
|
|
|
|
class TestConfig(unittest.TestCase):
|
2019-04-21 12:00:26 +02:00
|
|
|
def setup_vcr(self):
|
2019-05-04 16:11:51 +02:00
|
|
|
return OBSLocal.StagingWorkflow()
|
2018-08-16 21:46:05 -05:00
|
|
|
|
2017-05-01 17:33:31 -05:00
|
|
|
def test_basic(self):
|
2019-04-21 12:00:26 +02:00
|
|
|
wf = self.setup_vcr()
|
|
|
|
self.assertEqual('openSUSE', conf.config[wf.project]['lock-ns'])
|
2017-05-01 17:33:31 -05:00
|
|
|
|
|
|
|
def test_remote(self):
|
2019-04-21 12:00:26 +02:00
|
|
|
wf = self.setup_vcr()
|
2018-08-16 21:46:05 -05:00
|
|
|
# Initial config present in fixtures/oscrc and obs.py attribute default.
|
|
|
|
# Local config fixture contains overridden-by-local and should win over
|
|
|
|
# the remote config value.
|
2019-04-21 12:00:26 +02:00
|
|
|
self.assertEqual('local', conf.config[wf.project]['overridden-by-local'])
|
|
|
|
self.assertEqual('remote-indeed', conf.config[wf.project]['remote-only'])
|
2017-05-01 22:31:36 -05:00
|
|
|
|
2018-08-16 21:46:05 -05:00
|
|
|
# Change remote value.
|
2019-04-21 12:00:26 +02:00
|
|
|
attribute_value_save(wf.apiurl, wf.project, 'Config', 'remote-only = new value\n')
|
|
|
|
wf.load_config()
|
2018-06-15 08:41:24 +02:00
|
|
|
|
2019-04-21 12:00:26 +02:00
|
|
|
self.assertEqual('local', conf.config[wf.project]['overridden-by-local'])
|
|
|
|
self.assertEqual('new value', conf.config[wf.project]['remote-only'])
|
2018-06-15 08:41:24 +02:00
|
|
|
|
2017-05-01 22:31:36 -05:00
|
|
|
def test_remote_none(self):
|
2019-04-21 12:00:26 +02:00
|
|
|
wf = self.setup_vcr()
|
|
|
|
wf.load_config('not_real_project')
|
2018-08-16 21:46:05 -05:00
|
|
|
self.assertTrue(True) # Did not crash!
|
2018-01-08 21:08:00 -06:00
|
|
|
|
|
|
|
def test_pattern_order(self):
|
2019-04-21 12:00:26 +02:00
|
|
|
wf = self.setup_vcr()
|
2018-01-08 21:08:00 -06:00
|
|
|
# Add pattern to defaults in order to identify which was matched.
|
|
|
|
for pattern in DEFAULT:
|
|
|
|
DEFAULT[pattern]['pattern'] = pattern
|
|
|
|
|
|
|
|
# A list of projects that should match each of the DEFAULT patterns.
|
|
|
|
projects = (
|
|
|
|
'openSUSE:Factory',
|
2018-11-20 10:49:03 +01:00
|
|
|
'openSUSE:Factory:ARM',
|
2020-08-11 15:15:24 +08:00
|
|
|
'openSUSE:Jump:15.2',
|
2019-11-21 13:42:19 +01:00
|
|
|
'openSUSE:Leap:15.2',
|
|
|
|
'openSUSE:Leap:15.2:ARM',
|
|
|
|
'openSUSE:Leap:15.2:NonFree',
|
|
|
|
'openSUSE:Leap:15.2:Update',
|
2018-06-29 11:29:21 +02:00
|
|
|
'openSUSE:Backports:SLE-15',
|
2018-08-22 23:54:30 -05:00
|
|
|
'openSUSE:Backports:SLE-15:Update',
|
2018-01-08 21:08:00 -06:00
|
|
|
'SUSE:SLE-15:GA',
|
|
|
|
'SUSE:SLE-12:GA',
|
2018-01-08 21:22:04 -06:00
|
|
|
'GNOME:Factory',
|
2018-01-08 21:08:00 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
# Ensure each pattern is match instead of catch-all pattern.
|
|
|
|
patterns = set()
|
|
|
|
for project in projects:
|
2019-04-21 12:00:26 +02:00
|
|
|
config = Config(wf.apiurl, project)
|
2018-01-08 21:08:00 -06:00
|
|
|
patterns.add(conf.config[project]['pattern'])
|
|
|
|
|
|
|
|
self.assertEqual(len(patterns), len(DEFAULT))
|
2018-08-16 23:32:36 -05:00
|
|
|
|
|
|
|
def test_get_memoize_reset(self):
|
|
|
|
"""Ensure memoize_session_reset() properly forces re-fetch of config."""
|
2019-04-21 12:00:26 +02:00
|
|
|
wf = self.setup_vcr()
|
|
|
|
self.assertEqual('remote-indeed', Config.get(wf.apiurl, wf.project)['remote-only'])
|
2018-08-16 23:32:36 -05:00
|
|
|
|
2019-04-21 12:00:26 +02:00
|
|
|
attribute_value_save(wf.apiurl, wf.project, 'Config', 'remote-only = new value\n')
|
2018-08-16 23:32:36 -05:00
|
|
|
memoize_session_reset()
|
|
|
|
|
2019-04-21 12:00:26 +02:00
|
|
|
self.assertEqual('new value', Config.get(wf.apiurl, wf.project)['remote-only'])
|