예제 #1
0
    def test_serialize_modified_orders(self):

        re = RequestEnvelope(GetModifiedOrderRequest())

        root = re.serialize()
        mod_requests = root.findall('.//GetModifiedOrders')
        len_mod_request = len(root.find('.//Request'))

        assert len(mod_requests) == 1
        assert len_mod_request > 0
예제 #2
0
    def test_serialize_modified_orders(self):

        re = RequestEnvelope(GetModifiedOrderRequest())

        root = re.serialize()
        mod_requests = root.findall('.//GetModifiedOrders')
        len_mod_request = len(root.find('.//Request'))

        assert len(mod_requests) == 1
        assert len_mod_request > 0
예제 #3
0
파일: order.py 프로젝트: sinu/symantecssl
def post_request(endpoint, request_model, credentials):
    """Create a post request against Symantec's SOAPXML API.

    Currently supported Request Models are:
    GetModifiedOrders
    QuickOrderRequest

    note:: the request can take a considerable amount of time if the
    date range covers a large amount of changes.

    note:: credentials should be a dictionary with the following values:

    partner_code
    username
    password

    Access all data from response via models

    :param endpoint: Symantec endpoint to hit directly
    :param request_model: request model instance to initiate call type
    :param credentials: Symantec specific credentials for orders.
    :return response: deserialized response from API
    """

    request_model.set_credentials(**credentials)
    model = ReqEnv(request_model=request_model)
    serialized_xml = etree.tostring(model.serialize(), pretty_print=True)

    headers = {'Content-Type': 'application/soap+xml'}

    response = requests.post(endpoint, serialized_xml, headers=headers)
    setattr(response, "model", None)

    # Symantec not expected to return 2xx range; only 200
    if response.status_code != 200:
        raise FailedRequest(response)
    xml_root = etree.fromstring(response.content)
    deserialized = request_model.response_model.deserialize(xml_root)
    setattr(response, "model", deserialized)

    return response
예제 #4
0
def post_request(endpoint, request_model, credentials):
    """Create a post request against Symantec's SOAPXML API.

    Currently supported Request Models are:
    GetModifiedOrders
    QuickOrderRequest

    note:: the request can take a considerable amount of time if the
    date range covers a large amount of changes.

    note:: credentials should be a dictionary with the following values:

    partner_code
    username
    password

    Access all data from response via models

    :param endpoint: Symantec endpoint to hit directly
    :param request_model: request model instance to initiate call type
    :param credentials: Symantec specific credentials for orders.
    :return response: deserialized response from API
    """

    request_model.set_credentials(**credentials)
    model = ReqEnv(request_model=request_model)
    serialized_xml = etree.tostring(model.serialize(), pretty_print=True)

    headers = {'Content-Type': 'application/soap+xml'}

    response = requests.post(endpoint, serialized_xml, headers=headers)
    setattr(response, "model", None)

    # Symantec not expected to return 2xx range; only 200
    if response.status_code != 200:
        raise FailedRequest(response)
    xml_root = etree.fromstring(response.content)
    deserialized = request_model.response_model.deserialize(xml_root)
    setattr(response, "model", deserialized)

    return response
예제 #5
0
def _prepare_request(request_model, credentials):
    """
    Prepare the request for execution.

    :param request_model: an object with a ``serialize`` method that returns
        some LXML Etrees.
    :param dict credentials: A dictionary containing the following keys:

            - ``partner_code``

            - ``username``

            - ``password``

    :return: a 2-tuple of C{bytes} - the contents of the request and C{dict}
             mapping C{bytes} to C{bytes} - the HTTP headers for the request.
    """
    request_model.set_credentials(**credentials)
    model = ReqEnv(request_model=request_model)
    serialized_xml = etree.tostring(model.serialize(), pretty_print=True)
    headers = {'Content-Type': 'application/soap+xml'}

    return (serialized_xml, headers)
예제 #6
0
def _prepare_request(request_model, credentials):
    """
    Prepare the request for execution.

    :param request_model: an object with a ``serialize`` method that returns
        some LXML Etrees.
    :param dict credentials: A dictionary containing the following keys:

            - ``partner_code``

            - ``username``

            - ``password``

    :return: a 2-tuple of C{bytes} - the contents of the request and C{dict}
             mapping C{bytes} to C{bytes} - the HTTP headers for the request.
    """
    request_model.set_credentials(**credentials)
    model = ReqEnv(request_model=request_model)
    serialized_xml = etree.tostring(model.serialize(), pretty_print=True)
    headers = {'Content-Type': 'application/soap+xml'}

    return (serialized_xml, headers)