From 6c5d681b517a921406968b96362799dee7c33ad2 Mon Sep 17 00:00:00 2001 From: Bulat Gaifullin Date: Tue, 8 Mar 2016 02:00:54 +0300 Subject: [PATCH] Fixed error-handling for input data validation The property absolute_path was 2.5.1 and not available in previous versions Change-Id: Ib4b7e9c9a7f0113275915799624aeef5f6bf8281 Closes-Bug: 1554249 --- packetary/api.py | 6 ++++-- packetary/schemas/package_files_schema.py | 2 +- packetary/tests/test_schemas.py | 14 +++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packetary/api.py b/packetary/api.py index 2da17a7..bd83aeb 100644 --- a/packetary/api.py +++ b/packetary/api.py @@ -310,10 +310,12 @@ class RepositoryApi(object): try: jsonschema.validate(data, schema) except jsonschema.ValidationError as e: - self._raise_validation_error("data", e.message, e.absolute_path) + self._raise_validation_error( + "data", e.message, e.path + ) except jsonschema.SchemaError as e: self._raise_validation_error( - "schema", e.message, e.absolute_schema_path + "schema", e.message, e.schema_path ) @staticmethod diff --git a/packetary/schemas/package_files_schema.py b/packetary/schemas/package_files_schema.py index 2120fed..fef91a6 100644 --- a/packetary/schemas/package_files_schema.py +++ b/packetary/schemas/package_files_schema.py @@ -21,6 +21,6 @@ PACKAGE_FILES_SCHEMA = { "type": "array", "items": { "type": "string", - "pattern": "^(\/|file:\/\/|https?:\/\/).+$" + "pattern": r"^(/|file:///|https?://).+$" } } diff --git a/packetary/tests/test_schemas.py b/packetary/tests/test_schemas.py index 004ebf1..b650098 100644 --- a/packetary/tests/test_schemas.py +++ b/packetary/tests/test_schemas.py @@ -251,9 +251,8 @@ class TestPackageFilesSchema(base.TestCase): def test_valid_file_urls(self): file_urls = [ - "file://test1.pkg", - "file:///test2.pkg", - "/test3.pkg", + "file:///test1.pkg", + "/test2.pkg", "http://test4.pkg", "https://test5.pkg" ] @@ -278,10 +277,11 @@ class TestPackageFilesSchema(base.TestCase): def test_validation_fail_if_invalid_file_urls(self): file_urls = [ - ["test1.pkg"], # does not match pattern - ["./test2.pkg"], # does not match pattern - ["file//test3.pkg"], # does not match pattern - ["http//test4.pkg"] # does not match pattern + ["test1.pkg"], + ["./test2.pkg"], + ["file//test3.pkg"], + ["http//test4.pkg"], + ["file://test4.pkg"] ] for url in file_urls[2:]: