Merge branch 'hotfix/address-xml-parse'
This commit is contained in:
commit
8d0788049a
@ -3,9 +3,10 @@ import requests
|
|||||||
import xmltodict
|
import xmltodict
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from usps import USPSApi
|
from usps import USPSApi as USPSApiBase
|
||||||
|
|
||||||
class USPSApiWithRate(USPSApi):
|
|
||||||
|
class USPSApi(USPSApiBase):
|
||||||
urls = {
|
urls = {
|
||||||
'tracking': 'TrackV2{test}&XML={xml}',
|
'tracking': 'TrackV2{test}&XML={xml}',
|
||||||
'label': 'eVS{test}&XML={xml}',
|
'label': 'eVS{test}&XML={xml}',
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
import os, time
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
from selenium.webdriver.firefox.webdriver import WebDriver
|
from selenium.webdriver.firefox.webdriver import WebDriver
|
||||||
from selenium.webdriver.common.keys import Keys
|
from selenium.webdriver.common.keys import Keys
|
||||||
from selenium.webdriver.support.ui import Select
|
from selenium.webdriver.support.ui import Select
|
||||||
@ -8,6 +10,7 @@ from selenium.webdriver.support.ui import WebDriverWait
|
|||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
|
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
|
||||||
|
|
||||||
|
|
||||||
class AddressTests(StaticLiveServerTestCase):
|
class AddressTests(StaticLiveServerTestCase):
|
||||||
fixtures = ['products.json']
|
fixtures = ['products.json']
|
||||||
|
|
||||||
@ -54,3 +57,35 @@ class AddressTests(StaticLiveServerTestCase):
|
|||||||
).text,
|
).text,
|
||||||
'USPS: Address Not Found.'
|
'USPS: Address Not Found.'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_address_is_url_safe(self):
|
||||||
|
self.browser.get(self.live_server_url + '/checkout/address/')
|
||||||
|
self.assertEqual(
|
||||||
|
self.browser.title,
|
||||||
|
'Checkout | Port Townsend Roasting Co.'
|
||||||
|
)
|
||||||
|
|
||||||
|
full_name_input = self.browser.find_element_by_name("full_name")
|
||||||
|
full_name_input.send_keys('John Doe')
|
||||||
|
email_input = self.browser.find_element_by_id('id_email')
|
||||||
|
email_input.send_keys('john@example.com')
|
||||||
|
street_address_1_input = self.browser.find_element_by_name('street_address_1')
|
||||||
|
street_address_1_input.send_keys('4031 N Douglas HWY #B')
|
||||||
|
city_input = self.browser.find_element_by_name('city')
|
||||||
|
city_input.send_keys('Juneau')
|
||||||
|
state_select = select = Select(self.browser.find_element_by_name('state'))
|
||||||
|
state_select.select_by_value('AK')
|
||||||
|
postal_code_input = self.browser.find_element_by_name('postal_code')
|
||||||
|
postal_code_input.send_keys('99801')
|
||||||
|
self.browser.find_element_by_xpath('//input[@value="Continue to Payment"]').click()
|
||||||
|
# try:
|
||||||
|
# WebDriverWait(self.browser, 4).until(
|
||||||
|
# EC.presence_of_element_located((By.CLASS_NAME, 'errorlist'))
|
||||||
|
# )
|
||||||
|
# finally:
|
||||||
|
# self.browser.quit()
|
||||||
|
|
||||||
|
self.assertRegex(
|
||||||
|
self.browser.current_url,
|
||||||
|
'^http://localhost:[0-9]*/checkout/$'
|
||||||
|
)
|
||||||
|
|||||||
@ -8,7 +8,7 @@ from django.shortcuts import redirect, reverse
|
|||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
|
|
||||||
from core.models import Product, OrderLine, Coupon
|
from core.models import Product, OrderLine, Coupon
|
||||||
from core.usps import USPSApiWithRate
|
from core.usps import USPSApi
|
||||||
from core import (
|
from core import (
|
||||||
DiscountValueType,
|
DiscountValueType,
|
||||||
VoucherType,
|
VoucherType,
|
||||||
@ -125,7 +125,7 @@ class Cart:
|
|||||||
usps_rate_request = self.build_usps_rate_request()
|
usps_rate_request = self.build_usps_rate_request()
|
||||||
except TypeError as e:
|
except TypeError as e:
|
||||||
return Decimal('0.00')
|
return Decimal('0.00')
|
||||||
usps = USPSApiWithRate(settings.USPS_USER_ID, test=True)
|
usps = USPSApi(settings.USPS_USER_ID, test=True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
validation = usps.get_rate(usps_rate_request)
|
validation = usps.get_rate(usps_rate_request)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
from requests import ConnectionError
|
from requests import ConnectionError
|
||||||
|
from urllib.parse import quote
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.mail import EmailMessage
|
from django.core.mail import EmailMessage
|
||||||
@ -74,12 +75,12 @@ class AddressForm(forms.Form):
|
|||||||
def clean(self):
|
def clean(self):
|
||||||
cleaned_data = super().clean()
|
cleaned_data = super().clean()
|
||||||
address = Address(
|
address = Address(
|
||||||
name=cleaned_data.get('full_name'),
|
name=quote(cleaned_data.get('full_name')),
|
||||||
address_1=cleaned_data.get('street_address_1'),
|
address_1=quote(cleaned_data.get('street_address_1')),
|
||||||
address_2=cleaned_data.get('street_address_2'),
|
address_2=quote(cleaned_data.get('street_address_2')),
|
||||||
city=cleaned_data.get('city'),
|
city=quote(cleaned_data.get('city')),
|
||||||
state=cleaned_data.get('state'),
|
state=quote(cleaned_data.get('state')),
|
||||||
zipcode=cleaned_data.get('postal_code')
|
zipcode=quote(cleaned_data.get('postal_code'))
|
||||||
)
|
)
|
||||||
usps = USPSApi(settings.USPS_USER_ID, test=True)
|
usps = USPSApi(settings.USPS_USER_ID, test=True)
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,9 @@ import sys
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from paypalcheckoutsdk.core import PayPalHttpClient, SandboxEnvironment, LiveEnvironment
|
from paypalcheckoutsdk.core import (
|
||||||
|
PayPalHttpClient, SandboxEnvironment, LiveEnvironment
|
||||||
|
)
|
||||||
from paypalcheckoutsdk.orders import OrdersCreateRequest, OrdersCaptureRequest
|
from paypalcheckoutsdk.orders import OrdersCreateRequest, OrdersCaptureRequest
|
||||||
from paypalhttp.serializers.json_serializer import Json
|
from paypalhttp.serializers.json_serializer import Json
|
||||||
|
|
||||||
@ -91,19 +93,14 @@ class CreateOrder(PayPalClient):
|
|||||||
processed_items = [
|
processed_items = [
|
||||||
{
|
{
|
||||||
# Shows within upper-right dropdown during payment approval
|
# Shows within upper-right dropdown during payment approval
|
||||||
"name": f'{item["product"]}: '
|
"name": f'{item["product"]}: ' + ', '.join([
|
||||||
", ".join(
|
next((
|
||||||
[
|
f"{value['quantity']} x {v[1]}"
|
||||||
next(
|
for i, v in enumerate(CoffeeGrind.GRIND_CHOICES)
|
||||||
(
|
if v[0] == key
|
||||||
f"{value['quantity']} x {v[1]}"
|
),
|
||||||
for i, v in enumerate(CoffeeGrind.GRIND_CHOICES)
|
None,
|
||||||
if v[0] == key
|
) for key, value in item["variations"].items()]
|
||||||
),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
for key, value in item["variations"].items()
|
|
||||||
]
|
|
||||||
)[:100],
|
)[:100],
|
||||||
# Item details will also be in the completed paypal.com
|
# Item details will also be in the completed paypal.com
|
||||||
# transaction view
|
# transaction view
|
||||||
|
|||||||
@ -21,8 +21,8 @@ class RequestFaker:
|
|||||||
},
|
},
|
||||||
'items': [
|
'items': [
|
||||||
{
|
{
|
||||||
'name': 'Decaf',
|
'name': 'Decaf: 1 x Whole Beans, 2 x Percolator',
|
||||||
'description': '1 x Whole Beans, 2 x Percolator',
|
'description': '',
|
||||||
'unit_amount': {'currency_code': 'USD', 'value': '13.40'},
|
'unit_amount': {'currency_code': 'USD', 'value': '13.40'},
|
||||||
'quantity': '3',
|
'quantity': '3',
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,7 @@ from . import RequestFaker
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CreateOrderTest(TestCase):
|
class CreateOrderTest(TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
@ -35,7 +36,6 @@ class CreateOrderTest(TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = Client()
|
self.client = Client()
|
||||||
|
|
||||||
|
|
||||||
def test_build_request_body(self):
|
def test_build_request_body(self):
|
||||||
product_list_url = reverse('storefront:product-list')
|
product_list_url = reverse('storefront:product-list')
|
||||||
response = self.client.get(product_list_url, follow=True)
|
response = self.client.get(product_list_url, follow=True)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user