Пример #1
0
 def passes_with_StritMock_with_valid_template(self):
     self.assert_passes({
         "StrictMock(template=int)": (
             "str",
             StrictMock(template=int),
         )
     })
Пример #2
0
 def fails_with_StritMock_with_invalid_template(self):
     self.assert_fails({
         "StrictMock(template=dict)": (
             "str",
             StrictMock(template=dict),
         )
     })
Пример #3
0
 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")
Пример #4
0
 def passes_with_StritMock_without_template(self):
     self.assert_passes(
         {
             "StrictMock": (
                 "str",
                 StrictMock(),
             )
         }
     )
Пример #5
0
 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)
Пример #6
0
 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)
Пример #7
0
    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, ))
Пример #8
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)
Пример #9
0
 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)
Пример #10
0
    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, ))
Пример #11
0
 def without_a_template(context):
     context.memoize("target", lambda self: StrictMock())
     context.merge_context("patching works")
Пример #12
0
        def with_a_template(context):
            context.memoize(
                "target",
                lambda self: StrictMock(template=sample_module.SomeClass))

            context.merge_context("common", fails_if_class_attribute=False)
Пример #13
0
 def fails_for_mock_with_wrong_template(self):
     self.assert_fails(StrictMock(template=int))
Пример #14
0
 def passes_for_mock_with_correct_template(self):
     self.assert_passes(StrictMock(template=str))
Пример #15
0
 def passes_for_mock_without_template(self):
     self.assert_passes(StrictMock())
Пример #16
0
 def _get_fake_path(self, file_name):
     fake_path = StrictMock(Path, runtime_attrs=["name"])
     fake_path.name = file_name
     return fake_path
Пример #17
0
 def passes_with_StritMock_with_valid_template(self):
     self.assert_passes(
         {"StrictMock(template=str)": StrictMock(template=str)})