|
| 1 | +"""Testing the create label from shipment functionality.""" |
| 2 | +import json |
| 3 | +import unittest |
| 4 | +import urllib.parse as urlparse |
| 5 | + |
| 6 | +import responses |
| 7 | + |
| 8 | +from shipengine.enums import BaseURL, Endpoints |
| 9 | +from tests.util import stub_shipengine_instance |
| 10 | + |
| 11 | + |
| 12 | +class TestCreateLabelFromShipment(unittest.TestCase): |
| 13 | + def test_create_label_from_shipment(self) -> None: |
| 14 | + """Test purchase label from shipment.""" |
| 15 | + responses.add( |
| 16 | + **{ |
| 17 | + "method": responses.POST, |
| 18 | + "url": urlparse.urljoin( |
| 19 | + BaseURL.SHIPENGINE_RPC_URL.value, Endpoints.GET_RATE_FROM_SHIPMENT.value |
| 20 | + ), |
| 21 | + "body": json.dumps( |
| 22 | + { |
| 23 | + "label_id": "se-75714944", |
| 24 | + "status": "completed", |
| 25 | + "shipment_id": "se-144835189", |
| 26 | + "ship_date": "2021-08-05T00:00:00Z", |
| 27 | + "created_at": "2021-08-05T18:01:46.0013168Z", |
| 28 | + "shipment_cost": {"currency": "usd", "amount": 27.98}, |
| 29 | + "insurance_cost": {"currency": "usd", "amount": 0.0}, |
| 30 | + "tracking_number": "1Z63R0960311549776", |
| 31 | + "is_return_label": False, |
| 32 | + "rma_number": None, |
| 33 | + "is_international": False, |
| 34 | + "batch_id": "", |
| 35 | + "carrier_id": "se-656172", |
| 36 | + "service_code": "ups_ground", |
| 37 | + "package_code": "package", |
| 38 | + "voided": False, |
| 39 | + "voided_at": None, |
| 40 | + "label_format": "pdf", |
| 41 | + "display_scheme": "label", |
| 42 | + "label_layout": "4x6", |
| 43 | + "trackable": True, |
| 44 | + "label_image_id": None, |
| 45 | + "carrier_code": "ups", |
| 46 | + "tracking_status": "in_transit", |
| 47 | + "label_download": { |
| 48 | + "pdf": "https://api.shipengine.com/v1/downloads/10/nRpNbEgTzkaBB1HitZNfjQ/label-75714944.pdf", # noqa |
| 49 | + "png": "https://api.shipengine.com/v1/downloads/10/nRpNbEgTzkaBB1HitZNfjQ/label-75714944.png", # noqa |
| 50 | + "zpl": "https://api.shipengine.com/v1/downloads/10/nRpNbEgTzkaBB1HitZNfjQ/label-75714944.zpl", # noqa |
| 51 | + "href": "https://api.shipengine.com/v1/downloads/10/nRpNbEgTzkaBB1HitZNfjQ/label-75714944.pdf", # noqa |
| 52 | + }, |
| 53 | + "form_download": None, |
| 54 | + "insurance_claim": None, |
| 55 | + "packages": [ |
| 56 | + { |
| 57 | + "package_id": 80350838, |
| 58 | + "package_code": "package", |
| 59 | + "weight": {"value": 20.0, "unit": "ounce"}, |
| 60 | + "dimensions": { |
| 61 | + "unit": "inch", |
| 62 | + "length": 24.0, |
| 63 | + "width": 12.0, |
| 64 | + "height": 6.0, |
| 65 | + }, |
| 66 | + "insured_value": {"currency": "usd", "amount": 0.0}, |
| 67 | + "tracking_number": "1Z63R0960311549776", |
| 68 | + "label_messages": { |
| 69 | + "reference1": None, |
| 70 | + "reference2": None, |
| 71 | + "reference3": None, |
| 72 | + }, |
| 73 | + "external_package_id": None, |
| 74 | + "sequence": 1, |
| 75 | + } |
| 76 | + ], |
| 77 | + "charge_event": "carrier_default", |
| 78 | + } |
| 79 | + ), |
| 80 | + "status": 200, |
| 81 | + "content_type": "application/json", |
| 82 | + } |
| 83 | + ) |
| 84 | + |
| 85 | + shipengine = stub_shipengine_instance() |
| 86 | + result = shipengine.create_label_from_shipment( |
| 87 | + shipment={ |
| 88 | + "shipment": { |
| 89 | + "service_code": "ups_ground", |
| 90 | + "ship_to": { |
| 91 | + "name": "Jane Doe", |
| 92 | + "address_line1": "525 S Winchester Blvd", |
| 93 | + "city_locality": "San Jose", |
| 94 | + "state_province": "CA", |
| 95 | + "postal_code": "95128", |
| 96 | + "country_code": "US", |
| 97 | + "address_residential_indicator": "yes", |
| 98 | + }, |
| 99 | + "ship_from": { |
| 100 | + "name": "John Doe", |
| 101 | + "company_name": "Example Corp", |
| 102 | + "phone": "555-555-5555", |
| 103 | + "address_line1": "4009 Marathon Blvd", |
| 104 | + "city_locality": "Austin", |
| 105 | + "state_province": "TX", |
| 106 | + "postal_code": "78756", |
| 107 | + "country_code": "US", |
| 108 | + "address_residential_indicator": "no", |
| 109 | + }, |
| 110 | + "packages": [ |
| 111 | + { |
| 112 | + "weight": {"value": 20, "unit": "ounce"}, |
| 113 | + "dimensions": { |
| 114 | + "height": 6, |
| 115 | + "width": 12, |
| 116 | + "length": 24, |
| 117 | + "unit": "inch", |
| 118 | + }, |
| 119 | + } |
| 120 | + ], |
| 121 | + } |
| 122 | + } |
| 123 | + ) |
| 124 | + self.assertEqual(result["status"], "completed") |
0 commit comments