[REL] connector_amazon_sp: for 11.0

This commit is contained in:
Jared Kipe
2022-02-04 13:25:45 -08:00
parent 8b2afa882d
commit bf7192f71a
48 changed files with 4264 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
from contextlib import contextmanager
from datetime import datetime, timedelta, timezone
from sp_api.base.ApiResponse import ApiResponse
from unittest.mock import patch
@contextmanager
def mock_submit_feed_api(return_error=False):
submit_feed_res1 = {'errors': None,
'headers': {'Content-Length': '665',
'Content-Type': 'application/json',
'Date': datetime.now(tz=timezone.utc).strftime('%a, %d %b %Y %H:%M:00 %Z'),
},
'kwargs': {},
'next_token': None,
'pagination': None,
'payload': {'encryptionDetails': {'initializationVector': '',
'key': '',
'standard': 'AES'},
'feedDocumentId': '',
'url': ''}}
submit_feed_res2 = {'errors': None,
'headers': {'Content-Length': '37',
'Content-Type': 'application/json',
'Date': datetime.now(tz=timezone.utc).strftime('%a, %d %b %Y %H:%M:00 %Z'),
},
'kwargs': {},
'next_token': None,
'pagination': None,
'payload': {'feedId': '555555555555'}}
if return_error:
submit_feed_res2['payload'] = {}
with patch('odoo.addons.connector_amazon_sp.components.api.amazon.Feeds') as mock_feeds:
mock_feeds.return_value.submit_feed.return_value = ApiResponse(**submit_feed_res1), ApiResponse(**submit_feed_res2)
yield
@contextmanager
def mock_check_feed_api(done=False):
check_feed_res3 = {'errors': None,
'headers': {'Content-Length': '175', 'Content-Type': 'application/json',
'Date': datetime.now(tz=timezone.utc).strftime('%a, %d %b %Y %H:%M:00 %Z')},
'kwargs': {},
'next_token': None,
'pagination': None,
'payload': {'createdTime': datetime.now(tz=timezone.utc).isoformat(timespec='seconds'),
'feedId': '555555555555',
'feedType': 'POST_PRODUCT_DATA',
'marketplaceIds': ['555555555555'],
'processingStatus': 'IN_QUEUE'}}
if done:
check_feed_res3['payload']['processingStatus'] = 'DONE'
end_time = datetime.now(tz=timezone.utc)
start_time = end_time - timedelta(minutes=2)
check_feed_res3['payload']['processingStartTime'] = start_time.isoformat(timespec='seconds')
check_feed_res3['payload']['processingEndTime'] = end_time.isoformat(timespec='seconds')
check_feed_res3['payload']['resultFeedDocumentId'] = 'xxxxxxxx'
feed_result_document = """
<?xml version="1.0" encoding="UTF-8"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.02</DocumentVersion>
<MerchantIdentifier>555555555555</MerchantIdentifier>
</Header>
<MessageType>ProcessingReport</MessageType>
<Message>
<MessageID>1</MessageID>
<ProcessingReport>
<DocumentTransactionID>555555555555</DocumentTransactionID>
<StatusCode>Complete</StatusCode>
<ProcessingSummary>
<MessagesProcessed>1</MessagesProcessed>
<MessagesSuccessful>1</MessagesSuccessful>
<MessagesWithError>0</MessagesWithError>
<MessagesWithWarning>0</MessagesWithWarning>
</ProcessingSummary>
</ProcessingReport>
</Message>
</AmazonEnvelope>
"""
with patch('odoo.addons.connector_amazon_sp.components.api.amazon.Feeds') as mock_feeds:
mock_feeds.return_value.get_feed.return_value = ApiResponse(**check_feed_res3)
mock_feeds.return_value.get_feed_result_document.return_value = feed_result_document
yield

View File

@@ -0,0 +1,74 @@
from contextlib import contextmanager
from sp_api.base.ApiResponse import ApiResponse
from unittest.mock import patch
get_order_response = {'payload': {'AmazonOrderId': '111-1111111-1111111',
'PurchaseDate': '2021-04-24T20:22:03Z',
'LastUpdateDate': '2021-04-26T17:25:41Z',
'OrderStatus': 'Shipped',
'FulfillmentChannel': 'MFN',
'SalesChannel': 'Amazon.com',
'ShipServiceLevel': 'Std US D2D Dom',
'OrderTotal': {'CurrencyCode': 'USD',
'Amount': '159.96'},
'NumberOfItemsShipped': 1,
'NumberOfItemsUnshipped': 0,
'PaymentMethod': 'Other',
'PaymentMethodDetails': ['Standard'],
'IsReplacementOrder': False,
'MarketplaceId': 'ATVPDKIKX0DER',
'ShipmentServiceLevelCategory': 'Standard',
'OrderType': 'StandardOrder',
'EarliestShipDate': '2021-04-26T07:00:00Z',
'LatestShipDate': '2021-04-27T06:59:59Z',
'EarliestDeliveryDate': '2021-04-30T07:00:00Z',
'LatestDeliveryDate': '2021-05-01T06:59:59Z',
'IsBusinessOrder': False,
'IsPrime': True,
'IsGlobalExpressEnabled': False,
'IsPremiumOrder': False,
'IsSoldByAB': False,
'DefaultShipFromLocationAddress': {'Name': 'null',
'AddressLine1': 'null',
'AddressLine2': 'null',
'City': 'SELLERSBURG',
'StateOrRegion': 'IN',
'PostalCode': '47172',
'CountryCode': 'US'},
'IsISPU': False}}
get_order_items_response = {'payload': {'AmazonOrderId': '111-1111111-1111111',
'OrderItems': [
{'ASIN': 'A1B1C1D1E1',
'OrderItemId': '12345678901234',
'SellerSKU': 'TEST_PRODUCT',
'Title': 'Test Product Purchased From Amazon',
'QuantityOrdered': 1, 'QuantityShipped': 1,
'ProductInfo': {'NumberOfItems': '1'},
'ItemPrice': {'CurrencyCode': 'USD', 'Amount': '199.95'},
'ItemTax': {'CurrencyCode': 'USD', 'Amount': '0.00'},
'PromotionDiscount': {'CurrencyCode': 'USD', 'Amount': '39.99'},
'PromotionDiscountTax': {'CurrencyCode': 'USD', 'Amount': '0.00'},
'PromotionIds': ['Coupon'],
'IsGift': 'false',
'ConditionId': 'New',
'ConditionSubtypeId': 'New',
'IsTransparency': False}]}}
get_order_address_response = {'payload': {'AmazonOrderId': '111-1111111-1111111',
'ShippingAddress': {'StateOrRegion': 'FL', 'PostalCode': '34655-5649',
'City': 'NEW PORT RICHEY', 'CountryCode': 'US',
'Name': ''}}}
get_order_buyer_info_response = {'payload': {'AmazonOrderId': '111-1111111-1111111',
'BuyerEmail': 'obfuscated@marketplace.amazon.com'}}
@contextmanager
def mock_orders_api():
with patch('odoo.addons.connector_amazon_sp.components.api.amazon.Orders') as mock_orders:
mock_orders.return_value.get_order.return_value = ApiResponse(**get_order_response)
mock_orders.return_value.get_order_items.return_value = ApiResponse(**get_order_items_response)
mock_orders.return_value.get_order_address.return_value = ApiResponse(**get_order_address_response)
mock_orders.return_value.get_order_buyer_info.return_value = ApiResponse(**get_order_buyer_info_response)
yield