Add urllib quote to address validation
This commit is contained in:
parent
c09e166381
commit
05506503bf
@ -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)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user