Exemple #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")
Exemple #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
Exemple #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
Exemple #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
Exemple #5
0
def test_send_multiple_messages_real_twilio_constructed_client():
    """Ensure that it is possible to send the SMS message(s) through Twilio service."""
    util.load_environment()
    recipient_phone_number = os.getenv(
        constants.environment.Recipient_Phone_Number)
    phone_number_message_dictionary = {
        recipient_phone_number: "Test Message First"
    }
    sid_list = sms.send_messages(phone_number_message_dictionary)
    assert sid_list is not None
    assert len(sid_list) == 1
Exemple #6
0
def test_send_single_message_real_twilio_constructed_client():
    """Ensure that it is possible to send the SMS message through Twilio service."""
    util.load_environment()
    internal_client = Client()
    twilio_phone_number = os.getenv(constants.environment.Twilio_Phone_Number)
    recipient_phone_number = os.getenv(
        constants.environment.Recipient_Phone_Number)
    sid = sms.send_message(
        internal_client,
        recipient_phone_number,
        twilio_phone_number,
        "Test: Sending Message Through Twilio",
    )
    assert sid is not None
Exemple #7
0
def test_extract_dataframe_from_not_existing_sheet():
    """Ensure that trying to extract a Pandas dataframe from non-existent Sheetfu sheet does not work."""
    with pytest.raises(SheetNotFoundError):
        util.load_environment()
        _ = sheets.extract_dataframe(None)
Exemple #8
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)
Exemple #9
0
def test_dotenv_creates_environment():
    """Ensure that the use of dotenv creates expected environment variables."""
    util.load_environment()
    key = "SHEETFU_CONFIG_TYPE"
    value = os.getenv(key)
    assert value == "service_account"