requests.request_exceptions.RequestException

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

7 Examples 7

Example 1

Project: barbican
Source File: test_dogtag.py
View license
    def test_issue_return_ca_unavailable(self):
        order_meta = {
            dogtag_import.DogtagCAPlugin.PROFILE_ID: self.approved_profile_id}
        plugin_meta = {}

        self.certclient_mock.enroll_cert.side_effect = (
            request_exceptions.RequestException())

        result_dto = self.plugin.issue_certificate_request(
            self.order_id, order_meta, plugin_meta, self.barbican_meta_dto)

        self.certclient_mock.enroll_cert.assert_called_once_with(
            self.approved_profile_id,
            order_meta)

        self.assertEqual(cm.CertificateStatus.CA_UNAVAILABLE_FOR_REQUEST,
                         result_dto.status,
                         "result_dto status incorrect")

Example 2

Project: barbican
Source File: test_dogtag.py
View license
    def test_cancel_ca_unavailable(self):
        order_meta = mock.ANY
        plugin_meta = {dogtag_import.DogtagCAPlugin.REQUEST_ID:
                       self.request_id_mock}
        self.certclient_mock.review_request.side_effect = (
            request_exceptions.RequestException("request_exception"))

        result_dto = self.plugin.cancel_certificate_request(
            self.order_id, order_meta, plugin_meta, self.barbican_meta_dto)

        self.assertEqual(cm.CertificateStatus.CA_UNAVAILABLE_FOR_REQUEST,
                         result_dto.status,
                         "result_dto_status incorrect")

Example 3

Project: barbican
Source File: test_dogtag.py
View license
    def test_modify_ca_unavailable(self):
        order_meta = mock.ANY
        plugin_meta = {dogtag_import.DogtagCAPlugin.REQUEST_ID:
                       self.request_id_mock}
        self.certclient_mock.review_request.side_effect = (
            request_exceptions.RequestException("request_exception"))

        result_dto = self.plugin.modify_certificate_request(
            self.order_id, order_meta, plugin_meta, self.barbican_meta_dto)

        self.assertEqual(cm.CertificateStatus.CA_UNAVAILABLE_FOR_REQUEST,
                         result_dto.status,
                         "result_dto_status incorrect")

Example 4

Project: barbican
Source File: symantec.py
View license
def _ca_create_order(self, order_meta, plugin_meta):
    """Creates an order with the Symantec CA.

    The PartnerOrderId and GeoTrustOrderId are returned and stored in
    plugin_meta. PartnerCode and ProductCode are also stored in plugin_meta
    for future use.

    All required order parameters must be stored as a dict in
    order_meta.
    Required fields are:
    PartnerCode, ProductCode, PartnerOrderId, OrganizationName,
    AddressLine1, City, Region, PostalCode, Country, OrganizationPhone
    ValidityPeriod, ServerCount, WebServerType, AdminContactFirstName,
    AdminContactLastName, AdminContactPhone, AdminContactEmail,
    AdminContactTitle, AdminContactAddressLine1, AdminContactCity,
    AdminContactRegion, AdminContactPostalCode, AdminContactCountry,
    BillingContact*,  TechContact*, and CSR.

    *The Billing and Tech contact information follows the same convention
    as the AdminContact fields.

    Optional Parameters: TechSameAsAdmin, BillSameAsAdmin, more options can be
    found in Symantec's API docs. Contact Symantec for the API document.

    :returns: tuple with success, error message, and can retry
    """

    api = Symantec(self.username, self.password, self.url)

    try:
        order_data = api.order(**order_meta)

        # GeotrustOrderId is used to handle emails from Symantec.
        # PartnerCode and ProductCode are being stored in plugin_meta for
        # convenience when calling _ca_get_order_status, _ca_modify_order, etc.
        plugin_meta["GeotrustOrderID"] = order_data["GeotrustOrderID"]
        plugin_meta["PartnerOrderID"] = order_data["PartnerOrderID"]
        plugin_meta["PartnerCode"] = order_meta["OrderDetails"]["PartnerCode"]
        plugin_meta["ProductCode"] = order_meta["OrderDetails"]["ProductCode"]
        return True, None, False
    except symantec_exceptions.SymantecError as e:
        return False, e, False
    except request_exceptions.RequestException as e:
        return False, e, True

Example 5

Project: barbican
Source File: symantec.py
View license
def _ca_get_order_status(self, plugin_meta):
    """Sends a request to the Symantec CA for details on an order.

    Parameters needed for GetOrderByPartnerOrderID:
    plugin_meta parameters: PartnerOrderId, PartnerCode

    If the order is complete, the Certificate is returned as a string.
    returns: tuple with success, error message, can retry,
             and the certificate (if available).
    """
    api = Symantec(self.username, self.password, self.url)

    order_details = {
        "PartnerOrderID": plugin_meta["PartnerOrderID"],
        "PartnerCode": plugin_meta["PartnerCode"],
        "ReturnCertificateInfo": "TRUE",
        "ReturnFulfillment": "TRUE",
        "ReturnCaCerts": "TRUE",
    }

    try:
        order_data = api.get_order_by_partner_order_id(**order_details)
        if order_data["OrderInfo"]["OrderState"] == "COMPLETED":
            ca = order_data["Fulfillment"]["CACertificates"]["CACertificate"]
            return True, None, False, ca["CACert"]
        return True, None, False, None
    except symantec_exceptions.SymantecError as e:
        return False, e, False, None
    except request_exceptions.RequestException as e:
        return False, e, True, None

Example 6

Project: barbican
Source File: symantec.py
View license
def _ca_modify_order(self, order_meta, plugin_meta):
    """Sends a request to the Symantec CA to modify an order.

    Parameters needed for modifyOrder:
        PartnerOrderID - Needed to specify order
        PartnerCode - Needed to specify order
        ProductCode - Needed to specify order

    Also need a dict, order_meta with the parameters/values to modify.

    returns: tuple with success, error message, and can retry.
    """
    api = Symantec(self.username, self.password, self.url)

    order_details = {
        "PartnerOrderID": plugin_meta["PartnerOrderID"],
        "PartnerCode": plugin_meta["PartnerCode"],
        "ProductCode": plugin_meta["ProductCode"],
    }

    order_details.update(order_meta)

    try:
        api.validate_order_parameters(**order_details)
        return True, None, False
    except symantec_exceptions.SymantecError as e:
        return False, e, False
    except request_exceptions.RequestException as e:
        return False, e, True

Example 7

Project: barbican
Source File: symantec.py
View license
def _ca_cancel_order(self, plugin_meta):
    """Sends a request to the Symantec CA to cancel an order.

    Parameters needed for modifyOrder:
        PartnerOrderID - Needed to specify order
        PartnerCode - Needed to specify order
        ProductCode - Needed to specify order

    returns: tuple with success, error message, and can retry.
    """
    api = Symantec(self.username, self.password, self.url)

    order_details = {
        "PartnerOrderID": plugin_meta["PartnerOrderID"],
        "PartnerCode": plugin_meta["PartnerCode"],
        "ProductCode": plugin_meta["ProductCode"],
        "ModifyOrderOperation": "CANCEL",
    }

    try:
        api.modify_order(**order_details)
        return True, None, False
    except symantec_exceptions.SymantecError as e:
        return False, e, False
    except request_exceptions.RequestException as e:
        return False, e, True