def cbers(path, row, sensor='MUX'): """Get CBERS scenes. Valid values for sensor are: 'MUX', 'AWFI', 'PAN5M' and 'PAN10M'. """ path = utils.zeroPad(path, 3) row = utils.zeroPad(row, 3) prefix = f'CBERS4/{sensor}/{path}/{row}/' session = boto3_session(region_name=region) s3 = session.client('s3') results = aws.list_directory(cbers_bucket, prefix, s3=s3) scene_ids = [os.path.basename(key.strip('/')) for key in results] results = [] for scene_id in scene_ids: info = utils.cbers_parse_scene_id(scene_id) scene_key = info["key"] preview_id = '_'.join(scene_id.split('_')[0:-1]) info[ 'thumbURL'] = f'https://s3.amazonaws.com/{cbers_bucket}/{scene_key}/{preview_id}_small.jpeg' info[ 'browseURL'] = f'https://s3.amazonaws.com/{cbers_bucket}/{scene_key}/{preview_id}.jpg' results.append(info) return results
def test_aws_list_directory_awserror(session): """Should raise an 'ClientError' error """ session.return_value.client.return_value.get_paginator.return_value.paginate.side_effect = [ ClientError({'Error': { 'Code': 500, 'Message': 'Error' }}, 'list_objects_v2') ] bucket = "landsat-pds" prefix = "L8/178/246/" with pytest.raises(ClientError): aws.list_directory(bucket, prefix)
def test_aws_list_directory_nodir(session): """Should return an empty list """ session.return_value.client.return_value.get_paginator.return_value.paginate.return_value = [ {} ] bucket = "landsat-pds" prefix = "L8/178/246/" assert not aws.list_directory(bucket, prefix)
def test_aws_list_directory_validClient(client): """Should work as expected """ client.return_value.get_paginator.return_value.paginate.return_value = [{ 'CommonPrefixes': [{ 'Prefix': 'L8/178/246/LC81782462014232LGN00/' }] }] bucket = "landsat-pds" prefix = "L8/178/246/" expected_value = ['L8/178/246/LC81782462014232LGN00/'] assert aws.list_directory(bucket, prefix, s3=client()) == expected_value
def test_aws_list_directory_validPays(session): """Should work as expected """ session.return_value.client.return_value.get_paginator.return_value.paginate.return_value = [ { 'CommonPrefixes': [{ 'Prefix': 'L8/178/246/LC81782462014232LGN00/' }] } ] bucket = "landsat-pds" prefix = "L8/178/246/" expected_value = ['L8/178/246/LC81782462014232LGN00/'] assert aws.list_directory(bucket, prefix, request_pays=True) == expected_value pag = session.return_value.client.return_value.get_paginator.return_value.paginate assert pag.call_args[1].get('RequestPayer') == 'requester'