Browse Source

Merge "Superfluous imports are now mocked"

changes/20/774220/3
Zuul 1 month ago
committed by Gerrit Code Review
parent
commit
97d82bfeaa
13 changed files with 113 additions and 35 deletions
  1. +8
    -6
      validations_common/tests/callback_plugins/test_fail_if_no_hosts.py
  2. +6
    -3
      validations_common/tests/callback_plugins/test_http_json.py
  3. +6
    -3
      validations_common/tests/callback_plugins/test_validation_json.py
  4. +6
    -5
      validations_common/tests/callback_plugins/test_validation_output.py
  5. +9
    -3
      validations_common/tests/callback_plugins/test_validation_stdout.py
  6. +24
    -0
      validations_common/tests/fakes.py
  7. +8
    -2
      validations_common/tests/library/test_advanced_format.py
  8. +8
    -4
      validations_common/tests/library/test_check_package_update.py
  9. +8
    -2
      validations_common/tests/library/test_haproxy_conf.py
  10. +8
    -2
      validations_common/tests/library/test_hiera.py
  11. +7
    -2
      validations_common/tests/library/test_reportentry.py
  12. +7
    -1
      validations_common/tests/library/test_validations_read_ini.py
  13. +8
    -2
      validations_common/tests/library/test_warn.py

+ 8
- 6
validations_common/tests/callback_plugins/test_fail_if_no_hosts.py View File

@ -19,16 +19,18 @@ test_fail_if_no_hosts
Tests for `fail_if_no_hosts` callback plugin.
"""
try:
from unittest import mock
except ImportError:
import mock
from validations_common.tests import base
from validations_common.tests import fakes
import validations_common.library.reportentry as validation
from validations_common.callback_plugins import fail_if_no_hosts
from validations_common.tests import base
from ansible.plugins.callback import CallbackBase
from ansible.executor.stats import AggregateStats
from unittest import mock
class TestFailIfNoHosts(base.TestCase):
@ -64,7 +66,7 @@ class TestFailIfNoHosts(base.TestCase):
the callback calls sys.exit.
"""
callback = fail_if_no_hosts.CallbackModule()
stats = AggregateStats()
stats = mock.MagicMock()
callback.v2_playbook_on_stats(stats)
mock_exit.assert_called_once_with(10)
@ -82,7 +84,7 @@ class TestFailIfNoHosts(base.TestCase):
"""
callback = fail_if_no_hosts.CallbackModule()
stats = AggregateStats()
stats = mock.MagicMock()
stats.processed = {
'system_foo': 'foo',


+ 6
- 3
validations_common/tests/callback_plugins/test_http_json.py View File

@ -19,13 +19,16 @@ test_http_json
Tests for `http_json` callback plugin.
"""
try:
from unittest import mock
except ImportError:
import mock
from validations_common.tests import base
from validations_common.tests import fakes
import validations_common.library.reportentry as validation
from validations_common.callback_plugins import http_json
from validations_common.tests import base
from unittest import mock
class TestHttpJson(base.TestCase):


+ 6
- 3
validations_common/tests/callback_plugins/test_validation_json.py View File

@ -19,12 +19,15 @@ test_validation_json
Tests for `validation_json` callback plugin.
"""
try:
from unittest import mock
except ImportError:
import mock
import validations_common.library.reportentry as validation
from validations_common.tests import base
from validations_common.tests import fakes
from unittest import mock
import validations_common.library.reportentry as validation
class TestValidationJson(base.TestCase):


+ 6
- 5
validations_common/tests/callback_plugins/test_validation_output.py View File

@ -19,17 +19,18 @@ test_validation_output
Tests for `validation_output` callback plugin.
"""
try:
from unittest import mock
except ImportError:
import mock
from unittest import mock
from validations_common.tests import base
from validations_common.tests import fakes
from ansible.executor.stats import AggregateStats
from ansible.parsing.ajson import AnsibleJSONEncoder
from ansible.playbook import Playbook
from ansible.plugins.callback import CallbackBase
import validations_common.library.reportentry as validation
from validations_common.callback_plugins import validation_output
from validations_common.tests import base
class MockStats(mock.MagicMock):


+ 9
- 3
validations_common/tests/callback_plugins/test_validation_stdout.py View File

@ -21,13 +21,19 @@ Tests for `validation_stdout` callback plugin.
"""
import os
import re
from unittest import mock
from ansible.plugins.callback import CallbackBase
try:
from unittest import mock
except ImportError:
import mock
from validations_common.tests import base
from validations_common.tests import fakes
import validations_common.library.reportentry as validation
from validations_common.callback_plugins import validation_stdout
from validations_common.tests import base
from ansible.plugins.callback import CallbackBase
def is_iso_time(time_string):


+ 24
- 0
validations_common/tests/fakes.py View File

@ -0,0 +1,24 @@
# -*- 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.
import sys
try:
from unittest import mock
except ImportError:
import mock
#This section mocks unnecessary module imports.
sys.modules['ansible.parsing.ajson'] = mock.MagicMock()
sys.modules['prettytable'] = mock.MagicMock()

+ 8
- 2
validations_common/tests/library/test_advanced_format.py View File

@ -12,9 +12,15 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
from validations_common.library import advanced_format
try:
from unittest import mock
except ImportError:
import mock
from validations_common.tests import base
from validations_common.tests import fakes
from validations_common.library import advanced_format
class TestAdvancedFormat(base.TestCase):


+ 8
- 4
validations_common/tests/library/test_check_package_update.py View File

@ -12,13 +12,17 @@
# License for the specific language governing permissions and limitations
# under the License.
import subprocess
from unittest import mock
from validations_common.library import check_package_update as cppkg
try:
from unittest import mock
except ImportError:
import mock
from validations_common.tests import base
from validations_common.tests import fakes
import subprocess
from validations_common.library import check_package_update as cppkg
PKG_INSTALLED = "foo-package|6.1.5|1|x86_64"
PKG_INVALID = "foo-package|6.1.5|x86_64"


+ 8
- 2
validations_common/tests/library/test_haproxy_conf.py View File

@ -12,9 +12,15 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
from validations_common.library import haproxy_conf
try:
from unittest import mock
except ImportError:
import mock
from validations_common.tests import base
from validations_common.tests import fakes
from validations_common.library import haproxy_conf
class TestHaproxyConf(base.TestCase):


+ 8
- 2
validations_common/tests/library/test_hiera.py View File

@ -12,9 +12,15 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
from validations_common.library import hiera
try:
from unittest import mock
except ImportError:
import mock
from validations_common.tests import base
from validations_common.tests import fakes
from validations_common.library import hiera
class TestHiera(base.TestCase):


+ 7
- 2
validations_common/tests/library/test_reportentry.py View File

@ -19,11 +19,16 @@ test_report_entry
Tests for `reportentry` module.
"""
try:
from unittest import mock
except ImportError:
import mock
import validations_common.library.reportentry as validation
from validations_common.tests import base
from validations_common.tests import fakes
import validations_common.library.reportentry as validation
from unittest import mock
reason = "Reason #1"
recommendation = ['Recommendation #1']


+ 7
- 1
validations_common/tests/library/test_validations_read_ini.py View File

@ -23,9 +23,15 @@ Tests for `validations_read_ini` module.
import os
import tempfile
import validations_common.library.validations_read_ini as validation
try:
from unittest import mock
except ImportError:
import mock
from validations_common.tests import base
from validations_common.tests import fakes
import validations_common.library.validations_read_ini as validation
invalid_content = '''
[DEFAULT#


+ 8
- 2
validations_common/tests/library/test_warn.py View File

@ -12,9 +12,15 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
from validations_common.library import warn
try:
from unittest import mock
except ImportError:
import mock
from validations_common.tests import base
from validations_common.tests import fakes
from validations_common.library import warn
class TestWarn(base.TestCase):


Loading…
Cancel
Save