def test_track_fedex(self): p = Package('012345678901234') try: p.track() except NotImplementedError: pass else: raise AssertionError('tracking fedex package should fail')
def track_shipment(shipment): """Receives a shipment object. Returns a dictionary of activities. activities = { 'shipment.id': [ {activity}, {activity} ] }""" activities = {} p = Package(shipment.tracking_no) activity_entries = p.track() activities[shipment.id] = activity_entries return activities
def test_track_ups(self): if not packagetrack.config.has_section('UPS'): raise SkipTest # This is just a random tracking number found on google. To find more, # google for something like: # ["Tracking Detail" site:wwwapps.ups.com inurl:WebTracking] p = Package('1Z58R4770350434926') info = p.track() assert info.status != '' assert isinstance(info.delivery_date, date) assert isinstance(info.last_update, datetime)
def test_track_ups(self): if not packagetrack.config.has_section('UPS'): raise SkipTest # This is just a random tracking number found on google. To find more, # google for something like: # ["Tracking Detail" site:wwwapps.ups.com inurl:WebTracking] p = Package('1Z12345E0291980793') info = p.track() assert info.status != '' assert isinstance(info.delivery_date, date) assert isinstance(info.last_update, datetime)
def request_email_body(messages): """Receives a list of dictionaries of message id's. Returns a dictionary of tracking numbers.""" for email in messages: url = "https://www.googleapis.com/gmail/v1/users/%s/messages/%s" % (session.get('user_email'), email["id"]) response = gmail.get(url) base64url_encoded_string = response.data["payload"]["body"]["data"] decoded = base64.b64decode(base64url_encoded_string.replace('-', '/')).replace('_', '+') tracking_number = parse_tracking_number(decoded) p = Package(tracking_number) return p.url()
def track(): tracking_number = request.args.get('tn', '') if not tracking_number: return redirect(url_for('index')) p = Package(tracking_number) status_list = p.track() locations = [email_helper.parse_location_no_save(loc) for loc in status_list] cities = ['{city}, {state}'.format(city=loc.get('city'), state=loc.get('state')) for loc in locations if loc.get('city') is not None and loc.get('state') is not None] return render_template("track.html", shipment=p, locations=locations, cities=json.dumps(cities), GOOGLE_MAPS=app.config.get('GOOGLE_MAPS'))
def test_track_unknown(self): try: Package('12391241248').track() except UnsupportedShipper: pass else: raise AssertionError("tracking package with unknown " "shipper should fail")
def test_ups_url(self): num = '1Z9999999999999999' url = Package(num).url() assert num in url assert url.startswith('http')
def test_usps_url(self): num = '91124235' url = Package(num).url() assert num in url assert url.startswith('http')
def test_identify_unknown(self): assert Package('14324423523').shipper == None
def test_fedex_url(self): num = '012345678901234' url = Package(num).url() assert num in url assert url.startswith('http')
def test_identify_usps(self): assert Package('91124235').shipper == 'USPS'
def test_identify_fedex(self): assert Package('012345678901234').shipper == 'FedEx'
def test_identify_ups(self): assert Package('1Z9999999999999999').shipper == 'UPS'
def test_validate_ups(self): assert Package('1Z58R4770350889570').validate() assert not Package('1Z58R4770350889572').validate()
def test_usps_validate(self): assert Package('9405503699300451135169').validate() assert not Package('9405503699300451134169').validate()