def test_todict_if_business_identification_no_is_set(self):
        doc = Document(DocType='SalesInvoice',
                       CustomerCode='123456789',
                       DocCode='12345',
                       CompanyCode='COMPANY_CODE')

        doc.BusinessIdentificationNo = 'GB999 999'

        doc.add_from_address(Line1='000 Main Street',
                             City='New York',
                             Region='NY',
                             Country='US',
                             PostalCode='10000')

        doc.add_to_address(Line1='001 Main Street',
                           Line2='',
                           City='New York',
                           Region='NY',
                           Country='US',
                           PostalCode='10000')

        doc.add_line(LineNo='1', ItemCode='123456789', Qty=1, Amount=str(100))

        dictionary = doc.todict()

        self.assertIn("BusinessIdentificationNo", dictionary.keys())
        self.assertEqual(dictionary.get("BusinessIdentificationNo"),
                         "GB999 999")
예제 #2
0
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='*****@*****.**')
    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
예제 #3
0
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='*****@*****.**')
    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
예제 #4
0
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='*****@*****.**')
    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