def passes_with_StritMock_with_valid_template(self): self.assert_passes({ "StrictMock(template=int)": ( "str", StrictMock(template=int), ) })
def fails_with_StritMock_with_invalid_template(self): self.assert_fails({ "StrictMock(template=dict)": ( "str", StrictMock(template=dict), ) })
def with_a_patched_runtime_attr(context): context.memoize( "target", lambda self: StrictMock(template=sample_module.SomeClass, runtime_attrs=["runtime_attr"]), ) context.memoize("attribute", lambda self: "runtime_attr") context.merge_context("patching works")
def passes_with_StritMock_without_template(self): self.assert_passes( { "StrictMock": ( "str", StrictMock(), ) } )
def setUp(self): super().setUp() self.clusters = [fxt.get_anymarkup("cluster1.yml")] self.clusters[0]["ocm"]["name"] = "ocm-nonexisting" self.clusters[0]["path"] = "/openshift/mycluster/cluster.yml" self.mock_callable( queries, "get_app_interface_settings").for_call().to_return_value( {}).and_assert_called_once() self.get_clusters = (self.mock_callable( queries, "get_clusters").for_call().to_return_value( self.clusters).and_assert_called_once()) self.ocmmap = StrictMock(ocmmod.OCMMap) self.ocm = StrictMock(ocmmod.OCM) self.mock_constructor(ocmmod, "OCMMap").to_return_value(self.ocmmap) self.mock_callable( self.ocmmap, "get").for_call("cluster1").to_return_value(self.ocm) self.update_cluster = self.mock_callable( self.ocm, "update_cluster").to_return_value(None) self.mock_callable(sys, "exit").to_raise(ValueError) self.addCleanup(mock_callable.unpatch_all_callable_mocks)
def setUp(self): super().setUp() self.clusters = [fxt.get_anymarkup('cluster1.yml')] self.clusters[0]['ocm']['name'] = 'ocm-nonexisting' self.clusters[0]['path'] = '/openshift/mycluster/cluster.yml' self.mock_callable( queries, 'get_app_interface_settings' ).for_call().to_return_value({}).and_assert_called_once() self.get_clusters = self.mock_callable( queries, 'get_clusters' ).for_call().to_return_value(self.clusters).and_assert_called_once() self.ocmmap = StrictMock(ocmmod.OCMMap) self.ocm = StrictMock(ocmmod.OCM) self.mock_constructor(ocmmod, 'OCMMap').to_return_value(self.ocmmap) self.mock_callable( self.ocmmap, 'get' ).for_call('cluster1').to_return_value(self.ocm) self.update_cluster = self.mock_callable( self.ocm, 'update_cluster' ).to_return_value(None) self.mock_callable( sys, 'exit' ).to_raise(ValueError) self.addCleanup(mock_callable.unpatch_all_callable_mocks)
def test_non_set_disable_uwm(self): current = { 'cluster1': { 'spec': self.clusters[0]['spec'], 'network': self.clusters[0]['network'], 'consoleUrl': 'aconsoleurl', 'serverUrl': 'aserverurl', 'elbFQDN': 'anelbfqdn', 'prometheusUrl': 'aprometheusurl', 'alertmanagerUrl': 'analertmanagerurl', } } self.clusters[0]['spec']['id'] = 'id' self.clusters[0]['spec']['external_id'] = 'ext_id' desired = deepcopy(current) self.clusters[0]['spec'][ocmmod.DISABLE_UWM_ATTR] = True self.mock_callable(occ, 'fetch_desired_state').to_return_value( desired ).and_assert_called_once() self.mock_callable(occ.mr_client_gateway, 'init').for_call( gitlab_project_id=None ).to_return_value('not a value').and_assert_called_once() self.mock_callable( self.ocmmap, 'cluster_specs' ).for_call().to_return_value((current, {})).and_assert_called_once() create_clusters_updates = StrictMock( clusters_updates.CreateClustersUpdates ) self.mock_constructor( clusters_updates, 'CreateClustersUpdates' ).to_return_value(create_clusters_updates) self.mock_callable( create_clusters_updates, 'submit' ).for_call(cli='not a value').to_return_value( None).and_assert_called_once() with self.assertRaises(ValueError) as e: occ.run(False) self.assertEqual(e.args, (0, ))
def passes_without_template(self): strict_mock = StrictMock() self.assert_passes(strict_mock, "arg2", kwarg1="kwarg1", kwarg2="kwarg2") self.assert_passes("arg1", strict_mock, kwarg1="kwarg1", kwarg2="kwarg2") self.assert_passes("arg1", "arg2", kwarg1=strict_mock, kwarg2="kwarg2") self.assert_passes("arg1", "arg2", kwarg1="kwarg1", kwarg2=strict_mock)
def fails_with_invalid_template(self): strict_mock = StrictMock(template=int) self.assert_fails(strict_mock, "arg2", kwarg1="kwarg1", kwarg2="kwarg2") self.assert_fails("arg1", strict_mock, kwarg1="kwarg1", kwarg2="kwarg2") self.assert_fails("arg1", "arg2", kwarg1=strict_mock, kwarg2="kwarg2") self.assert_fails("arg1", "arg2", kwarg1="kwarg1", kwarg2=strict_mock)
def test_non_set_disable_uwm(self): current = { "cluster1": { "spec": self.clusters[0]["spec"], "network": self.clusters[0]["network"], "consoleUrl": "aconsoleurl", "serverUrl": "aserverurl", "elbFQDN": "anelbfqdn", "prometheusUrl": "aprometheusurl", "alertmanagerUrl": "analertmanagerurl", } } self.clusters[0]["spec"]["id"] = "id" self.clusters[0]["spec"]["external_id"] = "ext_id" desired = deepcopy(current) self.clusters[0]["spec"][ocmmod.DISABLE_UWM_ATTR] = True self.mock_callable(occ, "fetch_desired_state").to_return_value( desired).and_assert_called_once() self.mock_callable( occ.mr_client_gateway, "init").for_call(gitlab_project_id=None).to_return_value( "not a value").and_assert_called_once() self.mock_callable(self.ocmmap, "cluster_specs").for_call().to_return_value( (current, {})).and_assert_called_once() create_clusters_updates = StrictMock( clusters_updates.CreateClustersUpdates) self.mock_constructor( clusters_updates, "CreateClustersUpdates").to_return_value(create_clusters_updates) self.mock_callable(create_clusters_updates, "submit").for_call( cli="not a value").to_return_value(None).and_assert_called_once() with self.assertRaises(ValueError) as e: occ.run(False) self.assertEqual(e.args, (0, ))
def without_a_template(context): context.memoize("target", lambda self: StrictMock()) context.merge_context("patching works")
def with_a_template(context): context.memoize( "target", lambda self: StrictMock(template=sample_module.SomeClass)) context.merge_context("common", fails_if_class_attribute=False)
def fails_for_mock_with_wrong_template(self): self.assert_fails(StrictMock(template=int))
def passes_for_mock_with_correct_template(self): self.assert_passes(StrictMock(template=str))
def passes_for_mock_without_template(self): self.assert_passes(StrictMock())
def _get_fake_path(self, file_name): fake_path = StrictMock(Path, runtime_attrs=["name"]) fake_path.name = file_name return fake_path
def passes_with_StritMock_with_valid_template(self): self.assert_passes( {"StrictMock(template=str)": StrictMock(template=str)})