Ejemplo n.º 1
0
def test_connect_to_not_existing_worksheet_in_valid_googlesheet():
    """Ensure that a sheet is not returned for a not-existing worksheet in a valid Google sheet."""
    with pytest.raises(SheetNameNoMatchError):
        util.load_environment()
        googlesheet_id_exists = "1ujmuIJy1NPhasIF4tnRSae0033hwa9g0wul5Ii2NwZU"
        _ = sheets.connect_to_sheet(googlesheet_id_exists,
                                    requested_sheet_name="SheetNotThere")
Ejemplo n.º 2
0
def test_connect_to_existing_googlesheet():
    """Ensure that a worksheet is returned for an existing sheet."""
    util.load_environment()
    googlesheet_id_exists = "1ujmuIJy1NPhasIF4tnRSae0033hwa9g0wul5Ii2NwZU"
    sheet = sheets.connect_to_sheet(googlesheet_id_exists)
    assert sheet is not None
    assert type(sheet) is model.Sheet
Ejemplo n.º 3
0
def download(googlesheet_id: str, env_file: Path,
             debug_level: DebugLevel) -> DataFrame:
    """Download the spreadsheet from Google Sheets, process it, and return an Pandas data frame."""
    logger = logging.getLogger(constants.logging.Rich)
    # DEBUG: display the debugging output for the program's command-line arguments
    logger.debug(f"The Google Sheet is {googlesheet_id}.")
    logger.debug(f"The debugging level is {debug_level.value}.")
    # construct the full name of the .env file
    env_file_name = constants.markers.Nothing
    # the file was specified and it is valid so derive its full name
    if env_file is not None:
        if env_file.is_file():
            # DEBUG: indicate that the .env file on command-line is in use
            logger.debug("Using provided .env file from the command-line")
            # convert the Pathlib Path to a string
            env_file_name = str(env_file)
    # the file name was not specified so construct the default name
    else:
        env_file_name = constants.markers.Nothing.join(
            [os.getcwd(), os.sep, constants.files.Env])
        # DEBUG: indicate the use of the .env file in the current working directory
        logger.debug("Using constructed .env file in current directory")
    # DEBUG: display the constructed name of the .env file
    logger.debug(f"Environment file: {env_file_name}")
    # load the required secure environment for connecting to Google Sheets
    util.load_environment(env_file_name)
    # connect the specified Google Sheet using the default internal sheet of "Sheet1"
    sheet = sheets.connect_to_sheet(googlesheet_id)
    # extract the Pandas data frame from the sheet in sheetfu's internal format
    dataframe = sheets.extract_dataframe(sheet)
    # console.print(constants.markers.Indent + "Downloading")
    return dataframe
Ejemplo n.º 4
0
def test_extract_dataframe_from_existing_googlesheet_and_existing_worksheet():
    """Ensure that it is possible to extract a Pandas dataframe from a Sheetfu sheet."""
    util.load_environment()
    googlesheet_id_exists = "1ujmuIJy1NPhasIF4tnRSae0033hwa9g0wul5Ii2NwZU"
    sheet = sheets.connect_to_sheet(googlesheet_id_exists)
    dataframe = sheets.extract_dataframe(sheet)
    assert dataframe is not None
    assert dataframe.ndim == 2
    assert dataframe.size == 520
Ejemplo n.º 5
0
def test_connect_to_not_existing_googlesheet():
    """Ensure that a worksheet is not returned for a not-existing Google sheet."""
    with pytest.raises(errors.HttpError):
        util.load_environment()
        googlesheet_id_exists = "1ujmuIJy1NPhasIF4tnRSae0033hwa9g0wul5Ii2NwZU-WRONG"
        _ = sheets.connect_to_sheet(googlesheet_id_exists)