def test_create_cluster_deploy(self):
        """
        Verify create_cluster_deploy creates a new deploy record.
        """
        bus = mock.MagicMock()
        bus.request.return_value = create_jsonrpc_response(
            ID, CLUSTER_DEPLOY.to_dict())

        self.assertEquals(
            create_jsonrpc_response(ID, CLUSTER_DEPLOY.to_dict()),
            operations.create_cluster_deploy.handler(SIMPLE_DEPLOY_REQUEST,
                                                     bus))
    def test_create_cluster_operation(self):
        """
        Verify create_cluster_operation creates a new record.
        """
        for model_instance, request in [
            (CLUSTER_UPGRADE, SIMPLE_UPGRADE_REQUEST),
            (CLUSTER_RESTART, SIMPLE_RESTART_REQUEST)
        ]:

            bus = mock.MagicMock()
            bus.request.return_value = create_jsonrpc_response(
                ID, model_instance.to_dict())

            self.assertEquals(
                create_jsonrpc_response(ID, model_instance.to_dict()),
                operations.create_cluster_operation(model_instance.__class__,
                                                    request, bus,
                                                    'phony_routing_key'))
    def test_get_cluster_deploy(self):
        """
        Verify get_cluster_deploy responds with the right information.
        """
        bus = mock.MagicMock()
        bus.storage.get.return_value = CLUSTER_DEPLOY

        self.assertEquals(
            create_jsonrpc_response(ID, CLUSTER_DEPLOY.to_dict()),
            operations.get_cluster_deploy.handler(SIMPLE_DEPLOY_REQUEST, bus))
    def test_create_cluster_deploy_with_invalid_data(self):
        """
        Verify create_cluster_deploy responds with an error when invalid data is given.
        """
        bus = mock.MagicMock()
        bus.request.return_value = create_jsonrpc_response(
            ID, BAD_CLUSTER_DEPLOY.to_dict())

        self.assertEquals(
            expected_error(ID, JSONRPC_ERRORS['INVALID_PARAMETERS']),
            operations.create_cluster_deploy.handler(BAD_DEPLOY_REQUEST, bus))
    def test_create_cluster_operation_with_invalid_data(self):
        """
        Verify create_cluster_operation responds with an error when invalid data is given.
        """
        for model_instance in (CLUSTER_UPGRADE, CLUSTER_RESTART):
            bus = mock.MagicMock()
            bus.request.return_value = create_jsonrpc_response(ID, {})

            self.assertEquals(
                expected_error(ID, JSONRPC_ERRORS['INVALID_REQUEST']),
                operations.create_cluster_operation(model_instance.__class__,
                                                    BAD_CLUSTER_OPERATION, bus,
                                                    'phony_routing_key'))
 def test_get_cluster_operation(self):
     """
     Verify get_cluster_operation responds with the right information.
     """
     for model_instance, request in [
         (CLUSTER_UPGRADE, SIMPLE_UPGRADE_REQUEST),
         (CLUSTER_RESTART, SIMPLE_RESTART_REQUEST)
     ]:
         bus = mock.MagicMock()
         bus.storage.get.return_value = model_instance
         self.assertEquals(
             create_jsonrpc_response(ID, model_instance.to_dict()),
             operations.get_cluster_operation(model_instance.__class__,
                                              request, bus))