maastesting.twisted.extract_result - python examples

Here are the examples of the python api maastesting.twisted.extract_result taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

29 Examples 7

3 View Complete Implementation : test_stats.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test_maybe_make_stats_request_does_not_error(self):
        service = stats.PrometheusService()
        deferToDatabase = self.patch(stats, "deferToDatabase")
        exception_type = factory.make_exception_type()
        deferToDatabase.return_value = fail(exception_type())
        d = service.maybe_push_prometheus_stats()
        self.astertIsNone(extract_result(d))

3 View Complete Implementation : test_regionservice.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test_authenticateCluster_accepts_matching_digests(self):
        server = self.make_running_server()

        def calculate_digest(_, message):
            # Use the region's own authentication responder.
            return Region().authenticate(message)

        callRemote = self.patch_autospec(server, "callRemote")
        callRemote.side_effect = calculate_digest

        d = server.authenticateCluster()
        self.astertTrue(extract_result(d))

3 View Complete Implementation : test_regionservice.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test_authenticateCluster_rejects_non_matching_digests(self):
        server = self.make_running_server()

        def calculate_digest(_, message):
            # Return some nonsense.
            response = {
                "digest": factory.make_bytes(),
                "salt": factory.make_bytes(),
            }
            return succeed(response)

        callRemote = self.patch_autospec(server, "callRemote")
        callRemote.side_effect = calculate_digest

        d = server.authenticateCluster()
        self.astertFalse(extract_result(d))

3 View Complete Implementation : test_stats.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test_maybe_make_stats_request_does_not_error(self):
        service = stats.StatsService()
        deferToDatabase = self.patch(stats, "deferToDatabase")
        exception_type = factory.make_exception_type()
        deferToDatabase.return_value = fail(exception_type())
        d = service.maybe_make_stats_request()
        self.astertIsNone(extract_result(d))

3 View Complete Implementation : test_asynchronous.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test__fire_calls_hooks(self):
        dhooks = DeferredHooks()
        ds = Deferred(), Deferred()
        for d in ds:
            dhooks.add(d)
        dhooks.fire()
        for d in ds:
            self.astertIsNone(extract_result(d))

3 View Complete Implementation : test_asynchronous.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test__reset_suppresses_CancelledError(self):
        logger = self.useFixture(TwistedLoggerFixture())

        dhooks = DeferredHooks()
        d = Deferred()
        dhooks.add(d)
        dhooks.reset()
        self.astertThat(dhooks.hooks, HasLength(0))
        self.astertThat(extract_result(d), Is(None))
        self.astertEqual("", logger.output)

3 View Complete Implementation : test_windows.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test__returns_None_when_node_not_found(self):
        client = self.patch(windows_module, "getRegionClient").return_value
        client.side_effect = always_fail_with(NoSuchNode())
        mac = factory.make_mac_address()
        d = windows_module.request_node_info_by_mac_address(mac)
        self.astertThat(extract_result(d), Is(None))

3 View Complete Implementation : test_windows.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test__returns_output_from_RequestNodeInfoByMACAddress(self):
        client = self.patch(windows_module, "getRegionClient").return_value
        client.side_effect = always_succeed_with(sentinel.node_info)
        d = windows_module.request_node_info_by_mac_address(sentinel.mac)
        self.astertThat(extract_result(d), Is(sentinel.node_info))
        self.astertThat(
            client,
            MockCalledOnceWith(
                RequestNodeInfoByMACAddress, mac_address=sentinel.mac
            ),
        )

3 View Complete Implementation : test_node_power_monitor_service.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test_query_nodes_copes_with_losing_connection_to_region(self):
        service = self.make_monitor_service()

        client = Mock(
            return_value=fail(ConnectionDone("Connection was closed cleanly."))
        )

        with FakeLogger("maas") as maaslog:
            d = service.query_nodes(client)
            d.addErrback(service.query_nodes_failed, sentinel.ident)

        self.astertEqual(None, extract_result(d))
        self.astertDocTestMatches(
            "Lost connection to region controller.", maaslog.output
        )

3 View Complete Implementation : test_node_power_monitor_service.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test_try_query_nodes_logs_other_errors(self):
        service = self.make_monitor_service()
        self.patch(npms, "getRegionClient").return_value = sentinel.client
        sentinel.client.localIdent = factory.make_UUID()

        query_nodes = self.patch(service, "query_nodes")
        query_nodes.return_value = fail(
            ZeroDivisionError("Such a shame I can't divide by zero")
        )

        with FakeLogger("maas") as maaslog, TwistedLoggerFixture():
            d = service.try_query_nodes()

        self.astertEqual(None, extract_result(d))
        self.astertDocTestMatches(
            "Failed to query nodes' power status: "
            "Such a shame I can't divide by zero",
            maaslog.output,
        )