2020-03-16 10:45:53 +01:00
|
|
|
# Copyright 2020 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# 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 unittest import mock
|
|
|
|
from unittest import TestCase
|
|
|
|
|
|
|
|
from validations_libs import utils
|
|
|
|
from validations_libs.tests import fakes
|
2020-03-22 19:04:07 +01:00
|
|
|
from validations_libs.validation_logs import ValidationLogs
|
2020-03-16 10:45:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestUtils(TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestUtils, self).setUp()
|
2020-03-22 19:04:07 +01:00
|
|
|
self.vlog = ValidationLogs()
|
2020-03-16 10:45:53 +01:00
|
|
|
|
2020-03-18 21:03:25 +01:00
|
|
|
@mock.patch('validations_libs.validation.Validation._get_content',
|
|
|
|
return_value=fakes.FAKE_PLAYBOOK)
|
|
|
|
@mock.patch('six.moves.builtins.open')
|
2020-03-24 14:47:16 +01:00
|
|
|
@mock.patch('os.path.exists', return_value=True)
|
|
|
|
def test_get_validations_data(self, mock_exists, mock_open, mock_data):
|
2020-03-18 21:03:25 +01:00
|
|
|
output = {'Name': 'Advanced Format 512e Support',
|
|
|
|
'Description': 'foo', 'Groups': ['prep', 'pre-deployment'],
|
|
|
|
'ID': '512e'}
|
2020-03-24 14:47:16 +01:00
|
|
|
res = utils.get_validations_data('512e')
|
2020-03-18 21:03:25 +01:00
|
|
|
self.assertEqual(res, output)
|
2020-03-16 10:45:53 +01:00
|
|
|
|
|
|
|
def test_get_validations_stats(self):
|
2020-03-22 19:04:07 +01:00
|
|
|
res = self.vlog.get_validations_stats(
|
|
|
|
fakes.VALIDATIONS_LOGS_CONTENTS_LIST)
|
2020-03-16 10:45:53 +01:00
|
|
|
self.assertEqual(res, fakes.VALIDATIONS_STATS)
|