add tests for launchpad validation

Change-Id: I45a227397c4c9df78e52ecf6c74509ffc997d430
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2016-11-23 15:29:16 -05:00 committed by Tony Breeds
parent f58b6b7eb9
commit 287e223534
3 changed files with 61 additions and 4 deletions

View File

@ -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,

View File

View File

@ -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))