# 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/feeds/gateway.py
# OP_TYPE_UPDATE = 'Update'
# OP_TYPE_PARTIAL_UPDATE = 'PartialUpdate'
# OP_TYPE_DELETE = 'Delete'
# class MwsFeedError(BaseException):
# def handle_feed_submission_response(merchant, response, feed_xml=None):
# def submit_product_feed(products, marketplaces, dry_run=False,
#                         operation_type=OP_TYPE_UPDATE):
# def update_feed_submission(submission):
# def update_feed_submissions(merchant):
# def list_submitted_feeds(merchants=None):
# def cancel_submission(submission):
# def process_submission_results(submission):
# def update_product_identifiers(merchant, products):
# def switch_product_fulfillment(marketplace, products, dry_run=False):
# 
# Path: oscar_mws/abstract_models.py
# STATUS_CANCELLED = "_CANCELLED_"
# 
# STATUS_SUBMITTED = "_SUBMITTED_"
# 
# TYPE_POST_PRODUCT_DATA = "_POST_PRODUCT_DATA_"


import mock
import pytest
from oscar_mws.test import factories
from oscar_mws.feeds import gateway as feed_gw
from oscar_mws.abstract_models import (
    STATUS_CANCELLED, STATUS_SUBMITTED, TYPE_POST_PRODUCT_DATA)
        'FeedSubmissionInfo': mock.Mock(
            FeedSubmissionId=submission.submission_id,
            SubmittedDate='2012-06-30',
            FeedType=submission.feed_type,
            FeedProcessingStatus=submission.processing_status)}

    with mock.patch('oscar_mws.feeds.gateway.get_merchant_connection') as conn:
        conn.return_value = mock.Mock(
            cancel_feed_submissions=mock.Mock(
                return_value=mock.Mock(parsed=response)))

        updated = feed_gw.cancel_submission(submission)

        assert updated.submission_id == submission.submission_id
        assert updated.processing_status == submission.processing_status


def test_cancelling_submission_updates_changed_status(submission):
    response = {
        'FeedSubmissionInfo': mock.Mock(
            FeedSubmissionId=submission.submission_id,
            SubmittedDate='2012-06-30',
            FeedType=submission.feed_type,
            FeedProcessingStatus=STATUS_CANCELLED)}

    with mock.patch('oscar_mws.feeds.gateway.get_merchant_connection') as conn:
        conn.return_value = mock.Mock(
            cancel_feed_submissions=mock.Mock(
                return_value=mock.Mock(parsed=response)))


# 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/feeds/gateway.py
# OP_TYPE_UPDATE = 'Update'
# OP_TYPE_PARTIAL_UPDATE = 'PartialUpdate'
# OP_TYPE_DELETE = 'Delete'
# class MwsFeedError(BaseException):
# def handle_feed_submission_response(merchant, response, feed_xml=None):
# def submit_product_feed(products, marketplaces, dry_run=False,
#                         operation_type=OP_TYPE_UPDATE):
# def update_feed_submission(submission):
# def update_feed_submissions(merchant):
# def list_submitted_feeds(merchants=None):
# def cancel_submission(submission):
# def process_submission_results(submission):
# def update_product_identifiers(merchant, products):
# def switch_product_fulfillment(marketplace, products, dry_run=False):
# 
# Path: oscar_mws/abstract_models.py
# STATUS_CANCELLED = "_CANCELLED_"
# 
# STATUS_SUBMITTED = "_SUBMITTED_"
# 
# TYPE_POST_PRODUCT_DATA = "_POST_PRODUCT_DATA_"


# Path: tests/unit/test_feeds.py
import mock
import pytest
from oscar_mws.test import factories
from oscar_mws.feeds import gateway as feed_gw
from oscar_mws.abstract_models import (
    STATUS_CANCELLED, STATUS_SUBMITTED, TYPE_POST_PRODUCT_DATA)

        'FeedSubmissionInfo': mock.Mock(
            FeedSubmissionId=submission.submission_id,
            SubmittedDate='2012-06-30',
            FeedType=submission.feed_type,
            FeedProcessingStatus=submission.processing_status)}

    with mock.patch('oscar_mws.feeds.gateway.get_merchant_connection') as conn:
        conn.return_value = mock.Mock(
            cancel_feed_submissions=mock.Mock(
                return_value=mock.Mock(parsed=response)))

        updated = feed_gw.cancel_submission(submission)

        assert updated.submission_id == submission.submission_id
        assert updated.processing_status == submission.processing_status


def test_cancelling_submission_updates_changed_status(submission):
    response = {
        'FeedSubmissionInfo': mock.Mock(
            FeedSubmissionId=submission.submission_id,
            SubmittedDate='2012-06-30',
            FeedType=submission.feed_type,
            FeedProcessingStatus=STATUS_CANCELLED)}

    with mock.patch('oscar_mws.feeds.gateway.get_merchant_connection') as conn:
        conn.return_value = mock.Mock(
            cancel_feed_submissions=mock.Mock(
                return_value=mock.Mock(parsed=response)))


        updated = feed_gw.cancel_submission(submission)