class TestListOrderItemsRequesterFailedBody(TestCase):
    """
    Test to make sure that the requester is raising on a status code 200 but the body is an ErrorResponse
    """

    body = """
    <ErrorResponse xmlns="https://mws.amazonservices.com/Orders/2013-09-01">
        <Error>
            <Type>Sender</Type>
            <Code>InvalidParameterValue</Code>
            <Message>Invalid AmazonOrderId: xxx-xxxxxxx-xxxxxxx</Message>
        </Error>
        <RequestId>request-id</RequestId>
    </ErrorResponse>
    """

    def setUp(self):
        self.requester = ListOrderItemsRequester(None, None, None)
        self.requester.api.list_order_items = lambda *args, **kwargs: make_response(
            200, self.body)

    def raise_failed_request(self):
        self.requester.request(None)

    def test_request(self):
        self.assertRaises(ErrorElement, self.raise_failed_request)
class TestListOrderItemsRequesterServerError(TestCase):
    body = ""

    def setUp(self):
        self.requester = ListOrderItemsRequester(None, None, None)
        self.requester.api.list_order_items = lambda *args, **kwargs: make_response(
            500, self.body)

    def raise_failed_request(self):
        self.requester.request(None)

    def test_request(self):
        self.assertRaises(requests.HTTPError, self.raise_failed_request)
class TestListOrderItemsRequesterClientError(TestCase):
    body = """
    <ErrorResponse xmlns="https://mws.amazonservices.com/Orders/2013-09-01">
        <Error>
            <Type>Sender</Type>
            <Code>InvalidParameterValue</Code>
            <Message>Invalid AmazonOrderId: xxx-xxxxxxx-xxxxxxx</Message>
        </Error>
        <RequestId>request-id</RequestId>
    </ErrorResponse>
    """

    def setUp(self):
        self.requester = ListOrderItemsRequester(None, None, None)
        self.requester.api.list_order_items = lambda *args, **kwargs: make_response(
            400, self.body)

    def raise_failed_request(self):
        self.requester.request(None)

    def test_request(self):
        self.assertRaises(requests.HTTPError, self.raise_failed_request)
class TestListOrderItemsRequesterSuccess(TestCase):

    body = """
    <ListOrderItemsResponse xmlns="https://mws.amazonservices.com/Orders/2013-09-01">
        <Empty />
    </ListOrderItemsResponse>
    """

    def setUp(self):
        self.requester = ListOrderItemsRequester(None, None, None)
        self.requester.api.list_order_items = lambda *args, **kwargs: make_response(
            200, self.body)

    def test_request(self):
        self.assertIsInstance(self.requester.request(None),
                              ListOrderItemsResponse)
 def setUp(self):
     self.requester = ListOrderItemsRequester(None, None, None)
     self.requester.api.list_order_items = lambda *args, **kwargs: make_response(
         200, self.body)