本文整理汇总了Python中pyavatax.base.Document.add_line方法的典型用法代码示例。如果您正苦于以下问题:Python Document.add_line方法的具体用法?Python Document.add_line怎么用?Python Document.add_line使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyavatax.base.Document
的用法示例。
在下文中一共展示了Document.add_line方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_validation
# 需要导入模块: from pyavatax.base import Document [as 别名]
# 或者: from pyavatax.base.Document import add_line [as 别名]
def test_validation():
try:
doc = Document(DocDate='foo') # testing date
except AvalaraException:
assert True
else:
assert False
try:
doc = Line(Qty='foo') # testing int
except AvalaraException:
assert True
else:
assert False
try:
doc = Line(Amount='foo') # testing float
except AvalaraException:
assert True
else:
assert False
doc = Document.new_sales_order(DocCode='1001', DocDate=datetime.date.today(), CustomerCode='[email protected]')
try:
doc.validate()
except AvalaraException:
assert True
else:
assert False
from_address = Address(Line1="435 Ericksen Avenue Northeast", Line2="#250", PostalCode="98110")
to_address = Address(Line1="435 Ericksen Avenue Northeast", Line2="#250", PostalCode="98110")
doc.add_from_address(from_address)
doc.add_to_address(to_address)
try:
doc.validate()
except AvalaraException:
assert True
else:
assert False
try:
doc.add_from_address(from_address)
except AvalaraException:
assert True
else:
assert False
try:
doc.add_to_address(from_address)
except AvalaraException:
assert True
else:
assert False
line = Line(Amount=10.00)
doc.add_line(line)
try:
doc.validate()
except AvalaraException:
assert False
示例2: test_timeout
# 需要导入模块: from pyavatax.base import Document [as 别名]
# 或者: from pyavatax.base.Document import add_line [as 别名]
def test_timeout():
api = get_api(timeout=0.00001)
lat = 47.627935
lng = -122.51702
line = Line(Amount=10.00)
doc = Document()
doc.add_line(line)
try:
api.get_tax(lat, lng, doc)
except AvalaraServerNotReachableException:
assert True
else:
assert False
示例3: test_gettax
# 需要导入模块: from pyavatax.base import Document [as 别名]
# 或者: from pyavatax.base.Document import add_line [as 别名]
def test_gettax():
api = get_api()
# A Lat/Long from Avalara's documentation
lat = 47.627935
lng = -122.51702
line = Line(Amount=10.00)
doc = Document()
doc.add_line(line)
tax = api.get_tax(lat, lng, doc)
assert tax.is_success is True
assert tax.Tax > 0
assert tax.total_tax == tax.Tax
tax = api.get_tax(lat, lng, None, sale_amount=10.00)
assert tax.is_success is True
assert tax.Tax > 0
assert tax.total_tax == tax.Tax
示例4: test_timeout
# 需要导入模块: from pyavatax.base import Document [as 别名]
# 或者: from pyavatax.base.Document import add_line [as 别名]
def test_timeout():
with LogCapture('pyavatax.api') as l:
api = get_api(timeout=0.00001)
lat = 47.627935
lng = -122.51702
line = Line(Amount=10.00)
doc = Document()
doc.add_line(line)
try:
api.get_tax(lat, lng, doc)
except AvalaraServerNotReachableException:
assert True
else:
assert False
l.check(
('pyavatax.api', 'DEBUG', 'None inserting LineNo 1'),
('pyavatax.api', 'WARNING', "HTTPSConnectionPool(host='development.avalara.net', port=443): Request timed out. (timeout=1e-05)")
)
示例5: test_validation
# 需要导入模块: from pyavatax.base import Document [as 别名]
# 或者: from pyavatax.base.Document import add_line [as 别名]
def test_validation():
with pytest.raises(AvalaraValidationException) as e:
doc = Document(DocDate='foo') # testing date
assert e.value.code == AvalaraException.CODE_BAD_DATE
with pytest.raises(AvalaraValidationException) as e:
line = Line(Qty='foo') # testing int
assert e.value.code == AvalaraException.CODE_BAD_FLOAT
with pytest.raises(AvalaraValidationException) as e:
line = Line(Amount='foo') # testing float
assert e.value.code == AvalaraException.CODE_BAD_FLOAT
with pytest.raises(AvalaraValidationException) as e:
line = Line(ItemCode='this string is longer than fifty characters and should be stopped') # testing length
assert e.value.code == AvalaraException.CODE_TOO_LONG
doc = Document.new_sales_order(DocCode='1001', DocDate=datetime.date.today(), CustomerCode='[email protected]')
with pytest.raises(AvalaraValidationException) as e:
doc.validate()
assert e.value.code == AvalaraException.CODE_BAD_ADDRESS
from_address = Address(Line1="435 Ericksen Avenue Northeast", Line2="#250", PostalCode="98110")
to_address = Address(Line1="435 Ericksen Avenue Northeast", Line2="#250", PostalCode="98110")
doc.add_from_address(from_address)
doc.add_to_address(to_address)
with pytest.raises(AvalaraValidationException) as e:
doc.validate()
assert e.value.code == AvalaraException.CODE_BAD_LINE
with pytest.raises(AvalaraException) as e:
doc.add_from_address(from_address)
assert e.value.code == AvalaraException.CODE_HAS_FROM
with pytest.raises(AvalaraException) as e:
doc.add_to_address(to_address)
assert e.value.code == AvalaraException.CODE_HAS_TO
line = Line(Amount=10.00)
doc.add_line(line)
doc.validate()
api = get_api()
lat = 47.627935
lng = -122.51702
with pytest.raises(AvalaraTypeException) as e:
api.get_tax(lat, lng, 'foo', None)
assert e.value.code == AvalaraException.CODE_BAD_DOC
with pytest.raises(AvalaraException) as e:
api.get_tax(lat, lng, None, None)
assert e.value.code == AvalaraException.CODE_BAD_ARGS