# Path: oscar_mws/api.py
# class MWSError(Exception):
#     """
#     Main MWS Exception class
#     """
#     # Allows quick access to the response object.
#     # Do not rely on this attribute, always check if its not None.
#     response = None
#     url = None
# 
# Path: oscar_mws/test/factories.py
# class UserFactory(factory.DjangoModelFactory):
# class CountryFactory(factory.DjangoModelFactory):
# class ProductClassFactory(factory.DjangoModelFactory):
# class BasketFactory(factory.DjangoModelFactory):
# class AmazonProfileFactory(factory.DjangoModelFactory):
# class ProductFactory(factory.DjangoModelFactory):
# class MerchantAccountFactory(factory.DjangoModelFactory):
# class AmazonMarketplaceFactory(factory.DjangoModelFactory):
# class FeedSubmissionFactory(factory.DjangoModelFactory):
# class PartnerFactory(factory.DjangoModelFactory):
# class StockRecordFactory(factory.DjangoModelFactory):
# class ShippingAddressFactory(factory.DjangoModelFactory):
# class OrderLineFactory(factory.DjangoModelFactory):
# class OrderFactory(factory.DjangoModelFactory):
# class FulfillmentOrderFactory(factory.DjangoModelFactory):
#     FACTORY_FOR = get_model('auth', 'User')
#     FACTORY_FOR = get_model('address', 'Country')
#     FACTORY_FOR = get_model('catalogue', 'ProductClass')
#     FACTORY_FOR = get_model('basket', 'Basket')
#     FACTORY_FOR = get_model('oscar_mws', 'AmazonProfile')
#     FACTORY_DJANGO_GET_OR_CREATE = ('product',)
#     FACTORY_FOR = get_model('catalogue', 'Product')
#     FACTORY_FOR = get_model('oscar_mws', 'MerchantAccount')
#     FACTORY_FOR = get_model('oscar_mws', 'AmazonMarketplace')
#     FACTORY_FOR = get_model('oscar_mws', 'FeedSubmission')
#     FACTORY_DJANGO_GET_OR_CREATE = ('submission_id',)
#     FACTORY_FOR = get_model('partner', 'Partner')
#     FACTORY_FOR = get_model('partner', 'StockRecord')
#     FACTORY_FOR = get_model('order', 'ShippingAddress')
#     FACTORY_FOR = get_model('order', 'Line')
#     FACTORY_FOR = get_model('order', 'Order')
#     FACTORY_FOR = get_model('oscar_mws', 'FulfillmentOrder')
#     def stockrecord(self, created, extracted, **kwargs):
# 
# Path: oscar_mws/fulfillment/gateway.py
# def _update_shipment(shipment_data, fulfillment_order):
# def submit_fulfillment_orders(orders):
# def submit_fulfillment_order(fulfillment_order):
# def update_fulfillment_order(fulfillment_order):
# def update_fulfillment_orders(fulfillment_orders):
# def get_all_fulfillment_orders(merchant, query_datetime=None):
# def update_inventory(products):


import mock
from django.test import TestCase
from oscar_mws.api import MWSError
from oscar_mws.test import factories
from oscar_mws.fulfillment import gateway




class TestSubmittingFulfillmentOrder(TestCase):

    def setUp(self):
        super(TestSubmittingFulfillmentOrder, self).setUp()
        self.fulfillment_order = factories.FulfillmentOrderFactory()

    def test_sets_order_status_to_failed_with_error(self):
        with mock.patch('oscar_mws.fulfillment.gateway.get_merchant_connection') as gmc_mock:
            gmc_mock.return_value = mock.Mock(
                create_fulfillment_order=mock.Mock(side_effect=MWSError()))

            gateway.submit_fulfillment_orders([self.fulfillment_order])
            self.assertEquals(self.fulfillment_order.status,
                                self.fulfillment_order.SUBMISSION_FAILED)

    def test_sets_order_status_to_submitted_when_successful(self):
        with mock.patch('oscar_mws.fulfillment.gateway.get_merchant_connection') as gmc_mock:
            gmc_mock.return_value = mock.Mock(
                create_fulfillment_order=mock.Mock())


# Path: oscar_mws/api.py
# class MWSError(Exception):
#     """
#     Main MWS Exception class
#     """
#     # Allows quick access to the response object.
#     # Do not rely on this attribute, always check if its not None.
#     response = None
#     url = None
# 
# Path: oscar_mws/test/factories.py
# class UserFactory(factory.DjangoModelFactory):
# class CountryFactory(factory.DjangoModelFactory):
# class ProductClassFactory(factory.DjangoModelFactory):
# class BasketFactory(factory.DjangoModelFactory):
# class AmazonProfileFactory(factory.DjangoModelFactory):
# class ProductFactory(factory.DjangoModelFactory):
# class MerchantAccountFactory(factory.DjangoModelFactory):
# class AmazonMarketplaceFactory(factory.DjangoModelFactory):
# class FeedSubmissionFactory(factory.DjangoModelFactory):
# class PartnerFactory(factory.DjangoModelFactory):
# class StockRecordFactory(factory.DjangoModelFactory):
# class ShippingAddressFactory(factory.DjangoModelFactory):
# class OrderLineFactory(factory.DjangoModelFactory):
# class OrderFactory(factory.DjangoModelFactory):
# class FulfillmentOrderFactory(factory.DjangoModelFactory):
#     FACTORY_FOR = get_model('auth', 'User')
#     FACTORY_FOR = get_model('address', 'Country')
#     FACTORY_FOR = get_model('catalogue', 'ProductClass')
#     FACTORY_FOR = get_model('basket', 'Basket')
#     FACTORY_FOR = get_model('oscar_mws', 'AmazonProfile')
#     FACTORY_DJANGO_GET_OR_CREATE = ('product',)
#     FACTORY_FOR = get_model('catalogue', 'Product')
#     FACTORY_FOR = get_model('oscar_mws', 'MerchantAccount')
#     FACTORY_FOR = get_model('oscar_mws', 'AmazonMarketplace')
#     FACTORY_FOR = get_model('oscar_mws', 'FeedSubmission')
#     FACTORY_DJANGO_GET_OR_CREATE = ('submission_id',)
#     FACTORY_FOR = get_model('partner', 'Partner')
#     FACTORY_FOR = get_model('partner', 'StockRecord')
#     FACTORY_FOR = get_model('order', 'ShippingAddress')
#     FACTORY_FOR = get_model('order', 'Line')
#     FACTORY_FOR = get_model('order', 'Order')
#     FACTORY_FOR = get_model('oscar_mws', 'FulfillmentOrder')
#     def stockrecord(self, created, extracted, **kwargs):
# 
# Path: oscar_mws/fulfillment/gateway.py
# def _update_shipment(shipment_data, fulfillment_order):
# def submit_fulfillment_orders(orders):
# def submit_fulfillment_order(fulfillment_order):
# def update_fulfillment_order(fulfillment_order):
# def update_fulfillment_orders(fulfillment_orders):
# def get_all_fulfillment_orders(merchant, query_datetime=None):
# def update_inventory(products):


# Path: tests/unit/fulfillment/test_gateway.py
import mock
from django.test import TestCase
from oscar_mws.api import MWSError
from oscar_mws.test import factories
from oscar_mws.fulfillment import gateway





class TestSubmittingFulfillmentOrder(TestCase):

    def setUp(self):
        super(TestSubmittingFulfillmentOrder, self).setUp()
        self.fulfillment_order = factories.FulfillmentOrderFactory()

    def test_sets_order_status_to_failed_with_error(self):
        with mock.patch('oscar_mws.fulfillment.gateway.get_merchant_connection') as gmc_mock:
            gmc_mock.return_value = mock.Mock(
                create_fulfillment_order=mock.Mock(side_effect=MWSError()))

            gateway.submit_fulfillment_orders([self.fulfillment_order])
            self.assertEquals(self.fulfillment_order.status,
                                self.fulfillment_order.SUBMISSION_FAILED)

    def test_sets_order_status_to_submitted_when_successful(self):
        with mock.patch('oscar_mws.fulfillment.gateway.get_merchant_connection') as gmc_mock:
            gmc_mock.return_value = mock.Mock(
                create_fulfillment_order=mock.Mock())


            gateway.submit_fulfillment_orders([self.fulfillment_order])