From 287e223534fb68e7eb4f7e65780cf59ad2df2ca2 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Wed, 23 Nov 2016 15:29:16 -0500 Subject: [PATCH] add tests for launchpad validation Change-Id: I45a227397c4c9df78e52ecf6c74509ffc997d430 Signed-off-by: Doug Hellmann --- openstack_releases/cmds/validate.py | 12 +++-- openstack_releases/tests/__init__.py | 0 openstack_releases/tests/test_validate.py | 53 +++++++++++++++++++++++ 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 openstack_releases/tests/__init__.py create mode 100644 openstack_releases/tests/test_validate.py diff --git a/openstack_releases/cmds/validate.py b/openstack_releases/cmds/validate.py index 1b0dfc345f..4a730cbf38 100644 --- a/openstack_releases/cmds/validate.py +++ b/openstack_releases/cmds/validate.py @@ -64,10 +64,8 @@ def is_a_hash(val): return re.search('^[a-f0-9]{40}$', val, re.I) is not None -def validate_metadata(deliverable_info, team_data, mk_warning, mk_error): - """Look at the general metadata in the deliverable file. - """ - # Look for the launchpad project +def validate_launchpad(deliverable_info, mk_warning, mk_error): + "Look for the launchpad project" try: lp_name = deliverable_info['launchpad'] except KeyError: @@ -77,6 +75,11 @@ def validate_metadata(deliverable_info, team_data, mk_warning, mk_error): if (lp_resp.status_code // 100) == 4: mk_error('Launchpad project %s does not exist' % lp_name) + +def validate_metadata(deliverable_info, team_data, mk_warning, mk_error): + """Look at the general metadata in the deliverable file. + """ + # Look for the team name if 'team' not in deliverable_info: mk_error('No team name given') @@ -372,6 +375,7 @@ def main(): print('ERROR: {}'.format(msg)) errors.append('{}: {}'.format(filename, msg)) + validate_launchpad(deliverable_info, mk_warning, mk_error) validate_metadata( deliverable_info, team_data, diff --git a/openstack_releases/tests/__init__.py b/openstack_releases/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/openstack_releases/tests/test_validate.py b/openstack_releases/tests/test_validate.py new file mode 100644 index 0000000000..56668cd655 --- /dev/null +++ b/openstack_releases/tests/test_validate.py @@ -0,0 +1,53 @@ +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslotest import base + +from openstack_releases.cmds import validate + + +class TestValidateLaunchpad(base.BaseTestCase): + + def test_no_launchpad_name(self): + warnings = [] + errors = [] + validate.validate_launchpad( + {}, + warnings.append, + errors.append, + ) + self.assertEqual(0, len(warnings)) + self.assertEqual(1, len(errors)) + + def test_invalid_launchpad_name(self): + warnings = [] + errors = [] + validate.validate_launchpad( + {'launchpad': 'nonsense-name'}, + warnings.append, + errors.append, + ) + self.assertEqual(0, len(warnings)) + self.assertEqual(1, len(errors)) + + def test_valid_launchpad_name(self): + warnings = [] + errors = [] + validate.validate_launchpad( + {'launchpad': 'oslo.config'}, + warnings.append, + errors.append, + ) + self.assertEqual(0, len(warnings)) + self.assertEqual(0, len(errors))