def test_url_builder(self): self.assertEqual('http://example.com/segment1/segment2', utils.url_builder(['/http://example.com', 'segment1/', '/segment2'])) self.assertEqual('http://example.com/segment1/segment2', utils.url_builder(('/http://example.com', 'segment1/', '/segment2',))) with self.assertRaises(AssertionError): utils.url_builder('example.com')
def download(self, scenes): """Download Function from Google Storage Args: SceneID {data_tye: List} Retruns: Tarred landsat data files """ self.google = landsat.settings.GOOGLE_STORAGE # Check for the validity of SceneID for scene in scenes: # An empty list in accordance to landsat unique ID scene_anatomy = { 'path': None, 'row': None, 'sat': None, 'scene': scene } if isinstance(scene, str) and len(scene) == 21: scene_anatomy['path'] = scene[3:6] scene_anatomy['row'] = scene[6:9] scene_anatomy['sat'] = 'L' + scene[2:3] else: raise IncorrectSceneId('Bad List') # Create a folder to download tarred landsat Scenes path = check_create_folder(self.download_dir) filename = scene + '.tar.bz' print path print scene_anatomy # Builds the URL to a google storage file url = url_builder([self.google,scene_anatomy['sat'], scene_anatomy['path'], scene_anatomy['row'],filename]) print url # Downloads and save at the location defined under path fetch(url,path) return path