def test_verify_api_root_error(fake_urlopen):
    fake_urlopen = fake_urlopen.expects_call()
    req = """http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22foo_id%22%3E%3CAddress+ID%3D%220%22%3E%3CAddress1%2F%3E%3CAddress2%3E6406+Ivy+Lane%3C%2FAddress2%3E%3CCity%3EGreenbelt%3C%2FCity%3E%3CState%3EMD%3C%2FState%3E%3CZip5%2F%3E%3CZip4%2F%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E"""
    fake_urlopen = fake_urlopen.with_args(req)
    res = StringIO(u"""<Error>
        <Number>80040b1a</Number>
        <Description>Authorization failure.  Perhaps username and/or password is incorrect.</Description>
        <Source>UspsCom::DoAuth</Source>
</Error>""")
    fake_urlopen.returns(res)

    address = OrderedDict([
            ('address', '6406 Ivy Lane'),
            ('city', 'Greenbelt'),
            ('state', 'MD'),
            ])
    msg = assert_raises(
        ValueError,
        verify,
        'foo_id',
        address
        )

    expected = ('80040b1a: Authorization failure.  Perhaps username '
                'and/or password is incorrect.'
                )
    eq(str(msg), expected)
Пример #2
0
def test_verify_api_order_error(fake_urlopen):
    fake_urlopen = fake_urlopen.expects_call()
    req = """http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22foo_id%22%3E%3CAddress+ID%3D%220%22%3E%3CAddress1%2F%3E%3CAddress2%3E6406+Ivy+Lane%3C%2FAddress2%3E%3CCity%3EGreenbelt%3C%2FCity%3E%3CState%3EMD%3C%2FState%3E%3CZip5%2F%3E%3CZip4%2F%3E%3C%2FAddress%3E%3CAddress+ID%3D%221%22%3E%3CAddress1%2F%3E%3CAddress2%3E8+Wildwood+Drive%3C%2FAddress2%3E%3CCity%3EOld+Lyme%3C%2FCity%3E%3CState%3ECT%3C%2FState%3E%3CZip5%2F%3E%3CZip4%2F%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E"""
    fake_urlopen = fake_urlopen.with_args(req)
    res = StringIO("""<?xml version="1.0"?>
<AddressValidateResponse><Address ID="0"><Address2>6406 IVY LN</Address2><City>GREENBELT</City><State>MD</State><Zip5>20770</Zip5><Zip4>1441</Zip4></Address><Address ID="2"><Address2>8 WILDWOOD DR</Address2><City>OLD LYME</City><State>CT</State><Zip5>06371</Zip5><Zip4>1844</Zip4></Address></AddressValidateResponse>"""
                   )
    fake_urlopen.returns(res)

    addresses = [
        OrderedDict([
            ('address', '6406 Ivy Lane'),
            ('city', 'Greenbelt'),
            ('state', 'MD'),
        ]),
        OrderedDict([
            ('address', '8 Wildwood Drive'),
            ('city', 'Old Lyme'),
            ('state', 'CT'),
        ]),
    ]
    msg = assert_raises(IndexError, verify, 'foo_id', *addresses)

    expected = ('The addresses returned are not in the same order '
                'they were requested')
    eq(str(msg), expected)
def test_verify_api_order_error(fake_urlopen):
    fake_urlopen = fake_urlopen.expects_call()
    req = """http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22foo_id%22%3E%3CAddress+ID%3D%220%22%3E%3CAddress1%2F%3E%3CAddress2%3E6406+Ivy+Lane%3C%2FAddress2%3E%3CCity%3EGreenbelt%3C%2FCity%3E%3CState%3EMD%3C%2FState%3E%3CZip5%2F%3E%3CZip4%2F%3E%3C%2FAddress%3E%3CAddress+ID%3D%221%22%3E%3CAddress1%2F%3E%3CAddress2%3E8+Wildwood+Drive%3C%2FAddress2%3E%3CCity%3EOld+Lyme%3C%2FCity%3E%3CState%3ECT%3C%2FState%3E%3CZip5%2F%3E%3CZip4%2F%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E"""
    fake_urlopen = fake_urlopen.with_args(req)
    res = StringIO(u"""<?xml version="1.0"?>
<AddressValidateResponse><Address ID="0"><Address2>6406 IVY LN</Address2><City>GREENBELT</City><State>MD</State><Zip5>20770</Zip5><Zip4>1441</Zip4></Address><Address ID="2"><Address2>8 WILDWOOD DR</Address2><City>OLD LYME</City><State>CT</State><Zip5>06371</Zip5><Zip4>1844</Zip4></Address></AddressValidateResponse>""")
    fake_urlopen.returns(res)

    addresses = [
        OrderedDict([
                ('address', '6406 Ivy Lane'),
                ('city', 'Greenbelt'),
                ('state', 'MD'),
                ]),
        OrderedDict([
                ('address', '8 Wildwood Drive'),
                ('city', 'Old Lyme'),
                ('state', 'CT'),
                ]),
        ]
    msg = assert_raises(
        IndexError,
        verify,
        'foo_id',
        *addresses
        )

    expected = ('The addresses returned are not in the same order '
                'they were requested'
                )
    eq(str(msg), expected)
Пример #4
0
def test_verify_api_root_error(fake_urlopen):
    fake_urlopen = fake_urlopen.expects_call()
    req = """https://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22foo_id%22%3E%3CAddress+ID%3D%220%22%3E%3CAddress1%2F%3E%3CAddress2%3E6406+Ivy+Lane%3C%2FAddress2%3E%3CCity%3EGreenbelt%3C%2FCity%3E%3CState%3EMD%3C%2FState%3E%3CZip5%2F%3E%3CZip4%2F%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E"""
    fake_urlopen = fake_urlopen.with_args(req)
    res = StringIO(u"""<Error>
        <Number>80040b1a</Number>
        <Description>Authorization failure.  Perhaps username and/or password is incorrect.</Description>
        <Source>UspsCom::DoAuth</Source>
</Error>""")
    fake_urlopen.returns(res)

    address = OrderedDict([
            ('address', '6406 Ivy Lane'),
            ('city', 'Greenbelt'),
            ('state', 'MD'),
            ])
    msg = assert_raises(
        ValueError,
        verify,
        'foo_id',
        address
        )

    expected = ('80040b1a: Authorization failure.  Perhaps username '
                'and/or password is incorrect.'
                )
    eq(str(msg), expected)
Пример #5
0
def test_verify_more_than_5(fake_urlopen):
    addresses = [
        OrderedDict(),
        OrderedDict(),
        OrderedDict(),
        OrderedDict(),
        OrderedDict(),
        OrderedDict(),
    ]

    msg = assert_raises(ValueError, verify, 'foo_id', *addresses)

    eq(str(msg), 'Only 5 addresses are allowed per request')
Пример #6
0
def test_verify_api_empty_error(fake_urlopen):
    fake_urlopen = fake_urlopen.expects_call()
    req = """http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22foo_id%22%3E%3CAddress+ID%3D%220%22%3E%3CAddress1%2F%3E%3CAddress2%3E6406+Ivy+Lane%3C%2FAddress2%3E%3CCity%3EGreenbelt%3C%2FCity%3E%3CState%3ENJ%3C%2FState%3E%3CZip5%2F%3E%3CZip4%2F%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E"""
    fake_urlopen = fake_urlopen.with_args(req)
    res = StringIO("""<?xml version="1.0"?>
<AddressValidateResponse></AddressValidateResponse>""")
    fake_urlopen.returns(res)

    address = OrderedDict([
        ('address', '6406 Ivy Lane'),
        ('city', 'Greenbelt'),
        ('state', 'NJ'),
    ])
    msg = assert_raises(TypeError, verify, 'foo_id', address)

    expected = 'Could not find any address or error information'
    eq(str(msg), expected)
Пример #7
0
def test_verify_api_address_error_single(fake_urlopen):
    fake_urlopen = fake_urlopen.expects_call()
    req = """http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22foo_id%22%3E%3CAddress+ID%3D%220%22%3E%3CAddress1%2F%3E%3CAddress2%3E6406+Ivy+Lane%3C%2FAddress2%3E%3CCity%3EGreenbelt%3C%2FCity%3E%3CState%3ENJ%3C%2FState%3E%3CZip5%2F%3E%3CZip4%2F%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E"""
    fake_urlopen = fake_urlopen.with_args(req)
    res = StringIO("""<?xml version="1.0"?>
<AddressValidateResponse><Address ID="0"><Error><Number>-2147219401</Number><Source>API_AddressCleancAddressClean.CleanAddress2;SOLServer.CallAddressDll</Source><Description>Address Not Found.</Description><HelpFile></HelpFile><HelpContext>1000440</HelpContext></Error></Address></AddressValidateResponse>"""
                   )
    fake_urlopen.returns(res)

    address = OrderedDict([
        ('address', '6406 Ivy Lane'),
        ('city', 'Greenbelt'),
        ('state', 'NJ'),
    ])
    msg = assert_raises(ValueError, verify, 'foo_id', address)

    expected = '-2147219401: Address Not Found.'
    eq(str(msg), expected)
def test_verify_more_than_5(fake_urlopen):
    addresses = [
        OrderedDict(),
        OrderedDict(),
        OrderedDict(),
        OrderedDict(),
        OrderedDict(),
        OrderedDict(),
        ]

    msg = assert_raises(
        ValueError,
        verify,
        'foo_id',
        *addresses
        )

    eq(str(msg), 'Only 5 addresses are allowed per request')
def test_verify_api_empty_error(fake_urlopen):
    fake_urlopen = fake_urlopen.expects_call()
    req = """http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22foo_id%22%3E%3CAddress+ID%3D%220%22%3E%3CAddress1%2F%3E%3CAddress2%3E6406+Ivy+Lane%3C%2FAddress2%3E%3CCity%3EGreenbelt%3C%2FCity%3E%3CState%3ENJ%3C%2FState%3E%3CZip5%2F%3E%3CZip4%2F%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E"""
    fake_urlopen = fake_urlopen.with_args(req)
    res = StringIO(u"""<?xml version="1.0"?>
<AddressValidateResponse></AddressValidateResponse>""")
    fake_urlopen.returns(res)

    address = OrderedDict([
            ('address', '6406 Ivy Lane'),
            ('city', 'Greenbelt'),
            ('state', 'NJ'),
            ])
    msg = assert_raises(
        TypeError,
        verify,
        'foo_id',
        address
        )

    expected = 'Could not find any address or error information'
    eq(str(msg), expected)
Пример #10
0
def test_verify_api_address_error_single(fake_urlopen):
    fake_urlopen = fake_urlopen.expects_call()
    req = """http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22foo_id%22%3E%3CAddress+ID%3D%220%22%3E%3CAddress1%2F%3E%3CAddress2%3E6406+Ivy+Lane%3C%2FAddress2%3E%3CCity%3EGreenbelt%3C%2FCity%3E%3CState%3ENJ%3C%2FState%3E%3CZip5%2F%3E%3CZip4%2F%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E"""
    fake_urlopen = fake_urlopen.with_args(req)
    res = StringIO(u"""<?xml version="1.0"?>
<AddressValidateResponse><Address ID="0"><Error><Number>-2147219401</Number><Source>API_AddressCleancAddressClean.CleanAddress2;SOLServer.CallAddressDll</Source><Description>Address Not Found.</Description><HelpFile></HelpFile><HelpContext>1000440</HelpContext></Error></Address></AddressValidateResponse>""")
    fake_urlopen.returns(res)

    address = OrderedDict([
            ('address', '6406 Ivy Lane'),
            ('city', 'Greenbelt'),
            ('state', 'NJ'),
            ])
    msg = assert_raises(
        ValueError,
        verify,
        'foo_id',
        address
        )

    expected = '-2147219401: Address Not Found.'
    eq(str(msg), expected)
def test_verify_api_empty_error(fake_requests_get):
    req = """http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22foo_id%22%3E%3CAddress+ID%3D%220%22%3E%3CAddress1+%2F%3E%3CAddress2%3E6406+Ivy+Lane%3C%2FAddress2%3E%3CCity%3EGreenbelt%3C%2FCity%3E%3CState%3ENJ%3C%2FState%3E%3CZip5+%2F%3E%3CZip4+%2F%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E"""
    res = """<?xml version="1.0"?>
<AddressValidateResponse></AddressValidateResponse>"""

    (fake_requests_get.expects_call()
        .with_args(req)
        .returns(fudge.Fake('Response').has_attr(content=res)))

    address = OrderedDict([
        ('address', '6406 Ivy Lane'),
        ('city', 'Greenbelt'),
        ('state', 'NJ'),
    ])
    msg = assert_raises(
        TypeError,
        verify,
        'foo_id',
        address
    )

    expected = 'Could not find any address or error information'
    eq(str(msg), expected)