def test_attach_subscription_task_success(self, environ_get):
     """Test the ParseAttachedSubscriptionsTask."""
     # prepare mock proxies the task is expected to interact with
     rhsm_entitlement_proxy = Mock()
     rhsm_entitlement_proxy.GetPools.return_value = "foo"
     rhsm_syspurpose_proxy = Mock()
     rhsm_syspurpose_proxy.GetSyspurpose.return_value = "bar"
     task = ParseAttachedSubscriptionsTask(
         rhsm_entitlement_proxy=rhsm_entitlement_proxy,
         rhsm_syspurpose_proxy=rhsm_syspurpose_proxy)
     # mock the parsing methods
     subscription1 = AttachedSubscription()
     subscription2 = AttachedSubscription()
     task._parse_subscription_json = Mock()
     task._parse_subscription_json.return_value = [
         subscription1, subscription2
     ]
     system_purpose_data = SystemPurposeData()
     task._parse_system_purpose_json = Mock()
     task._parse_system_purpose_json.return_value = system_purpose_data
     # run the task
     result = task.run()
     # check DBus proxies were called as expected
     rhsm_entitlement_proxy.GetPools.assert_called_once_with(
         {'pool_subsets': get_variant(Str, "consumed")}, {}, "en_US.UTF-8")
     rhsm_syspurpose_proxy.GetSyspurpose.assert_called_once_with(
         "en_US.UTF-8")
     # check the parsing methods were called
     task._parse_subscription_json.assert_called_once_with("foo")
     task._parse_system_purpose_json.assert_called_once_with("bar")
     # check the result that has been returned is as expected
     self.assertEqual(result.attached_subscriptions,
                      [subscription1, subscription2])
     self.assertEqual(result.system_purpose_data, system_purpose_data)
    def parse_attached_subscriptions_with_task(self):
        """Parse attached subscriptions with task.

        Parse data about attached subscriptions and final system purpose data.
        This data is available as JSON strings via the RHSM DBus API.

        :return: a DBus path of an installation task
        """
        rhsm_entitlement_proxy = self.rhsm_observer.get_proxy(RHSM_ENTITLEMENT)
        rhsm_syspurpose_proxy = self.rhsm_observer.get_proxy(RHSM_SYSPURPOSE)
        task = ParseAttachedSubscriptionsTask(
            rhsm_entitlement_proxy=rhsm_entitlement_proxy,
            rhsm_syspurpose_proxy=rhsm_syspurpose_proxy)
        # if the task succeeds, set attached subscriptions and system purpose data
        task.succeeded_signal.connect(
            lambda: self._set_system_subscription_data(task.get_result()))
        return task