from unittest.mock import MagicMock, Mock import pytest from charms.unit_test import patch_fixture # auto-patched from charmhelpers.core import hookenv from charmhelpers.core import unitdata from charms import layer from charms.layer import aws as layer_aws from reactive import aws as reactive_aws _aws = patch_fixture("charms.layer.aws._aws") mysql_api = patch_fixture("charms.layer.aws.MySQLRDSManager") def test_series_upgrade(): assert layer.status.blocked.call_count == 0 reactive_aws.pre_series_upgrade() assert layer.status.blocked.call_count == 1 @pytest.fixture def mock_kv(): orig = unitdata.kv.return_value unitdata.kv.return_value = MagicMock() yield unitdata.kv.return_value unitdata.kv.return_value = orig
from unittest.mock import Mock from charms.unit_test import patch_fixture # auto-patched from charmhelpers.core import hookenv from charmhelpers.core import unitdata from charms import layer from charms.layer import aws as layer_aws from reactive import aws as reactive_aws _aws = patch_fixture('charms.layer.aws._aws') mysql_api = patch_fixture('charms.layer.aws.MySQLRDSManager') def test_series_upgrade(): assert layer.status.blocked.call_count == 0 reactive_aws.pre_series_upgrade() assert layer.status.blocked.call_count == 1 def test_rds_mysql_api(_aws): hookenv.config.return_value = { 'rds-mysql-port': 3306, 'rds-mysql-storage': 20, 'rds-mysql-instance-class': 'db.t3.small', } unitdata.kv().get.return_value = {} mysql_rds = layer_aws.MySQLRDSManager() _aws.side_effect = [
from pathlib import Path from unittest import mock # patched import subprocess from urllib.request import urlopen from time import sleep import charms.layer from charms.unit_test import patch_fixture import reactive.openstack openstack = charms.layer.openstack status = charms.layer.status log_err = patch_fixture('charms.layer.openstack.log_err') _load_creds = patch_fixture('charms.layer.openstack._load_creds') detect_octavia = patch_fixture('charms.layer.openstack.detect_octavia') _run_with_creds = patch_fixture('charms.layer.openstack._run_with_creds') _openstack = patch_fixture('charms.layer.openstack._openstack') _neutron = patch_fixture('charms.layer.openstack._neutron') LoadBalancerClient = patch_fixture('charms.layer.openstack.LoadBalancerClient') OctaviaLBClient = patch_fixture('charms.layer.openstack.OctaviaLBClient') NeutronLBClient = patch_fixture('charms.layer.openstack.NeutronLBClient') _default_subnet = patch_fixture('charms.layer.openstack._default_subnet') kv = patch_fixture('charms.layer.openstack.kv') config = patch_fixture('charms.layer.openstack.config', {}) get_port_sec_enabled = patch_fixture('charms.layer.openstack.BaseLBImpl' '.get_port_sec_enabled', patch_opts={'return_value': True}, fixture_opts={'autouse': True})
from pathlib import Path from unittest import mock # patched import subprocess from urllib.request import urlopen from time import sleep import charms.layer from charms.unit_test import patch_fixture import reactive.openstack openstack = charms.layer.openstack status = charms.layer.status log_err = patch_fixture('charms.layer.openstack.log_err') _load_creds = patch_fixture('charms.layer.openstack._load_creds') detect_octavia = patch_fixture('charms.layer.openstack.detect_octavia') _run_with_creds = patch_fixture('charms.layer.openstack._run_with_creds') _openstack = patch_fixture('charms.layer.openstack._openstack') _neutron = patch_fixture('charms.layer.openstack._neutron') LoadBalancerClient = patch_fixture('charms.layer.openstack.LoadBalancerClient') OctaviaLBClient = patch_fixture('charms.layer.openstack.OctaviaLBClient') NeutronLBClient = patch_fixture('charms.layer.openstack.NeutronLBClient') _default_subnet = patch_fixture('charms.layer.openstack._default_subnet') kv = patch_fixture('charms.layer.openstack.kv') config = patch_fixture('charms.layer.openstack.config', {}) _normalize_creds = patch_fixture('charms.layer.openstack._normalize_creds') _save_creds = patch_fixture('charms.layer.openstack._save_creds') _determine_version = patch_fixture('charms.layer.openstack._determine_version')
from charms.unit_test import patch_fixture from charmhelpers.core import host # patched from charms import layer from reactive import docker_registry as handlers start_registry = patch_fixture('charms.layer.docker_registry.start_registry') stop_registry = patch_fixture('charms.layer.docker_registry.stop_registry') def test_series_upgrade(start_registry, stop_registry): assert start_registry.call_count == 0 assert stop_registry.call_count == 0 assert host.service_pause.call_count == 0 assert host.service_resume.call_count == 0 assert layer.status.blocked.call_count == 0 handlers.pre_series_upgrade() assert start_registry.call_count == 0 assert stop_registry.call_count == 1 assert host.service_pause.call_count == 1 assert host.service_resume.call_count == 0 assert layer.status.blocked.call_count == 1 handlers.post_series_upgrade() assert start_registry.call_count == 1 assert stop_registry.call_count == 1 assert host.service_pause.call_count == 1 assert host.service_resume.call_count == 1 assert layer.status.blocked.call_count == 1