Browse Source

Merge "Tests for validation.py module and helper classes"

changes/18/780518/3
Zuul 1 month ago
committed by Gerrit Code Review
parent
commit
8e04cca047
2 changed files with 127 additions and 0 deletions
  1. +1
    -0
      test-requirements.txt
  2. +126
    -0
      validations_common/tests/test_validation.py

+ 1
- 0
test-requirements.txt View File

@ -12,3 +12,4 @@ testtools>=2.2.0 # MIT
reno>=2.5.0 # Apache-2.0
netaddr>=0.7.18 # BSD
pre-commit # MIT
validations-libs>=1.0.4 # Apache-2.0

+ 126
- 0
validations_common/tests/test_validation.py View File

@ -0,0 +1,126 @@
# -*- coding: utf-8 -*-
# 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.
"""
test_validation
----------------------------------
Tests for `validation` sub module.
"""
import argparse
from unittest import mock
from validations_common import validation
from validations_common.tests import base
class TestValidationModule(base.TestCase):
def setUp(self):
self.module = mock.MagicMock()
super(TestValidationModule, self).setUp()
def test_module_init(self):
"""Check for presence of required module attributes.
Including the color constants needed for output formatting.
"""
required_attributes = [
'DESCRIPTION',
'EPILOG',
'RED',
'GREEN',
'CYAN',
'RESET'
]
module_attributes = set(dir(validation))
self.assertTrue(set(required_attributes).issubset(module_attributes))
class TestCommaListGroupAction(base.TestCase):
def setUp(self):
super(TestCommaListGroupAction, self).setUp()
@mock.patch('validations_common.validation.setattr')
def test_comma_list_group_action(self, mock_setattr):
"""As there is not much to test in this class
the assertions are made on attributes and inheritance.
"""
action = validation._CommaListGroupAction(
dest='foo',
option_strings='')
action('foo', 'bar', 'fizz,buzz')
self.assertEqual(type(action).__mro__[1], argparse.Action)
self.assertEqual(action.dest, 'foo')
self.assertEqual(action.option_strings, '')
mock_setattr.assert_called_once_with('bar', 'foo', ['fizz', 'buzz'])
class TestCommaListAction(base.TestCase):
def setUp(self):
super(TestCommaListAction, self).setUp()
@mock.patch('validations_common.validation.setattr')
def test_comma_list_action(self, mock_setattr):
"""As there is not much to test in this class
the assertions are made on attributes and inheritance.
"""
action = validation._CommaListAction(
dest='foo',
option_strings='')
action('foo', 'bar', 'fizz,buzz')
self.assertEqual(type(action).__mro__[1], argparse.Action)
self.assertEqual(action.dest, 'foo')
self.assertEqual(action.option_strings, '')
mock_setattr.assert_called_once_with('bar', 'foo', ['fizz', 'buzz'])
class TestValidation(base.TestCase):
def setUp(self):
super(TestValidation, self).setUp()
def test_validation_init(self):
pass
def test_validation_parser(self):
pass
def test_validation_print_dict_table(self):
pass
def test_validation_print_tuple_table(self):
pass
def test_validation_write_output(self):
pass
def test_validation_take_action_run(self):
pass
def test_validation_take_action_list(self):
pass
def test_validation_take_action_show(self):
pass

Loading…
Cancel
Save