Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix avalara test for generate reqyest data with click and collect (#12808)

Filip Owczarekf73318c129a6
diff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_get_checkout_tax_data_with_single_point.yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_get_checkout_tax_data_with_single_point.yaml
deleted file mode 100644
index bc4f1330f8..0000000000
--- a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_get_checkout_tax_data_with_single_point.yaml
+++ /dev/null
@@ -1,69 +0,0 @@
-interactions:
-- request:
- body: '{"createTransactionModel": {"companyCode": "DEFAULT", "type": "SalesOrder",
- "lines": [{"quantity": 3, "amount": "30.00", "taxCode": "O9999999", "taxIncluded":
- true, "itemCode": "123", "discounted": false, "description": "Test product",
- "ref1": "123"}], "code": "39d2b1bd-24e5-40fd-9caa-f421ff57a0f0", "date": "2023-02-16",
- "customerCode": 0, "discount": null, "addresses": {"singleLocation": {"line1":
- "4371 Lucas Knoll Apt. 791", "line2": "", "city": "BENNETTMOUTH", "region":
- "", "country": "PL", "postalCode": "53-601"}}, "commit": false, "currencyCode":
- "USD", "email": "[email protected]"}}'
- headers:
- Accept:
- - '*/*'
- Accept-Encoding:
- - gzip, deflate, br
- Authorization:
- - Basic Og==
- Connection:
- - keep-alive
- Content-Length:
- - '592'
- User-Agent:
- - python-requests/2.28.2
- method: POST
- uri: https://sandbox-rest.avatax.com/api/v2/transactions/createoradjust
- response:
- body:
- string: '{"id":0,"code":"39d2b1bd-24e5-40fd-9caa-f421ff57a0f0","companyId":7799660,"date":"2023-02-16","paymentDate":"2023-02-16","status":"Temporary","type":"SalesOrder","batchCode":"","currencyCode":"USD","exchangeRateCurrencyCode":"USD","customerUsageType":"","entityUseCode":"","customerVendorCode":"0","customerCode":"0","exemptNo":"","reconciled":false,"locationCode":"","reportingLocationCode":"","purchaseOrderNo":"","referenceCode":"","salespersonCode":"","totalAmount":24.39,"totalExempt":0.0,"totalDiscount":0.0,"totalTax":5.61,"totalTaxable":24.39,"totalTaxCalculated":5.61,"adjustmentReason":"NotAdjusted","locked":false,"version":1,"exchangeRateEffectiveDate":"2023-02-16","exchangeRate":1.0,"email":"[email protected]","modifiedDate":"2023-02-16T12:53:46.9234717Z","modifiedUserId":6479978,"taxDate":"2023-02-16","lines":[{"id":0,"transactionId":0,"lineNumber":"1","customerUsageType":"","entityUseCode":"","description":"Test
- product","discountAmount":0.0,"exemptAmount":0.0,"exemptCertId":0,"exemptNo":"","isItemTaxable":true,"itemCode":"123","lineAmount":24.3900,"quantity":3.0,"ref1":"123","ref2":"","reportingDate":"2023-02-16","tax":5.61,"taxableAmount":24.39,"taxCalculated":5.61,"taxCode":"O9999999","taxCodeId":9111,"taxDate":"2023-02-16","taxIncluded":true,"details":[{"id":0,"transactionLineId":0,"transactionId":0,"country":"PL","region":"PL","exemptAmount":0.0,"jurisCode":"PL","jurisName":"POLAND","stateAssignedNo":"","jurisType":"CNT","jurisdictionType":"Country","nonTaxableAmount":0.0,"rate":0.230000,"tax":5.61,"taxableAmount":24.39,"taxType":"Output","taxSubTypeId":"O","taxName":"Standard
- Rate","taxAuthorityTypeId":45,"taxCalculated":5.61,"rateType":"Standard","rateTypeCode":"S","unitOfBasis":"PerCurrencyUnit","isNonPassThru":false,"isFee":false,"reportingTaxableUnits":24.39,"reportingNonTaxableUnits":0.0,"reportingExemptUnits":0.0,"reportingTax":5.61,"reportingTaxCalculated":5.61,"liabilityType":"Seller"}],"nonPassthroughDetails":[],"hsCode":"","costInsuranceFreight":0.0,"vatCode":"PLS-230C","vatNumberTypeId":0}],"addresses":[{"id":0,"transactionId":0,"boundaryLevel":"Zip5","line1":"4371
- Lucas Knoll Apt. 791","line2":"","line3":"","city":"BENNETTMOUTH","region":"","postalCode":"53-601","country":"PL","taxRegionId":205102,"latitude":"","longitude":""}],"summary":[{"country":"PL","region":"PL","jurisType":"Country","jurisCode":"PL","jurisName":"POLAND","taxAuthorityType":45,"stateAssignedNo":"","taxType":"Output","taxSubType":"O","taxName":"Standard
- Rate","rateType":"Standard","taxable":24.39,"rate":0.230000,"tax":5.61,"taxCalculated":5.61,"nonTaxable":0.0,"exemption":0.0}]}'
- headers:
- Connection:
- - keep-alive
- Content-Type:
- - application/json; charset=utf-8
- Date:
- - Thu, 16 Feb 2023 12:53:46 GMT
- Location:
- - /api/v2/companies/7799660/transactions/0
- ServerDuration:
- - '00:00:00.0137975'
- Transfer-Encoding:
- - chunked
- X-Content-Type-Options:
- - nosniff
- api-supported-versions:
- - '2.0'
- cache-control:
- - private, no-cache, no-store
- referrer-policy:
- - same-origin
- strict-transport-security:
- - max-age=31536000; includeSubdomains
- x-avalara-uid:
- - d9c992ca-52ae-46f9-b741-6fc7fedaea86
- x-correlation-id:
- - d9c992ca-52ae-46f9-b741-6fc7fedaea86
- x-frame-options:
- - sameorigin
- x-permitted-cross-domain-policies:
- - none
- x-xss-protection:
- - 1; mode=block
- status:
- code: 201
- message: Created
-version: 1
diff --git a/saleor/plugins/avatax/tests/test_avatax.py b/saleor/plugins/avatax/tests/test_avatax.py
index 9b22edebae..2e6525f1a6 100644
--- a/saleor/plugins/avatax/tests/test_avatax.py
+++ b/saleor/plugins/avatax/tests/test_avatax.py
@@ -44,7 +44,6 @@ from .. import (
generate_request_data_from_checkout,
generate_request_data_from_checkout_lines,
get_cached_tax_codes_or_fetch,
- get_checkout_tax_data,
get_order_lines_data,
get_order_request_data,
get_order_tax_data,
@@ -3251,25 +3250,35 @@ def test_generate_request_data_from_checkout_for_cc_and_single_location(
}
-@patch("saleor.plugins.avatax.cache.set")
def test_get_checkout_tax_data_with_single_point(
- mock_cache_set,
checkout_with_item,
warehouse,
avatax_config,
):
# given
+ expected_address = {
+ "line1": "4371 Lucas Knoll Apt. 791",
+ "line2": "",
+ "city": "BENNETTMOUTH",
+ "region": "",
+ "country": "PL",
+ "postalCode": "53-601",
+ }
address = Address.objects.create(
- street_address_1="4371 Lucas Knoll Apt. 791",
- city="BENNETTMOUTH",
- postal_code="53-601",
- country="PL",
+ street_address_1=expected_address["line1"],
+ city=expected_address["city"],
+ postal_code=expected_address["postalCode"],
+ country=expected_address["country"],
)
warehouse.address = address
warehouse.is_private = False
warehouse.save()
+ avatax_config.from_street_address = expected_address["line1"]
+ avatax_config.from_city = expected_address["city"]
+ avatax_config.from_postal_code = expected_address["postalCode"]
+ avatax_config.from_country = expected_address["country"]
+
checkout_with_item.collection_point = warehouse
checkout_with_item.save()
@@ -3278,10 +3287,15 @@ def test_get_checkout_tax_data_with_single_point(
checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)
# when
- response = get_checkout_tax_data(checkout_info, lines, config=avatax_config)
+ request_data = generate_request_data_from_checkout(
+ checkout_info, lines, config=avatax_config
+ )
# then
- assert len(response.get("addresses", [])) == 1
+ addresses = request_data["createTransactionModel"]["addresses"]
+ assert addresses["singleLocation"] == expected_address
+ assert "shipFrom" not in addresses.keys()
+ assert "shipTo" not in addresses.keys()
def test_taxes_need_new_fetch_uses_cached_data(checkout_with_item, address):