1 # -*- coding: utf-8 -*-
3 # Copyright 2020 Whitestack, LLC
4 # *************************************************************
6 # This file is part of OSM common repository.
7 # All Rights Reserved to Whitestack, LLC
9 # Licensed under the Apache License, Version 2.0 (the "License"); you may
10 # not use this file except in compliance with the License. You may obtain
11 # a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18 # License for the specific language governing permissions and limitations
21 # For those usages not covered by the Apache License, Version 2.0 please
22 # contact: agarcia@whitestack.com
25 from osm_common
.sol004_package
import SOL004Package
, SOL004PackageException
29 class SOL004ValidatorTest(unittest
.TestCase
):
30 def test_get_package_file_hash_algorithm_from_manifest_with_metadata_dir(self
):
31 package
= SOL004Package(
32 "osm_common/tests/packages/native_charm_with_metadata_dir_vnf"
34 algorithm
= package
.get_package_file_hash_algorithm_from_manifest(
35 "Scripts/charms/simple/src/charm.py"
37 self
.assertEqual(algorithm
, "SHA-256")
39 def test_get_package_file_hash_algorithm_from_manifest_without_metadata_dir(self
):
40 package
= SOL004Package(
41 "osm_common/tests/packages/native_charm_without_metadata_dir_vnf"
43 algorithm
= package
.get_package_file_hash_algorithm_from_manifest(
44 "Scripts/charms/simple/src/charm.py"
46 self
.assertEqual(algorithm
, "SHA-256")
48 def test_get_package_file_hash_algorithm_from_manifest_on_non_existent_file(self
):
49 package
= SOL004Package(
50 "osm_common/tests/packages/native_charm_with_metadata_dir_vnf"
52 with self
.assertRaises(SOL004PackageException
):
53 package
.get_package_file_hash_algorithm_from_manifest("Non/Existing/file")
55 def test_get_package_file_hash_digest_from_manifest_with_metadata_dir(self
):
56 package
= SOL004Package(
57 "osm_common/tests/packages/native_charm_with_metadata_dir_vnf"
59 digest
= package
.get_package_file_hash_digest_from_manifest(
60 "Scripts/charms/simple/src/charm.py"
63 digest
, "ea72f897a966e6174ed9164fabc3c500df5a2f712eb6b22ab2408afb07d04d14"
66 def test_get_package_file_hash_digest_from_manifest_without_metadata_dir(self
):
67 package
= SOL004Package(
68 "osm_common/tests/packages/native_charm_without_metadata_dir_vnf"
70 digest
= package
.get_package_file_hash_digest_from_manifest(
71 "Scripts/charms/simple/src/charm.py"
74 digest
, "ea72f897a966e6174ed9164fabc3c500df5a2f712eb6b22ab2408afb07d04d14"
77 def test_get_package_file_hash_digest_from_manifest_on_non_existent_file(self
):
78 package
= SOL004Package(
79 "osm_common/tests/packages/native_charm_with_metadata_dir_vnf"
81 with self
.assertRaises(SOL004PackageException
):
82 package
.get_package_file_hash_digest_from_manifest("Non/Existing/file")
84 def test_get_package_file_hash_digest_from_manifest_on_non_existing_hash_entry(
87 package
= SOL004Package("osm_common/tests/packages/invalid_package_vnf")
88 with self
.assertRaises(SOL004PackageException
):
89 package
.get_package_file_hash_digest_from_manifest(
90 "Scripts/charms/simple/hooks/upgrade-charm"
93 def test_validate_package_file_hash_with_metadata_dir(self
):
94 package
= SOL004Package(
95 "osm_common/tests/packages/native_charm_with_metadata_dir_vnf"
97 package
.validate_package_file_hash("Scripts/charms/simple/src/charm.py")
99 def test_validate_package_file_hash_without_metadata_dir(self
):
100 package
= SOL004Package(
101 "osm_common/tests/packages/native_charm_without_metadata_dir_vnf"
103 package
.validate_package_file_hash("Scripts/charms/simple/src/charm.py")
105 def test_validate_package_file_hash_on_non_existing_file(self
):
106 package
= SOL004Package(
107 "osm_common/tests/packages/native_charm_with_metadata_dir_vnf"
109 with self
.assertRaises(SOL004PackageException
):
110 package
.validate_package_file_hash("Non/Existing/file")
112 def test_validate_package_file_hash_on_wrong_manifest_hash(self
):
113 package
= SOL004Package("osm_common/tests/packages/invalid_package_vnf")
114 with self
.assertRaises(SOL004PackageException
):
115 package
.validate_package_file_hash("Scripts/charms/simple/hooks/start")
117 def test_validate_package_file_hash_on_unsupported_hash_algorithm(self
):
118 package
= SOL004Package("osm_common/tests/packages/invalid_package_vnf")
119 with self
.assertRaises(SOL004PackageException
):
120 package
.validate_package_file_hash("Scripts/charms/simple/src/charm.py")
122 def test_validate_package_hashes_with_metadata_dir(self
):
123 package
= SOL004Package(
124 "osm_common/tests/packages/native_charm_with_metadata_dir_vnf"
126 package
.validate_package_hashes()
128 def test_validate_package_hashes_without_metadata_dir(self
):
129 package
= SOL004Package(
130 "osm_common/tests/packages/native_charm_without_metadata_dir_vnf"
132 package
.validate_package_hashes()
134 def test_validate_package_hashes_on_invalid_package(self
):
135 package
= SOL004Package("osm_common/tests/packages/invalid_package_vnf")
136 with self
.assertRaises(SOL004PackageException
):
137 package
.validate_package_hashes()
139 def test_get_descriptor_location_with_metadata_dir(self
):
140 package
= SOL004Package(
141 "osm_common/tests/packages/native_charm_with_metadata_dir_vnf"
143 descriptor_path
= package
.get_descriptor_location()
144 self
.assertEqual(descriptor_path
, "Definitions/native_charm_vnfd.yaml")
146 def test_get_descriptor_location_without_metadata_dir(self
):
147 package
= SOL004Package(
148 "osm_common/tests/packages/native_charm_without_metadata_dir_vnf"
150 descriptor_path
= package
.get_descriptor_location()
151 self
.assertEqual(descriptor_path
, "native_charm_vnfd.yaml")