Ejemplo n.º 1
0
    def load(self, sheet_id, token_json):
        """
        Loads the data

        sheet_id : str that represents the Google sheet's id
        token_json : str that represents the filename of the json file containing the credentials
        """

        self.sheet_id = sheet_id
        # define the scope
        scope = [
            "https://spreadsheets.google.com/feeds",
            "https://www.googleapis.com/auth/drive"
        ]
        # add credentials to the account
        creds = ServiceAccountCredentials.from_json_keyfile_name(
            token_json, scope)
        # authorize the clientsheet
        client = gspread.authorize(creds)
        sheet = client.open_by_key(sheet_id)
        worksheets = sheet.worksheets()

        for index, model_worksheet in enumerate(worksheets):
            cur_worksheet = worksheet.Worksheet(
                model_worksheet.get_all_records(), index)
            self.worksheets.append(cur_worksheet)
Ejemplo n.º 2
0
def date_trailing_right_spaces_worksheet(scope="class"):
    """
    Test data where the column name has trailing right spaces with 'Date'.
    """

    return worksheet.Worksheet(
        [{"Date    ": "May 2 ,2021", "Activity": "Play Games!", "Leader": "RandomPerson1"}],
        0)
Ejemplo n.º 3
0
def date_spaces_both_sides_worksheet(scope="class"):
    """
    Test data where the column names has spaces both sides of 'Date'.
    """

    return worksheet.Worksheet(
        [{"    Date    ": "May 2 ,2021", "Activity": "Play Games!", "Leader": "RandomPerson1"}],
        0)
Ejemplo n.º 4
0
def no_date_col_name_worksheet(scope="class"):
    """
    Test data has no column name called 'Date'.
    """

    return worksheet.Worksheet(
        [{"Blah": "May 2 ,2021", "Activity": "Play Games!", "Leader": "RandomPerson1"}],
        0)
Ejemplo n.º 5
0
def one_row_worksheet(scope="class"):
    """
    Test data of one row worksheet.
    """

    return worksheet.Worksheet(
        [{"Date": "May 2 ,2021", "Activity": "Play Games!", "Leader": "RandomPerson1"}],
        0)
Ejemplo n.º 6
0
def multi_rows_worksheet_not_in_order(scope="class"):
    """
    Test data of multirows workeet that is not in order by date.
    """

    return worksheet.Worksheet(
        [{"Date": "May 3 ,2021", "Activity": "Play Games!!", "Leader": "RandomPerson2"},
        {"Date": "May 2 ,2021", "Activity": "Play Games!", "Leader": "RandomPerson1"},
        {"Date": "May 4 ,2021", "Activity": "Play Games!!!", "Leader": "RandomPerson3"}],
        0)
Ejemplo n.º 7
0
def date_in_fifth_col_worksheet(scope="class"):
    """
    Test data where 5th column's name is called 'Date'.
    """

    return worksheet.Worksheet(
        [{"Game" : "Escape Room",
        "Co-leader" : "Somebody1",
        "Activity": "Play Games!",
        "Leader": "RandomPerson1",
        "Date": "May 2 ,2021"}],
        0)
Ejemplo n.º 8
0
def empty_worksheet(scope="class"):
    """
    Test data of empty worksheet.
    """

    return worksheet.Worksheet()