Esempio n. 1
0
def test_LabelXmlBuilder_exception_setLabelType():
    """Passing the wrong values to LabelXmlBuilder should throw a InvalidLabelValueError"""
    builder = LabelXmlBuilder()

    assert_raises(InvalidLabelValueError, builder.setLabelType, "wrong")
    assert_raises(InvalidLabelValueError, builder.setLabelSubType, "wrong")
    assert_raises(InvalidLabelValueError, builder.setLabelSize, "wrong")
    assert_raises(InvalidLabelValueError, builder.setImageFormat, "wrong")
    assert_raises(InvalidLabelValueError, builder.setImageResolution, "wrong")
    assert_raises(InvalidLabelValueError, builder.setMailClass, "wrong")
    assert_raises(InvalidLabelValueError, builder.setMailPieceShape, "wrong")
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 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_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 )
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
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"
Esempio n. 8
0
def test_LabelXmlBuilder_exception_setDateAdvance():
    """Passing a value outside of the [0,7] range should throw a InvalidLabelValueError"""
    builder = LabelXmlBuilder()

    assert_raises(InvalidLabelValueError, builder.setDateAdvance, -1)
    assert_raises(InvalidLabelValueError, builder.setDateAdvance, 8)
Esempio n. 9
0
    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
Esempio n. 10
0
def test_LabelXmlBuilder_test_shot_raise_the_required_exceptions_on_improper_values_or_missing_options(
):
    """This should raise certain exceptions at certain times to signify wrong parameters or missing options for the label 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

    builder = LabelXmlBuilder()
    xml = build_label()

    xml["LabelType"] = "Domestic"
    del xml["LabelSubType"]
    assert_raises(RequiredBecauseLabelValueError, builder.setByMap, xml)

    xml = build_label()
    del xml["AccountID"]
    assert_raises(RequiredLabelValueError, builder.setByMap, xml)

    xml = build_label()
    del xml["RequesterID"]
    assert_raises(RequiredLabelValueError, builder.setByMap, xml)

    xml = build_label()
    del xml["PassPhrase"]
    assert_raises(RequiredLabelValueError, builder.setByMap, xml)

    xml = build_label()
    del xml["WeightOz"]
    assert_raises(RequiredLabelValueError, builder.setByMap, xml)

    xml = build_label()
    del xml["MailpieceShape"]
    assert_raises(RequiredLabelValueError, builder.setByMap, xml)

    xml = build_label()
    del xml["MailpieceDimensions"]
    assert_raises(RequiredLabelValueError, builder.setByMap, xml)

    xml = build_label()
    del xml["ShipDate"]
    assert_raises(RequiredLabelValueError, builder.setByMap, xml)

    xml = build_label()
    del xml["ToAddress"]
    assert_raises(RequiredLabelValueError, builder.setByMap, xml)

    xml = build_label()
    del xml["FromAddress"]
    assert_raises(RequiredLabelValueError, builder.setByMap, xml)

    xml = build_label()
    del xml["PartnerCustomerID"]
    assert_raises(RequiredLabelValueError, builder.setByMap, xml)

    xml = build_label()
    del xml["PartnerTransactionID"]
    assert_raises(RequiredLabelValueError, builder.setByMap, xml)
Esempio n. 11
0
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)