Lianhao Lu | 0af4624 | 2018-08-29 18:17:46 +0800 | [diff] [blame] | 1 | # Copyright (c) 2018 Intel Corp. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | # |
| 15 | |
| 16 | import pytest |
| 17 | |
| 18 | from vnfsdk_pkgtools import vnfreq |
| 19 | |
Lianhao Lu | 40bcf5a | 2018-08-30 10:24:40 +0800 | [diff] [blame^] | 20 | |
| 21 | def check_result(reqid, reader, tosca, expected_fail_msg): |
| 22 | tester = vnfreq.get_vnfreq_tester(reqid) |
| 23 | tester.check(reader, tosca) |
| 24 | if expected_fail_msg: |
| 25 | assert isinstance(tester.err, vnfreq.VnfRequirementError) |
| 26 | assert expected_fail_msg in str(tester.err) |
| 27 | else: |
| 28 | assert tester.err == 0 |
| 29 | |
| 30 | |
| 31 | def test_R66070(mocker): |
Lianhao Lu | 0af4624 | 2018-08-29 18:17:46 +0800 | [diff] [blame] | 32 | reader = mocker.Mock() |
| 33 | reader.manifest = None |
Lianhao Lu | 40bcf5a | 2018-08-30 10:24:40 +0800 | [diff] [blame^] | 34 | check_result('R-66070', reader, None, 'No manifest file found') |
Lianhao Lu | 0af4624 | 2018-08-29 18:17:46 +0800 | [diff] [blame] | 35 | |
Lianhao Lu | 40bcf5a | 2018-08-30 10:24:40 +0800 | [diff] [blame^] | 36 | |
| 37 | def test_R77707(mocker, tmpdir): |
| 38 | # check only manifest file - success |
| 39 | p1 = tmpdir.join("manifest.mf") |
| 40 | p1.write("manifest") |
| 41 | reader = mocker.Mock() |
| 42 | reader.destination = str(tmpdir) |
| 43 | reader.entry_manifest_file = "manifest.mf" |
| 44 | reader.manifest.digests = {} |
| 45 | check_result('R-77707', reader, None, None) |
| 46 | |
| 47 | # check additional file - fail |
| 48 | p2 = tmpdir.mkdir('sub').join("non-existing") |
| 49 | p2.write("non existing") |
| 50 | check_result('R-77707', reader, None, |
| 51 | 'Package component sub/non-existing not found in manifest file') |
Lianhao Lu | 0af4624 | 2018-08-29 18:17:46 +0800 | [diff] [blame] | 52 | |