def build_label(): def mockToAddress(): ret = ( E.ToCompany("fake"), E.ToAddress1("1234 Fake St"), E.ToAddress2("Apartment 1"), E.ToCity("Faketilly"), E.ToState("VA"), E.ToPostalCode("12345"), ) return ret def mockFromAddress(): ret = ( E.FromName("Fakeson"), E.FromCompany("Fake company"), E.ReturnAddress1("12345 Fake ave."), E.ReturnAddress2("Room 10"), E.FromCity("Fakeville"), E.FromState("VA"), E.FromPostalCode("12345"), ) return ret builder = LabelXmlBuilder() builder.setTest() builder.setLabelType("Default") builder.setLabelSubType("None") builder.setLabelSize("4x6") builder.setImageFormat("JPEG") builder.setImageResolution("300") builder.setRequestID("123456") builder.setAccountID("123456") builder.setPassPhrase("x") builder.setMailClass("First") builder.setDateAdvance(0) builder.setWeightOunces(4.1) builder.setMailPieceShape("Letter") builder.setDimensions((10, 10, 0.5)) builder.setToAddress(mockToAddress) builder.setFromAddress(mockFromAddress) builder.setShipDate("10/7/2012") builder.setPartnerCustomerID("123456") builder.setPartnerTransactionID("123456") return builder.xml
def build_label(): def mockToAddress(): ret = ( E.ToCompany( "fake" ), E.ToAddress1( "1234 Fake St" ), E.ToAddress2( "Apartment 1" ), E.ToCity( "Faketilly" ), E.ToState( "VA" ), E.ToPostalCode( "12345" ), ) return ret def mockFromAddress(): ret = ( E.FromName( "Fakeson" ), E.FromCompany( "Fake company" ), E.ReturnAddress1( "12345 Fake ave." ), E.ReturnAddress2( "Room 10" ), E.FromCity( "Fakeville" ), E.FromState( "VA" ), E.FromPostalCode( "12345" ), ) return ret builder = LabelXmlBuilder() builder.setTest() builder.setLabelType( "Default" ) builder.setLabelSubType( "None" ) builder.setLabelSize( "4x6" ) builder.setImageFormat( "JPEG" ) builder.setImageResolution( "300" ) builder.setRequestID( "123456" ) builder.setAccountID( "123456" ) builder.setPassPhrase( "x" ) builder.setMailClass( "First" ) builder.setDateAdvance( 0 ) builder.setWeightOunces( 4.1 ) builder.setMailPieceShape( "Letter" ) builder.setDimensions( ( 10, 10, 0.5 ) ) builder.setToAddress( mockToAddress ) builder.setFromAddress( mockFromAddress ) builder.setShipDate( "10/7/2012" ) builder.setPartnerCustomerID( "123456" ) builder.setPartnerTransactionID( "123456" ) return builder.xml
def test_LavelXmlBuilder_to_xml(): """The to_string() should return a valid XML request""" def mockToAddress(): ret = ( #E.ToCompany( "fake" ), E.ToAddress1( "1234 Fake St" ), E.ToAddress2( "Apartment 1" ), E.ToCity( "Faketilly" ), E.ToState( "VA" ), E.ToPostalCode( "12345" ), #E.ToZIP4( "1234" ), #E.ToPhone( "1234567890" ), #E.ToEMail( "*****@*****.**" ) ) return ret def mockFromAddress(): ret = ( E.FromName( "Fakeson" ), #E.FromCompany( "Fake company" ), E.ReturnAddress1( "12345 Fake ave." ), E.ReturnAddress2( "Room 10" ), E.FromCity( "Fakeville" ), E.FromState( "VA" ), E.FromPostalCode( "12345" ), #E.FromZIP4( "1234" ), #E.FromPhone( "1234567890" ) ) return ret builder = LabelXmlBuilder() builder.setTest() builder.setLabelType( "Default" ) builder.setLabelSubType( "None" ) builder.setLabelSize( "4x6" ) builder.setImageFormat( "JPEG" ) builder.setImageResolution( "300" ) builder.setRequestID( "123456" ) builder.setAccountID( "123456" ) builder.setPassPhrase( "x" ) builder.setMailClass( "First" ) builder.setDateAdvance( 0 ) builder.setWeightOunces( 4.1 ) builder.setMailPieceShape( "Parcel" ) builder.setDimensions( ( 10, 10, 0.5 ) ) builder.setToAddress( mockToAddress ) builder.setFromAddress( mockFromAddress ) builder.setPartnerCustomerID( "123456" ) builder.setPartnerTransactionID( "123456" ) ret = builder.to_xml() assert ret.tag == "LabelRequest" assert ret[0].tag == "Test" #assert ret[1].tag == "LabelType" #assert ret[2].tag == "LabelSubType" assert ret[1].tag == "LabelSize" assert ret[2].tag == "ImageFormat" assert ret[3].tag == "ImageResolution" assert ret[4].tag == "RequesterID" assert ret[5].tag == "AccountID" assert ret[6].tag == "PassPhrase" assert ret[7].tag == "MailClass" #assert ret[10].tag == "DateAdvance" assert ret[8].tag == "WeightOz" assert ret[9].tag == "MailpieceShape" assert ret[10].tag == "PartnerCustomerID" assert ret[11].tag == "PartnerTransactionID" assert ret[12].tag == "LabelType" assert ret[13].tag == "LabelSubType" assert ret[14].tag == "MailpieceDimensions"
def test_LabelXmlBuilder_test_should_notn_raise_exception_when_setup_from_correct_map(): """This should not raise any exceptions because the information is valid""" def mockToAddress(): ret = ( E.ToCompany( "fake" ), E.ToAddress1( "1234 Fake St" ), E.ToAddress2( "Apartment 1" ), E.ToCity( "Faketilly" ), E.ToState( "VA" ), E.ToPostalCode( "12345" ), #E.ToZIP4( "1234" ), #E.ToPhone( "1234567890" ), #E.ToEMail( "*****@*****.**" ) ) return ret def mockFromAddress(): ret = ( E.FromName( "Fakeson" ), E.FromCompany( "Fake company" ), E.ReturnAddress1( "12345 Fake ave." ), E.ReturnAddress2( "Room 10" ), E.FromCity( "Fakeville" ), E.FromState( "VA" ), E.FromPostalCode( "12345" ), #E.FromZIP4( "1234" ), #E.FromPhone( "1234567890" ) ) return ret builder = LabelXmlBuilder() builder.setTest() builder.setLabelType( "Default" ) builder.setLabelSubType( "None" ) builder.setLabelSize( "4x6" ) builder.setImageFormat( "JPEG" ) builder.setImageResolution( "300" ) builder.setRequestID( "123456" ) builder.setAccountID( "123456" ) builder.setPassPhrase( "x" ) builder.setMailClass( "First" ) builder.setDateAdvance( 0 ) builder.setWeightOunces( 4.1 ) builder.setMailPieceShape( "Letter" ) builder.setDimensions( ( 10, 10, 0.5 ) ) builder.setToAddress( mockToAddress ) builder.setFromAddress( mockFromAddress ) builder.setShipDate( "10/7/2012" ) builder.setPartnerCustomerID( "123456" ) builder.setPartnerTransactionID( "123456" ) _map = builder.xml def test_closure(): global _xml try: builder.setByMap( _map ) raise Exception( "Everything is fine" ) except: raise InvalidLabelValueError( "" ) assert_raises( Exception, test_closure )
def test_LabelRequest_make_request(): """LabelRequest should return a successful request with a status == 0 and a proper label returned""" request = LabelRequest() def mockToAddress(): ret = ( #E.ToCompany( "fake" ), E.ToName("Sean"), E.ToAddress1("123 Fake"), E.ToAddress2(""), E.ToCity("faketilly"), E.ToState("VA"), E.ToPostalCode("20000"), #E.ToZIP4( "1234" ), #E.ToPhone( "1234567890" ), #E.ToEMail( "*****@*****.**" ) ) return ret def mockFromAddress(): ret = ( E.FromName("David"), #E.FromCompany( "Fake company" ), E.ReturnAddress1("123 fake"), E.ReturnAddress2(""), E.FromCity("faketilly"), E.FromState("VA"), E.FromPostalCode("20000"), #E.FromZIP4( "1234" ), #E.FromPhone( "1234567890" ) ) return ret builder = LabelXmlBuilder() builder.setTest() builder.setLabelType("Domestic") builder.setLabelSubType("None") builder.setLabelSize("4x6") builder.setImageFormat("JPEG") builder.setImageResolution("300") builder.setRequestID("123456") builder.setAccountID("123456") builder.setPassPhrase("x") builder.setMailClass("First") builder.setDateAdvance(0) builder.setWeightOunces(4.1) builder.setMailPieceShape("Parcel") builder.setDimensions((10.0, 10.0, 1)) builder.setToAddress(mockToAddress) builder.setFromAddress(mockFromAddress) builder.setPartnerCustomerID("123456") builder.setPartnerTransactionID("123456") _map = request.get(builder) dumpToFile("test/data/test_images/test_domestic.jpg", _map["Base64LabelImage"]) assert _map["Status"] == 0 builder.setLabelType("Default") _map = request.get(builder) dumpToFile("test/data/test_images/test_default.jpg", _map["Base64LabelImage"]) assert _map["Status"] == 0
def test_LabelRequest_make_request(): """LabelRequest should return a successful request with a status == 0 and a proper label returned""" request = LabelRequest() def mockToAddress(): ret = ( #E.ToCompany( "fake" ), E.ToName( "Sean" ), E.ToAddress1( "123 Fake" ), E.ToAddress2( "" ), E.ToCity( "faketilly" ), E.ToState( "VA" ), E.ToPostalCode( "20000" ), #E.ToZIP4( "1234" ), #E.ToPhone( "1234567890" ), #E.ToEMail( "*****@*****.**" ) ) return ret def mockFromAddress(): ret = ( E.FromName( "David" ), #E.FromCompany( "Fake company" ), E.ReturnAddress1( "123 fake" ), E.ReturnAddress2( "" ), E.FromCity( "faketilly" ), E.FromState( "VA" ), E.FromPostalCode( "20000" ), #E.FromZIP4( "1234" ), #E.FromPhone( "1234567890" ) ) return ret builder = LabelXmlBuilder() builder.setTest() builder.setLabelType( "Domestic" ) builder.setLabelSubType( "None" ) builder.setLabelSize( "4x6" ) builder.setImageFormat( "JPEG" ) builder.setImageResolution( "300" ) builder.setRequestID( "123456" ) builder.setAccountID( "123456" ) builder.setPassPhrase( "x" ) builder.setMailClass( "First" ) builder.setDateAdvance( 0 ) builder.setWeightOunces( 4.1 ) builder.setMailPieceShape( "Parcel" ) builder.setDimensions( ( 10.0, 10.0, 1 ) ) builder.setToAddress( mockToAddress ) builder.setFromAddress( mockFromAddress ) builder.setPartnerCustomerID( "123456" ) builder.setPartnerTransactionID( "123456" ) _map = request.get( builder ) dumpToFile( "test/data/test_images/test_domestic.jpg", _map["Base64LabelImage"] ) assert _map["Status"] == 0 builder.setLabelType( "Default" ) _map = request.get( builder ) dumpToFile( "test/data/test_images/test_default.jpg", _map["Base64LabelImage"] ) assert _map["Status"] == 0
def test_LavelXmlBuilder_to_xml(): """The to_string() should return a valid XML request""" def mockToAddress(): ret = ( #E.ToCompany( "fake" ), E.ToAddress1("1234 Fake St"), E.ToAddress2("Apartment 1"), E.ToCity("Faketilly"), E.ToState("VA"), E.ToPostalCode("12345"), #E.ToZIP4( "1234" ), #E.ToPhone( "1234567890" ), #E.ToEMail( "*****@*****.**" ) ) return ret def mockFromAddress(): ret = ( E.FromName("Fakeson"), #E.FromCompany( "Fake company" ), E.ReturnAddress1("12345 Fake ave."), E.ReturnAddress2("Room 10"), E.FromCity("Fakeville"), E.FromState("VA"), E.FromPostalCode("12345"), #E.FromZIP4( "1234" ), #E.FromPhone( "1234567890" ) ) return ret builder = LabelXmlBuilder() builder.setTest() builder.setLabelType("Default") builder.setLabelSubType("None") builder.setLabelSize("4x6") builder.setImageFormat("JPEG") builder.setImageResolution("300") builder.setRequestID("123456") builder.setAccountID("123456") builder.setPassPhrase("x") builder.setMailClass("First") builder.setDateAdvance(0) builder.setWeightOunces(4.1) builder.setMailPieceShape("Parcel") builder.setDimensions((10, 10, 0.5)) builder.setToAddress(mockToAddress) builder.setFromAddress(mockFromAddress) builder.setPartnerCustomerID("123456") builder.setPartnerTransactionID("123456") ret = builder.to_xml() assert ret.tag == "LabelRequest" assert ret[0].tag == "Test" #assert ret[1].tag == "LabelType" #assert ret[2].tag == "LabelSubType" assert ret[1].tag == "LabelSize" assert ret[2].tag == "ImageFormat" assert ret[3].tag == "ImageResolution" assert ret[4].tag == "RequesterID" assert ret[5].tag == "AccountID" assert ret[6].tag == "PassPhrase" assert ret[7].tag == "MailClass" #assert ret[10].tag == "DateAdvance" assert ret[8].tag == "WeightOz" assert ret[9].tag == "MailpieceShape" assert ret[10].tag == "PartnerCustomerID" assert ret[11].tag == "PartnerTransactionID" assert ret[12].tag == "LabelType" assert ret[13].tag == "LabelSubType" assert ret[14].tag == "MailpieceDimensions"
def test_LabelXmlBuilder_test_should_notn_raise_exception_when_setup_from_correct_map( ): """This should not raise any exceptions because the information is valid""" def mockToAddress(): ret = ( E.ToCompany("fake"), E.ToAddress1("1234 Fake St"), E.ToAddress2("Apartment 1"), E.ToCity("Faketilly"), E.ToState("VA"), E.ToPostalCode("12345"), #E.ToZIP4( "1234" ), #E.ToPhone( "1234567890" ), #E.ToEMail( "*****@*****.**" ) ) return ret def mockFromAddress(): ret = ( E.FromName("Fakeson"), E.FromCompany("Fake company"), E.ReturnAddress1("12345 Fake ave."), E.ReturnAddress2("Room 10"), E.FromCity("Fakeville"), E.FromState("VA"), E.FromPostalCode("12345"), #E.FromZIP4( "1234" ), #E.FromPhone( "1234567890" ) ) return ret builder = LabelXmlBuilder() builder.setTest() builder.setLabelType("Default") builder.setLabelSubType("None") builder.setLabelSize("4x6") builder.setImageFormat("JPEG") builder.setImageResolution("300") builder.setRequestID("123456") builder.setAccountID("123456") builder.setPassPhrase("x") builder.setMailClass("First") builder.setDateAdvance(0) builder.setWeightOunces(4.1) builder.setMailPieceShape("Letter") builder.setDimensions((10, 10, 0.5)) builder.setToAddress(mockToAddress) builder.setFromAddress(mockFromAddress) builder.setShipDate("10/7/2012") builder.setPartnerCustomerID("123456") builder.setPartnerTransactionID("123456") _map = builder.xml def test_closure(): global _xml try: builder.setByMap(_map) raise Exception("Everything is fine") except: raise InvalidLabelValueError("") assert_raises(Exception, test_closure)