Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Commit

Permalink
Add order test and update factories
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Vetter committed Nov 4, 2013
1 parent 13dde4c commit f4e5eff
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 31 deletions.
7 changes: 6 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import os
import logging

from django.conf import settings

from oscar import OSCAR_MAIN_TEMPLATE_DIR, get_core_apps

location = lambda x: os.path.join(
os.path.dirname(os.path.realpath(__file__)), x
)
sandbox = lambda x: location("sandbox/%s" % x)

from oscar import OSCAR_MAIN_TEMPLATE_DIR, get_core_apps
logging.basicConfig(level=logging.INFO)


def pytest_configure():
Expand All @@ -16,6 +19,7 @@ def pytest_configure():

DEFAULT_SETTINGS = OSCAR_SETTINGS
DEFAULT_SETTINGS.update(OSCAR_MWS_SETTINGS)
DEFAULT_SETTINGS['OSCAR_DEFAULT_CURRENCY'] = 'USD'

settings.configure(
DATABASES={
Expand Down Expand Up @@ -134,5 +138,6 @@ def pytest_configure():
},
}
},
DEBUG=True,
**DEFAULT_SETTINGS
)
18 changes: 17 additions & 1 deletion docs/source/notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Notes
=====

.. warning:: For same parts of the API to work, you'll have to provide tax
information in your MWS Pro account. Otherwise you'll get a
``Seller is not registered for Basic fulfillment.`` error message back.

For the time being, this is going to be a collection of finding while using the
MWS API. It mainly things that I've picked up while working on it through
feedback submitting wrong or incomplete data. It's not necessarily correct and
Expand All @@ -11,7 +15,19 @@ Fulfillment
-----------

* Fulfillment orders are created against a seller account rather than a
marektplace. This means
marektplace. That means all marketplaces that belong to the same seller
account are submitted against that seller account and do not require a
marketplaces.

Submitting An Order
~~~~~~~~~~~~~~~~~~~

* The ``DestinationAddress.CountryCode`` is validated against the seller
account region and is rejected if outside of it. E.g. a ``US`` country code
submitted to a seller acount for Europe is rejected with::

<Error>
<Type>Sender</Type>
<Code>InvalidRequestException</Code>
<Message>Value US for parameter DestinationAddress.CountryCode is invalid. Reason: InvalidValue.</Message>
</Error>
22 changes: 21 additions & 1 deletion oscar_mws/test/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
Selector = get_class('partner.strategy', 'Selector')


class CountryFactory(factory.DjangoModelFactory):
FACTORY_FOR = get_model('address', 'Country')

iso_3166_1_a2 = factory.Iterator(['US', 'GB', 'DE'])
iso_3166_1_a3 = factory.Iterator(['USA', 'GBR', 'DEU'])
iso_3166_1_numeric = factory.Iterator(['840', '276', '826'])


class ProductClassFactory(factory.DjangoModelFactory):
FACTORY_FOR = get_model('catalogue', 'ProductClass')

Expand Down Expand Up @@ -85,11 +93,23 @@ class FeedSubmissionFactory(factory.DjangoModelFactory):
class PartnerFactory(factory.DjangoModelFactory):
FACTORY_FOR = get_model('partner', 'Partner')

name = factory.Sequence(lambda n:'Dummy partner {}'.format(n))
name = factory.Sequence(lambda n: 'Dummy partner {}'.format(n))


class StockRecordFactory(factory.DjangoModelFactory):
FACTORY_FOR = get_model('partner', 'StockRecord')

price_excl_tax = D('12.99')
partner = factory.SubFactory(PartnerFactory)


class ShippingAddressFactory(factory.DjangoModelFactory):
FACTORY_FOR = get_model('order', 'ShippingAddress')

first_name = 'Peter'
last_name = 'Griffin'
line1 = '31 Spooner Street'
line4 = 'Quahog'
state = 'RI'
country = factory.SubFactory(CountryFactory)
postcode = '12345'
22 changes: 22 additions & 0 deletions oscar_mws/test/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import base64
import hashlib

from . import factories


class DataLoaderMixin(object):
data_directory = 'tests/data'
Expand All @@ -18,3 +20,23 @@ def load_data(self, filename):
with open(path) as fh:
data = fh.read()
return data


class IntegrationMixin(object):

def setUp(self):
super(IntegrationMixin, self).setUp()
self.product = factories.ProductFactory(
upc='9781741173420', title='Kayaking Around Australia')
self.merchant = factories.MerchantAccountFactory(
name="Integration Test Account", seller_id=os.getenv('SELLER_ID'),
aws_api_key=os.getenv('AWS_ACCESS_KEY_ID'),
aws_api_secret=os.getenv('AWS_SECRET_ACCESS_KEY'))

amazon_profile = factories.AmazonProfileFactory(product=self.product)
amazon_profile.fulfillment_by = amazon_profile.FULFILLMENT_BY_AMAZON
amazon_profile.save()

self.marketplace = factories.AmazonMarketplaceFactory(
merchant=self.merchant, marketplace_id='ATVPDKIKX0DER')
amazon_profile.marketplaces.add(self.marketplace)
69 changes: 41 additions & 28 deletions tests/integration/test_fulfillment.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,18 @@
import os
import time
import pytest

from django.test import TestCase

from oscar.test.factories import create_product
from oscar.test.factories import create_order

from oscar_mws.test import factories
from oscar_mws.models import AmazonProfile
from oscar_mws import abstract_models as am
from oscar_mws.test import factories, mixins
from oscar_mws.feeds import gateway as feeds_gw
from oscar_mws.fulfillment.creator import FulfillmentOrderCreator


@pytest.mark.integration
class TestSubmittingAFeed(TestCase):

def setUp(self):
self.product = create_product(
upc='9781741173420',
title='Kayaking Around Australia',
)
self.merchant = factories.MerchantAccountFactory(
name="Integration Test Account",
seller_id=os.getenv('SELLER_ID'),
aws_api_key=os.getenv('AWS_ACCESS_KEY_ID'),
aws_api_secret=os.getenv('AWS_SECRET_ACCESS_KEY'),
)
self.marketplace = factories.AmazonMarketplaceFactory(
merchant=self.merchant,
marketplace_id='ATVPDKIKX0DER',
)

amazon_profile = AmazonProfile.objects.create(product=self.product)
amazon_profile.fulfillment_by = AmazonProfile.FULFILLMENT_BY_AMAZON
amazon_profile.save()

amazon_profile.marketplaces.add(self.marketplace)
class TestSubmittingAFeed(mixins.IntegrationMixin, TestCase):

def _check_submission(self, submission):
self.assertEquals(submission.processing_status, am.STATUS_SUBMITTED)
Expand Down Expand Up @@ -89,7 +66,7 @@ def test_is_processed(self):

self.assertEquals(
self.product.amazon_profile.fulfillment_by,
AmazonProfile.FULFILLMENT_BY_AMAZON
self.product.amazon_profile.FULFILLMENT_BY_AMAZON
)

# Delete product
Expand All @@ -100,3 +77,39 @@ def test_is_processed(self):
)
submission = self._check_submission(submissions[0])
self.assertEquals(submission.processing_status, am.STATUS_DONE)


@pytest.mark.integration
class TestAFulfillmentOrder(mixins.IntegrationMixin, TestCase):

def setUp(self):
super(TestAFulfillmentOrder, self).setUp()
self.basket = factories.BasketFactory()
self.basket.add_product(self.product)
shipping_address = factories.ShippingAddressFactory()
self.order = create_order(shipping_address=shipping_address,
basket=self.basket)

def _wait_until_submission_processed(self, submission):
while submission.processing_status not in [am.STATUS_DONE,
am.STATUS_CANCELLED]:
time.sleep(20) # wait before next polling to avoid throttling
submission = feeds_gw.update_feed_submission(submission)

if submission.processing_status != am.STATUS_DONE:
raise Exception('Feed {} in unexpected state {}'.format(
submission.submission_id, submission.processing_status))

return submission

def test_can_be_created(self):
submissions = feeds_gw.submit_product_feed(
products=[self.product], marketplaces=[self.marketplace])
self._wait_until_submission_processed(submissions[0])

submission = feeds_gw.switch_product_fulfillment(
marketplace=self.marketplace, products=[self.product])
self._wait_until_submission_processed(submission)

creator = FulfillmentOrderCreator()
orders = creator.create_fulfillment_order(self.order)

0 comments on commit f4e5eff

Please sign in to comment.