def test_blob_creation(self): import imghdr, StringIO data = 'some_image_data' when(StringIO).StringIO(data).thenReturn('data_file') when(imghdr).what('data_file').thenReturn('jpeg') image = Image.create(data=data) reader = BlobReader(image.blob_key) self.assertEqual(data, reader.read()) image = image.key.get() self.assertEqual('image/jpeg', image.format)
def send_property_notification(property_listing, item_url): recipients_config = feed_config_connector.get_alert_recipients() recipients = ["%s <%s>" % (_['name'], _['email']) for _ in recipients_config] property_type_map = { 'apartment': "Apartment", 'condo': "Condo", 'cottage/cabin': "Cottage/Cabin", 'duplex': "Duplex", 'flat': "Flat", 'house': "House", 'in-law': "In-Law", 'townhouse': "Townhouse" } # TODO: use app_identity sender_address = "Rental Bot <*****@*****.**>" property_type = property_listing.property_types[0] \ if property_listing.property_types else "Property" property_type_description = property_type_map.get(property_type, property_type) formatted_address = "%s, %s, %s %s" % ( property_listing.address, property_listing.city, property_listing.state_code, property_listing.postal_code ) geo = property_listing.geo subject = "%s in %s (%s)" % ( property_type_description, property_listing.neighborhood, property_listing.address ) message = mail.EmailMessage( sender=sender_address, subject=subject, to=recipients ) message.body = item_url message.html = """<a href="{}">{}</a><br/> <br/> <a href="https://www.google.com/maps/place/{}/@{}">Google Maps</a><br/> """.format( item_url, property_listing.title.encode('utf-8'), urllib.quote_plus(formatted_address), "%s,%s" % (geo.lat, geo.lon) ) blob_reader = BlobReader(property_listing.image.original_jpeg_blob_key) message.attachments=[("property.jpg", blob_reader.read())] message.send()
def get(self): fileName = self.request.url[self.request.url.rfind('/')+1:] file = File.get_by_key_name(fileName) if file is None: self.error(404) return blob_key = file.blobKey.key() blob_reader = BlobReader(blob_key) value = blob_reader.read() #TODO : test as it is not recommended for big files (https://developers.google.com/appengine/docs/python/blobstore/blobreaderclass) self.response.headers['Content-Type'] = 'application/octet-stream' self.response.out.write(value);