Here are the examples of the python api mock.NonCallableMock taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
40 Examples
3
Example 1
Project: subscription-manager Source File: fixture.py
def _inject_mock_valid_consumer(self, uuid=None):
"""For changing injected consumer identity to one that passes is_valid()
Returns the injected identity if it need to be examined.
"""
identity = NonCallableMock(name='ValidIdentityMock')
identity.uuid = uuid or "VALIDCONSUMERUUID"
identity.is_valid = Mock(return_value=True)
identity.cert_dir_path = "/not/a/real/path/to/pki/consumer/"
inj.provide(inj.IDENTITY, identity)
return identity
3
Example 2
Project: subscription-manager Source File: fixture.py
def _inject_mock_invalid_consumer(self, uuid=None):
"""For chaning injected consumer identity to one that fails is_valid()
Returns the injected identity if it need to be examined.
"""
invalid_identity = NonCallableMock(name='InvalidIdentityMock')
invalid_identity.is_valid = Mock(return_value=False)
invalid_identity.uuid = uuid or "INVALIDCONSUMERUUID"
invalid_identity.cert_dir_path = "/not/a/real/path/to/pki/consumer/"
inj.provide(inj.IDENTITY, invalid_identity)
return invalid_identity
3
Example 3
Project: subscription-manager Source File: test_entbranding.py
def _inj_mock_ent_dir(self, ents=None):
ent_list = ents or []
mock_ent_dir = mock.NonCallableMock(name='MockEntDir')
mock_ent_dir.list_valid.return_value = ent_list
inj.provide(inj.ENT_DIR, mock_ent_dir)
return mock_ent_dir
3
Example 4
Project: subscription-manager Source File: test_entbranding.py
def test_none_brand_name_on_product(self):
stub_product = StubProduct(id=123, name="An Awesome OS", brand_type='OS')
stub_product.name = None
stub_installed_product = StubProduct(id=123, name="An Awesome OS")
mock_prod_dir = mock.NonCallableMock(name='MockProductDir')
mock_prod_dir.get_installed_products.return_value = [stub_installed_product.id]
mock_ent_cert = mock.Mock(name='MockEntCert')
mock_ent_cert.products = [stub_product]
self._inj_mock_ent_dir([mock_ent_cert])
brand_installer = self.brand_installer_class()
brand_installer.install()
self.assertFalse(self.mock_install.called)
3
Example 5
Project: subscription-manager Source File: test_entbranding.py
def test_none_brand_type_none_brand_name_on_product(self):
stub_product = StubProduct(id=123, name="An Awesome OS")
stub_product.name = None
mock_prod_dir = mock.NonCallableMock(name='MockProductDir')
mock_prod_dir.get_installed_products.return_value = [stub_product.id]
mock_ent_cert = mock.Mock(name='MockEntCert')
mock_ent_cert.products = [stub_product]
self._inj_mock_ent_dir([mock_ent_cert])
brand_installer = self.brand_installer_class()
brand_installer.install()
self.assertFalse(self.mock_install.called)
3
Example 6
Project: subscription-manager Source File: test_entbranding.py
def test_none_brand_type_brand_name_on_product(self):
stub_product = StubProduct(id=123, name="An Awesome OS",
brand_name="Branded Awesome OS")
stub_product.name = None
stub_installed_product = StubProduct(id=123, name="An Awesome OS")
mock_prod_dir = mock.NonCallableMock(name='MockProductDir')
mock_prod_dir.get_installed_products.return_value = [stub_installed_product.id]
mock_ent_cert = mock.Mock(name='MockEntCert')
mock_ent_cert.products = [stub_product]
self._inj_mock_ent_dir([mock_ent_cert])
brand_installer = self.brand_installer_class()
brand_installer.install()
self.assertFalse(self.mock_install.called)
3
Example 7
Project: subscription-manager Source File: test_entbranding.py
def test_wrong_brand_type_brand_name_on_product(self):
stub_product = StubProduct(id=123, name="An Awesome OS",
brand_type='Middleware',
brand_name="Branded Awesome OS")
stub_installed_product = StubProduct(id=123, name="An Awesome OS")
mock_prod_dir = mock.NonCallableMock(name='MockProductDir')
mock_prod_dir.get_installed_products.return_value = [stub_installed_product.id]
mock_ent_cert = mock.Mock(name='MockEntCert')
mock_ent_cert.products = [stub_product]
self._inj_mock_ent_dir([mock_ent_cert])
brand_installer = self.brand_installer_class()
brand_installer.install()
self.assertFalse(self.mock_install.called)
3
Example 8
Project: subscription-manager Source File: test_entbranding.py
def test_wrong_brand_type_none_brand_name_on_product(self):
stub_product = StubProduct(id=123, name="An Awesome OS",
brand_type='Middleware')
stub_installed_product = StubProduct(id=123, name="An Awesome OS")
mock_prod_dir = mock.NonCallableMock(name='MockProductDir')
mock_prod_dir.get_installed_products.return_value = [stub_installed_product.id]
mock_ent_cert = mock.Mock(name='MockEntCert')
mock_ent_cert.products = [stub_product]
self._inj_mock_ent_dir([mock_ent_cert])
brand_installer = self.brand_installer_class()
brand_installer.install()
self.assertFalse(self.mock_install.called)
3
Example 9
Project: subscription-manager Source File: test_entbranding.py
def test_multiple_branded_ent_certs_for_installed_product(self):
stub_product = DefaultStubProduct()
stub_installed_product = DefaultStubInstalledProduct()
mock_prod_dir = mock.NonCallableMock(name='MockProductDir')
mock_prod_dir.get_installed_products.return_value = [stub_installed_product.id]
inj.provide(inj.PROD_DIR, mock_prod_dir)
mock_ent_cert = mock.Mock(name='MockEntCert')
mock_ent_cert.products = [stub_product]
mock_ent_cert_2 = mock.Mock(name='MockEntCert2')
mock_ent_cert_2.products = [stub_product]
brand_installer = self.brand_installer_class([mock_ent_cert, mock_ent_cert_2])
brand_installer.install()
self.assertTrue(self.mock_install.called)
3
Example 10
Project: subscription-manager Source File: test_entbranding.py
def test_get_brand(self):
# inj a prod dir with some installed products
stub_installed_product = DefaultStubInstalledProduct()
stub_product = DefaultStubProduct()
mock_product_dir = mock.NonCallableMock()
mock_product_dir.get_installed_products.return_value = [stub_installed_product.id]
inj.provide(inj.PROD_DIR, mock_product_dir)
mock_ent_cert = mock.Mock()
mock_ent_cert.products = [stub_product]
ent_certs = [mock_ent_cert]
brand_picker = rhelentbranding.RHELBrandPicker(ent_certs)
brand = brand_picker.get_brand()
self.assertTrue("Mock Product", brand.name)
3
Example 11
Project: subscription-manager Source File: test_entbranding.py
def test_get_brand_not_installed(self):
stub_product = DefaultStubProduct()
# note, no 'brand_type' set
other_stub_product = StubProduct(id=321, name="A Non Branded Product")
mock_product_dir = mock.NonCallableMock()
mock_product_dir.get_installed_products.return_value = [other_stub_product.id]
inj.provide(inj.PROD_DIR, mock_product_dir)
mock_ent_cert = mock.Mock()
mock_ent_cert.products = [stub_product]
ent_certs = [mock_ent_cert]
brand_picker = rhelentbranding.RHELBrandPicker(ent_certs)
brand = brand_picker.get_brand()
self.assertTrue(brand is None)
3
Example 12
Project: subscription-manager Source File: test_entbranding.py
def test_is_installed_rhel_branded_product_is_installed(self):
stub_product = DefaultStubProduct()
mock_product_dir = mock.NonCallableMock()
mock_product_dir.get_installed_products.return_value = [stub_product.id]
inj.provide(inj.PROD_DIR, mock_product_dir)
brand_picker = rhelentbranding.RHELBrandPicker([])
irp = brand_picker._is_installed_rhel_branded_product(stub_product)
self.assertTrue(irp)
3
Example 13
Project: subscription-manager Source File: test_entbranding.py
def test_get_installed_branded_products(self):
stub_product = DefaultStubProduct()
mock_product_dir = mock.NonCallableMock()
mock_product_dir.get_installed_products.return_value = [stub_product.id]
inj.provide(inj.PROD_DIR, mock_product_dir)
brand_picker = rhelentbranding.RHELBrandPicker([])
irp = brand_picker._is_installed_rhel_branded_product(stub_product)
self.assertTrue(irp)
3
Example 14
Project: subscription-manager Source File: test_facts_gui.py
def test_update_button_disabled(self):
# Need an unregistered consumer object:
id_mock = NonCallableMock()
id_mock.name = None
id_mock.uuid = None
def new_identity():
return id_mock
provide(IDENTITY, new_identity)
dialog = factsgui.SystemFactsDialog(self.stub_facts)
dialog.show()
enabled = dialog.update_button.get_property('sensitive')
self.assertFalse(enabled)
3
Example 15
Project: subscription-manager Source File: test_model_ent_cert.py
def _inj_mock_dirs(self, stub_product=None):
stub_product = stub_product or DefaultStubInstalledProduct()
mock_prod_dir = mock.NonCallableMock(name='MockProductDir')
mock_prod_dir.get_installed_products.return_value = [stub_product.id]
mock_prod_dir.get_provided_tags.return_value = stub_product.provided_tags
mock_content = create_mock_content(tags=['awesomeos-ostree-1'])
mock_cert_contents = [mock_content]
mock_ent_cert = mock.Mock(name='MockEntCert')
mock_ent_cert.products = [stub_product]
mock_ent_cert.content = mock_cert_contents
mock_ent_dir = mock.NonCallableMock(name='MockEntDir')
mock_ent_dir.list_valid.return_value = [mock_ent_cert]
inj.provide(inj.PROD_DIR, mock_prod_dir)
inj.provide(inj.ENT_DIR, mock_ent_dir)
3
Example 16
def setUp(self):
SubManFixture.setUp(self)
self.status = json.loads(INST_PROD_STATUS)['installedProducts']
self.prod_status_cache = NonCallableMock()
self.prod_status_cache.load_status = Mock(return_value=self.status)
inj.provide(inj.PROD_STATUS_CACHE, self.prod_status_cache)
self.calculator = ValidProductDateRangeCalculator(None)
3
Example 17
Project: subscription-manager Source File: test_validity.py
def test_unregistered(self):
id_mock = NonCallableMock()
id_mock.is_valid.return_value = False
inj.provide(inj.IDENTITY, id_mock)
self.calculator = ValidProductDateRangeCalculator(None)
for pid in (INST_PID_1, INST_PID_2, INST_PID_3):
self.assertTrue(self.calculator.calculate(pid) is None)
3
Example 18
Project: cgstudiomap Source File: testcallable.py
def test_attributes(self):
one = NonCallableMock()
self.assertTrue(issubclass(type(one.one), Mock))
two = NonCallableMagicMock()
self.assertTrue(issubclass(type(two.two), MagicMock))
3
Example 19
def test_attribute_deletion(self):
for mock in (Mock(), MagicMock(), NonCallableMagicMock(),
NonCallableMock()):
self.assertTrue(hasattr(mock, 'm'))
del mock.m
self.assertFalse(hasattr(mock, 'm'))
del mock.f
self.assertFalse(hasattr(mock, 'f'))
self.assertRaises(AttributeError, getattr, mock, 'f')
3
Example 20
def _mock_response(self):
response = NonCallableMock()
response._headers = {}
response.status_code = 200
response.queries = []
response.get = response._headers.get
response.content = ''
return response
3
Example 21
Project: silk Source File: test_execute_sql.py
def mock_sql():
mock_sql_query = Mock(spec_set=['_execute_sql', 'query', 'as_sql'])
mock_sql_query._execute_sql = Mock()
mock_sql_query.query = NonCallableMock(spec_set=['model'])
mock_sql_query.query.model = Mock()
query_string = 'SELECT * from table_name'
mock_sql_query.as_sql = Mock(return_value=(query_string, ()))
return mock_sql_query, query_string
3
Example 22
Project: ec2-api Source File: test_apirequest.py
def setUp(self):
super(EC2RequesterTestCase, self).setUp()
self.controller = self.mock(
'ec2api.api.cloud.VpcCloudController').return_value
self.fake_context = mock.NonCallableMock(
request_id=context.generate_request_id())
3
Example 23
Project: ec2-api Source File: test_api_init.py
def setUp(self):
super(ApiInitTestCase, self).setUp()
self.controller = self.mock(
'ec2api.api.cloud.VpcCloudController').return_value
self.fake_context = mock.NonCallableMock(
request_id=context.generate_request_id())
ec2_request = apirequest.APIRequest('FakeAction', 'fake_v1',
{'Param': 'fake_param'})
self.environ = {'REQUEST_METHOD': 'FAKE',
'ec2.request': ec2_request,
'ec2api.context': self.fake_context}
self.request = wsgi.Request(self.environ)
self.application = api.Executor()
3
Example 24
Project: ec2-api Source File: test_db_api.py
def setUp(self):
super(DbApiTestCase, self).setUp()
self.context = mock.NonCallableMock(
project_id=fakes.random_os_id())
self.other_context = mock.NonCallableMock(
project_id=fakes.random_os_id())
3
Example 25
Project: ec2-api Source File: test_integrated_scenario.py
def assert_image_project(self, expected_project_id, image_id):
if expected_project_id:
context = mock.NonCallableMock(project_id=expected_project_id)
else:
context = self.context
image_item = db_api.get_item_by_id(context, image_id)
if expected_project_id:
self.assertIsNotNone(image_item)
else:
self.assertIsNone(image_item)
3
Example 26
Project: networking-odl Source File: test_networking_topology.py
def mock_client(self, topology_name=None):
mocked_client = mock.NonCallableMock(
specs=network_topology.NetworkTopologyClient)
if topology_name:
cached_file_path = path.join(path.dirname(__file__), topology_name)
with open(cached_file_path, 'rt') as fd:
topology = jsonutils.loads(str(fd.read()), encoding='utf-8')
mocked_client.get().json.return_value = topology
return mocked_client
0
Example 27
Project: subscription-manager Source File: fixture.py
def setUp(self):
self.addCleanup(patch.stopall)
# Never attempt to use the actual managercli.cfg which points to a
# real file in etc.
cfg_patcher = patch.object(subscription_manager.managercli, 'cfg', new=stubs.config.CFG)
self.mock_cfg = cfg_patcher.start()
# By default mock that we are registered. Individual test cases
# can override if they are testing disconnected scenario.
id_mock = NonCallableMock(name='FixtureIdentityMock')
id_mock.exists_and_valid = Mock(return_value=True)
id_mock.uuid = 'fixture_identity_mock_uuid'
id_mock.name = 'fixture_identity_mock_name'
id_mock.cert_dir_path = "/not/a/real/path/to/pki/consumer/"
id_mock.keypath.return_value = "/not/a/real/key/path"
id_mock.certpath.return_value = "/not/a/real/cert/path"
# Don't really care about date ranges here:
self.mock_calc = NonCallableMock()
self.mock_calc.calculate.return_value = None
# Avoid trying to read real /etc/yum.repos.d/redhat.repo
self.mock_repofile_path_exists_patcher = patch('subscription_manager.repolib.RepoFile.path_exists')
mock_repofile_path_exists = self.mock_repofile_path_exists_patcher.start()
mock_repofile_path_exists.return_value = True
inj.provide(inj.IDENTITY, id_mock)
inj.provide(inj.PRODUCT_DATE_RANGE_CALCULATOR, self.mock_calc)
inj.provide(inj.ENTITLEMENT_STATUS_CACHE, stubs.StubEntitlementStatusCache())
inj.provide(inj.PROD_STATUS_CACHE, stubs.StubProductStatusCache())
inj.provide(inj.OVERRIDE_STATUS_CACHE, stubs.StubOverrideStatusCache())
inj.provide(inj.RELEASE_STATUS_CACHE, stubs.StubReleaseStatusCache())
inj.provide(inj.PROFILE_MANAGER, stubs.StubProfileManager())
# By default set up an empty stub entitlement and product dir.
# Tests need to modify or create their own but nothing should hit
# the system.
self.ent_dir = stubs.StubEntitlementDirectory()
inj.provide(inj.ENT_DIR, self.ent_dir)
self.prod_dir = stubs.StubProductDirectory()
inj.provide(inj.PROD_DIR, self.prod_dir)
# Installed products manager needs PROD_DIR injected first
inj.provide(inj.INSTALLED_PRODUCTS_MANAGER, stubs.StubInstalledProductsManager())
self.stub_cp_provider = stubs.StubCPProvider()
self._release_versions = []
self.stub_cp_provider.content_connection.get_versions = self._get_release_versions
inj.provide(inj.CP_PROVIDER, self.stub_cp_provider)
inj.provide(inj.CERT_SORTER, stubs.StubCertSorter())
# setup and mock the plugin_manager
plugin_manager_mock = MagicMock(name='FixturePluginManagerMock')
plugin_manager_mock.runiter.return_value = iter([])
inj.provide(inj.PLUGIN_MANAGER, plugin_manager_mock)
inj.provide(inj.DBUS_IFACE, Mock(name='FixtureDbusIfaceMock'))
pooltype_cache = Mock()
inj.provide(inj.POOLTYPE_CACHE, pooltype_cache)
# don't use file based locks for tests
inj.provide(inj.ACTION_LOCK, RLock)
self.stub_facts = stubs.StubFacts()
inj.provide(inj.FACTS, self.stub_facts)
self.dbus_patcher = patch('subscription_manager.managercli.CliCommand._request_validity_check')
self.dbus_patcher.start()
# No tests should be trying to connect to any configure or test server
# so really, everything needs this mock. May need to be in __init__, or
# better, all test classes need to use SubManFixture
self.is_valid_server_patcher = patch("subscription_manager.managercli.is_valid_server_info")
is_valid_server_mock = self.is_valid_server_patcher.start()
is_valid_server_mock.return_value = True
# No tests should be trying to test the proxy connection
# so really, everything needs this mock. May need to be in __init__, or
# better, all test classes need to use SubManFixture
self.test_proxy_connection_patcher = patch("subscription_manager.managercli.CliCommand.test_proxy_connection")
test_proxy_connection_mock = self.test_proxy_connection_patcher.start()
test_proxy_connection_mock.return_value = True
self.files_to_cleanup = []
0
Example 28
Project: subscription-manager Source File: test_entbranding.py
def test(self):
stub_product = DefaultStubProduct()
stub_installed_product = DefaultStubInstalledProduct()
mock_prod_dir = mock.NonCallableMock(name='MockProductDir')
mock_prod_dir.get_installed_products.return_value = [stub_installed_product.id]
inj.provide(inj.PROD_DIR, mock_prod_dir)
mock_ent_cert = mock.Mock(name='MockEntCert')
mock_ent_cert.products = [stub_product]
self._inj_mock_ent_dir([mock_ent_cert])
brand_installer = self.brand_installer_class()
brand_installer.install()
self.assertTrue(self.mock_install.called)
call_args = self.mock_install.call_args
brand_arg = call_args[0][0]
self.assertTrue(isinstance(brand_arg, entbranding.ProductBrand))
self.assertTrue(isinstance(brand_arg, rhelentbranding.RHELProductBrand))
self.assertEquals('Awesome OS super', brand_arg.name)
0
Example 29
Project: subscription-manager Source File: test_entbranding.py
def test_no_need_to_update_branding(self):
stub_product = StubProduct(id=123, brand_type='OS',
name="Some name",
brand_name=self.current_brand)
stub_installed_product = StubProduct(id=123, name="Some name")
mock_prod_dir = mock.NonCallableMock(name='MockProductDir')
mock_prod_dir.get_installed_products.return_value = [stub_installed_product.id]
inj.provide(inj.PROD_DIR, mock_prod_dir)
mock_ent_cert = mock.Mock(name='MockEntCert')
mock_ent_cert.products = [stub_product]
self._inj_mock_ent_dir([mock_ent_cert])
brand_installer = self.brand_installer_class()
brand_installer.install()
self.assertFalse(self.mock_install.called)
0
Example 30
Project: subscription-manager Source File: test_entbranding.py
def test_no_brand_type_on_product(self):
# no brand_type
stub_product = StubProduct(id=123, name="Awesome OS Super")
stub_installed_product = StubProduct(id=123, name="Awesome OS Super")
# simulate a old style Product, shouldn't happen
del stub_product.brand_type
mock_prod_dir = mock.NonCallableMock(name='MockProductDir')
mock_prod_dir.get_installed_products.return_value = [stub_installed_product.id]
inj.provide(inj.PROD_DIR, mock_prod_dir)
mock_ent_cert = mock.Mock(name='MockEntCert')
mock_ent_cert.products = [stub_product]
self._inj_mock_ent_dir([mock_ent_cert])
brand_installer = self.brand_installer_class()
brand_installer.install()
self.assertFalse(self.mock_install.called)
0
Example 31
Project: subscription-manager Source File: test_entbranding.py
def test_none_product_name_none_brand_name_on_product(self):
# can't create a certificate2.Product without a name
# so create it with and undo it. This should never happen
stub_product = StubProduct(name="placeholder", id=123, brand_type='OS')
stub_product.name = None
stub_product.brand_name = None
stub_installed_product = StubProduct(name="placeholder", id=123)
mock_prod_dir = mock.NonCallableMock(name='MockProductDir')
mock_prod_dir.get_installed_products.return_value = [stub_installed_product.id]
mock_ent_cert = mock.Mock(name='MockEntCert')
mock_ent_cert.products = [stub_product]
self._inj_mock_ent_dir([mock_ent_cert])
brand_installer = self.brand_installer_class()
brand_installer.install()
self.assertFalse(self.mock_install.called)
0
Example 32
Project: subscription-manager Source File: test_entbranding.py
def test_multiple_matching_branded_products(self):
stub_product = DefaultStubProduct()
stub_installed_product = DefaultStubInstalledProduct()
stub_product_2 = StubProduct(id=321, brand_type='OS', name="Awesome",
brand_name="Slightly Different Awesome OS Super")
stub_installed_product_2 = StubProduct(id=321, name="Awesome")
mock_prod_dir = mock.NonCallableMock(name='MockProductDir')
mock_prod_dir.get_installed_products.return_value = [stub_installed_product.id,
stub_installed_product_2.id]
inj.provide(inj.PROD_DIR, mock_prod_dir)
mock_ent_cert = mock.Mock(name='MockEntCert')
mock_ent_cert.products = [stub_product, stub_product_2]
brand_installer = self.brand_installer_class([mock_ent_cert])
brand_installer.install()
# we give up in this case and leave things as is
self.assertFalse(self.mock_install.called)
0
Example 33
Project: subscription-manager Source File: test_entbranding.py
def test(self):
stub_product = DefaultStubProduct()
mock_prod_dir = mock.NonCallableMock(name='MockProductDir')
mock_prod_dir.get_installed_products.return_value = [stub_product.id]
inj.provide(inj.PROD_DIR, mock_prod_dir)
mock_ent_cert = mock.Mock(name='MockEntCert')
mock_ent_cert.products = [stub_product]
brand_installer = self.brand_installer_class([mock_ent_cert])
brand_installer.install()
self.assertTrue(self.mock_install.called)
call_args = self.mock_install.call_args
brand_arg = call_args[0][0]
self.assertTrue(isinstance(brand_arg, entbranding.ProductBrand))
self.assertTrue(isinstance(brand_arg, rhelentbranding.RHELProductBrand))
self.assertEquals("Awesome OS super", brand_arg.name)
# verify the install on all the installers got called
count = 0
for bi in brand_installer.brand_installers:
if isinstance(bi, mock.Mock):
self.assertTrue(bi.install.called)
count = count + 1
self.assertEquals(2, count)
0
Example 34
Project: subscription-manager Source File: test_entbranding.py
def test_get_brand_multiple_ents_with_branding_same_name(self):
# inj a prod dir with some installed products
stub_product = DefaultStubProduct()
stub_product_2 = DefaultStubProduct()
mock_product_dir = mock.NonCallableMock()
mock_product_dir.get_installed_products.return_value = [stub_product.id]
inj.provide(inj.PROD_DIR, mock_product_dir)
mock_ent_cert = mock.Mock()
mock_ent_cert.products = [stub_product]
mock_ent_cert_2 = mock.Mock()
mock_ent_cert_2.products = [stub_product_2]
ent_certs = [mock_ent_cert, mock_ent_cert_2]
brand_picker = rhelentbranding.RHELBrandPicker(ent_certs)
brand = brand_picker.get_brand()
self.assertTrue(brand is not None)
self.assertTrue("Awesome OS", brand.name)
0
Example 35
Project: subscription-manager Source File: test_entbranding.py
def test_get_brand_multiple_ents_with_branding_different_branded_name(self):
# inj a prod dir with some installed products
stub_product = DefaultStubProduct()
# same product id, different name
stub_product_2 = StubProduct(id=123, brand_type='OS',
name='A Different Stub Product',
brand_name='A Different branded Stub Product')
mock_product_dir = mock.NonCallableMock()
# note stub_product.id=123 will match the Product from both ents
mock_product_dir.get_installed_products.return_value = [stub_product.id]
inj.provide(inj.PROD_DIR, mock_product_dir)
mock_ent_cert = mock.Mock()
mock_ent_cert.products = [stub_product]
mock_ent_cert_2 = mock.Mock()
mock_ent_cert_2.products = [stub_product_2]
ent_certs = [mock_ent_cert, mock_ent_cert_2]
brand_picker = rhelentbranding.RHELBrandPicker(ent_certs)
brand = brand_picker.get_brand()
self.assertTrue(brand is None)
0
Example 36
Project: subscription-manager Source File: test_entbranding.py
def test_get_brand_branded_unknown_brand_type(self):
stub_installed_product = StubProduct(id=123, name="Stub Product Name")
# note, no 'brand_type' attribute
other_stub_installed_product = StubProduct(id=321, name='A Non Branded Product')
mock_product_dir = mock.NonCallableMock()
mock_product_dir.get_installed_products.return_value = [stub_installed_product.id,
other_stub_installed_product.id]
inj.provide(inj.PROD_DIR, mock_product_dir)
stub_product = StubProduct(id=123, brand_type="middleware",
name="Stub Product Name", brand_name="Awesome Middleware")
mock_ent_cert = mock.Mock()
mock_ent_cert.products = [stub_product]
ent_certs = [mock_ent_cert]
# NOTE: this looks like a branded product, except the brand type is one
# the RHELBrandPicker doesn't know
brand_picker = rhelentbranding.RHELBrandPicker(ent_certs)
brand = brand_picker.get_brand()
self.assertTrue(brand is None)
0
Example 37
Project: subscription-manager Source File: test_registration.py
def _inject_ipm(self):
mock_ipm = NonCallableMock(spec=cache.InstalledProductsManager)
mock_ipm.tags = None
inj.provide(inj.INSTALLED_PRODUCTS_MANAGER, mock_ipm)
return mock_ipm
0
Example 38
Project: cgstudiomap Source File: testcallable.py
def test_non_callable(self):
for mock in NonCallableMagicMock(), NonCallableMock():
self.assertRaises(TypeError, mock)
self.assertFalse(hasattr(mock, '__call__'))
self.assertIn(mock.__class__.__name__, repr(mock))
0
Example 39
Project: cgstudiomap Source File: testmock.py
def test_assert_called_with_failure_message(self):
mock = NonCallableMock()
expected = "mock(1, '2', 3, bar='foo')"
message = 'Expected call: %s\nNot called'
self.assertRaisesWithMsg(
AssertionError, message % (expected,),
mock.assert_called_with, 1, '2', 3, bar='foo'
)
mock.foo(1, '2', 3, foo='foo')
asserters = [
mock.foo.assert_called_with, mock.foo.assert_called_once_with
]
for meth in asserters:
actual = "foo(1, '2', 3, foo='foo')"
expected = "foo(1, '2', 3, bar='foo')"
message = 'Expected call: %s\nActual call: %s'
self.assertRaisesWithMsg(
AssertionError, message % (expected, actual),
meth, 1, '2', 3, bar='foo'
)
# just kwargs
for meth in asserters:
actual = "foo(1, '2', 3, foo='foo')"
expected = "foo(bar='foo')"
message = 'Expected call: %s\nActual call: %s'
self.assertRaisesWithMsg(
AssertionError, message % (expected, actual),
meth, bar='foo'
)
# just args
for meth in asserters:
actual = "foo(1, '2', 3, foo='foo')"
expected = "foo(1, 2, 3)"
message = 'Expected call: %s\nActual call: %s'
self.assertRaisesWithMsg(
AssertionError, message % (expected, actual),
meth, 1, 2, 3
)
# empty
for meth in asserters:
actual = "foo(1, '2', 3, foo='foo')"
expected = "foo()"
message = 'Expected call: %s\nActual call: %s'
self.assertRaisesWithMsg(
AssertionError, message % (expected, actual), meth
)
0
Example 40
Project: cgstudiomap Source File: testmock.py
def test_arg_lists(self):
mocks = [
Mock(),
MagicMock(),
NonCallableMock(),
NonCallableMagicMock()
]
def assert_attrs(mock):
names = 'call_args_list', 'method_calls', 'mock_calls'
for name in names:
attr = getattr(mock, name)
self.assertIsInstance(attr, _CallList)
self.assertIsInstance(attr, list)
self.assertEqual(attr, [])
for mock in mocks:
assert_attrs(mock)
if callable(mock):
mock()
mock(1, 2)
mock(a=3)
mock.reset_mock()
assert_attrs(mock)
mock.foo()
mock.foo.bar(1, a=3)
mock.foo(1).bar().baz(3)
mock.reset_mock()
assert_attrs(mock)