Fixed invalid call signature for clone-command
Also make versions as optional field in packages_schema. Fixed ValidationError formatting when path contains int indexes. Closes-Bug: 1543503 Change-Id: Idf070b4431bdac2c49340e9e09902a5b39d2a548
This commit is contained in:
parent
9e107cde9a
commit
34b2ba01b2
|
@ -258,5 +258,7 @@ class RepositoryApi(object):
|
|||
def _raise_validation_error(what, details, path):
|
||||
message = "Invalid {0}: {1}.".format(what, details)
|
||||
if path:
|
||||
message = "\n".join((message, "Field: {0}".format(".".join(path))))
|
||||
message += "\nField: [{0}]".format(
|
||||
"][".join(repr(p) for p in path)
|
||||
)
|
||||
raise ValueError(message)
|
||||
|
|
|
@ -32,21 +32,12 @@ class CloneCommand(PackagesMixin, RepositoriesMixin, BaseRepoCommand):
|
|||
required=True,
|
||||
help="The path to the destination folder."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--clean",
|
||||
dest="keep_existing",
|
||||
action='store_false',
|
||||
default=True,
|
||||
help="Remove packages that does not exist in origin repo."
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--sources",
|
||||
action='store_true',
|
||||
default=False,
|
||||
help="Also copy source packages."
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--locales",
|
||||
action='store_true',
|
||||
|
@ -61,7 +52,6 @@ class CloneCommand(PackagesMixin, RepositoriesMixin, BaseRepoCommand):
|
|||
parsed_args.repositories,
|
||||
parsed_args.requirements,
|
||||
parsed_args.destination,
|
||||
parsed_args.keep_existing,
|
||||
parsed_args.sources,
|
||||
parsed_args.locales,
|
||||
parsed_args.include_mandatory
|
||||
|
|
|
@ -142,7 +142,7 @@ class RepositoryController(object):
|
|||
|
||||
:return : Return a jsonschema represented as a dict
|
||||
"""
|
||||
return self.driver.repository_data_schema()
|
||||
return self.driver.get_repository_data_schema()
|
||||
|
||||
def _copy_packages(self, target, packages, observer):
|
||||
with self.context.async_section() as section:
|
||||
|
|
|
@ -22,8 +22,7 @@ PACKAGES_SCHEMA = {
|
|||
"items": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"name",
|
||||
"versions"
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"name": {
|
||||
|
|
|
@ -55,7 +55,6 @@ class TestCliCommands(base.TestCase):
|
|||
"-d", "/root",
|
||||
"-t", "deb",
|
||||
"-a", "x86_64",
|
||||
"--clean",
|
||||
"--skip-mandatory"
|
||||
]
|
||||
|
||||
|
@ -80,6 +79,11 @@ class TestCliCommands(base.TestCase):
|
|||
def start_cmd(self, cmd, argv):
|
||||
cmd.debug(argv + self.common_argv)
|
||||
|
||||
def get_api_instance_mock(self, api_mock):
|
||||
api_instance = mock.MagicMock(spec=RepositoryApi)
|
||||
api_mock.create.return_value = api_instance
|
||||
return api_instance
|
||||
|
||||
def check_common_config(self, config):
|
||||
self.assertEqual("http://proxy", config.http_proxy)
|
||||
self.assertEqual("https://proxy", config.https_proxy)
|
||||
|
@ -93,8 +97,7 @@ class TestCliCommands(base.TestCase):
|
|||
[{"name": "repo"}],
|
||||
[{"name": "package"}],
|
||||
]
|
||||
api_instance = mock.MagicMock(spec=RepositoryApi)
|
||||
api_mock.create.return_value = api_instance
|
||||
api_instance = self.get_api_instance_mock(api_mock)
|
||||
api_instance.clone_repositories.return_value = CopyStatistics()
|
||||
self.start_cmd(clone, self.clone_argv)
|
||||
api_mock.create.assert_called_once_with(
|
||||
|
@ -105,7 +108,7 @@ class TestCliCommands(base.TestCase):
|
|||
read_file_mock.assert_any_call("packages.yaml")
|
||||
api_instance.clone_repositories.assert_called_once_with(
|
||||
[{"name": "repo"}], [{"name": "package"}], "/root",
|
||||
False, False, False, False
|
||||
False, False, False
|
||||
)
|
||||
stdout_mock.write.assert_called_once_with(
|
||||
"Packages copied: 0/0.\n"
|
||||
|
@ -113,8 +116,7 @@ class TestCliCommands(base.TestCase):
|
|||
|
||||
def test_get_packages_cmd(self, api_mock, read_file_mock, stdout_mock):
|
||||
read_file_mock.return_value = [{"name": "repo"}]
|
||||
api_instance = mock.MagicMock(spec=RepositoryApi)
|
||||
api_mock.create.return_value = api_instance
|
||||
api_instance = self.get_api_instance_mock(api_mock)
|
||||
api_instance.get_packages.return_value = [
|
||||
gen_package(name="test1", filesize=1, requires=None,
|
||||
obsoletes=None, provides=None)
|
||||
|
@ -136,8 +138,7 @@ class TestCliCommands(base.TestCase):
|
|||
|
||||
def test_get_unresolved_cmd(self, api_mock, read_file_mock, stdout_mock):
|
||||
read_file_mock.return_value = [{"name": "repo"}]
|
||||
api_instance = mock.MagicMock(spec=RepositoryApi)
|
||||
api_mock.create.return_value = api_instance
|
||||
api_instance = self.get_api_instance_mock(api_mock)
|
||||
api_instance.get_unresolved_dependencies.return_value = [
|
||||
gen_relation(name="test")
|
||||
]
|
||||
|
@ -162,8 +163,7 @@ class TestCliCommands(base.TestCase):
|
|||
[{"name": "repo"}],
|
||||
["/test1.deb", "/test2.deb", "/test3.deb"],
|
||||
]
|
||||
api_instance = mock.MagicMock(spec=RepositoryApi)
|
||||
api_mock.create.return_value = api_instance
|
||||
api_instance = self.get_api_instance_mock(api_mock)
|
||||
api_instance.create_repository.return_value = gen_repository()
|
||||
self.start_cmd(create, self.create_argv)
|
||||
api_mock.create.assert_called_once_with(
|
||||
|
|
|
@ -271,12 +271,12 @@ class TestRepositoryApi(base.TestCase):
|
|||
def test_validate_invalid_data(self, jschema_m):
|
||||
jschema_m.ValidationError = jsonschema.ValidationError
|
||||
jschema_m.SchemaError = jsonschema.SchemaError
|
||||
|
||||
paths = [("a", "b"), ()]
|
||||
for path in paths:
|
||||
paths = [(("a", 0), "\['a'\]\[0\]"), ((), "")]
|
||||
for path, details in paths:
|
||||
msg = "Invalid data: error."
|
||||
details = "\nField: {0}".format(".".join(path)) if path else ""
|
||||
with self.assertRaisesRegexp(ValueError, msg + details):
|
||||
if details:
|
||||
msg += "\nField: {0}".format(details)
|
||||
with self.assertRaisesRegexp(ValueError, msg):
|
||||
jschema_m.validate.side_effect = jsonschema.ValidationError(
|
||||
"error", path=path
|
||||
)
|
||||
|
@ -285,7 +285,9 @@ class TestRepositoryApi(base.TestCase):
|
|||
jschema_m.validate.reset_mock()
|
||||
|
||||
msg = "Invalid schema: error."
|
||||
with self.assertRaisesRegexp(ValueError, msg + details):
|
||||
if details:
|
||||
msg += "\nField: {0}".format(details)
|
||||
with self.assertRaisesRegexp(ValueError, msg):
|
||||
jschema_m.validate.side_effect = jsonschema.SchemaError(
|
||||
"error", schema_path=path
|
||||
)
|
||||
|
|
|
@ -176,3 +176,9 @@ class TestRepositoryController(base.TestCase):
|
|||
self.driver.add_packages.assert_called_once_with(
|
||||
self.ctrl.context.connection, repo, set(packages)
|
||||
)
|
||||
|
||||
def test_get_repository_data_schema(self):
|
||||
self.assertIs(
|
||||
self.ctrl.driver.get_repository_data_schema(),
|
||||
self.ctrl.get_repository_data_schema()
|
||||
)
|
||||
|
|
|
@ -179,7 +179,8 @@ class TestPackagesSchema(base.TestCase):
|
|||
{"name": "test1", "versions": [">= 1.1.2", "<= 3"]},
|
||||
{"name": "test2", "versions": ["< 3", "> 1", ">= 4"]},
|
||||
{"name": "test3", "versions": ["= 3"]},
|
||||
{"name": "test4", "versions": ["= 3"]}
|
||||
{"name": "test4", "versions": ["= 3"]},
|
||||
{"name": "test4"}
|
||||
]
|
||||
self.assertNotRaises(
|
||||
jsonschema.ValidationError, jsonschema.validate, requirements_data,
|
||||
|
@ -188,7 +189,6 @@ class TestPackagesSchema(base.TestCase):
|
|||
|
||||
def test_validation_fail_for_required_properties(self):
|
||||
requirements_data = [
|
||||
[{"name": "test1"}],
|
||||
[{"versions": ["< 3", "> 1"]}]
|
||||
]
|
||||
for data in requirements_data:
|
||||
|
@ -231,7 +231,11 @@ class TestPackagesSchema(base.TestCase):
|
|||
versions = [
|
||||
["1.1.2"], # relational operator
|
||||
[">=3"], # not whitespace after ro
|
||||
["== 3"] # ==
|
||||
["== 3"],
|
||||
["=> 3"],
|
||||
["=< 3"],
|
||||
[">> 3"],
|
||||
["<< 3"],
|
||||
]
|
||||
for version in versions:
|
||||
self.assertRaisesRegexp(
|
||||
|
|
Loading…
Reference in New Issue