Exemplo n.º 1
0
    def with_invalid_column(sample_google_sheet_normal,
                            sample_plenty_data_invalid):
        result = update_column(google=sample_google_sheet_normal,
                               plenty=sample_plenty_data_invalid)

        # should be unchanged
        assert_frame_equal(sample_google_sheet_normal, result)
Exemplo n.º 2
0
    def with_attributes(sample_google_sheet_normal,
                        sample_plenty_data_attributes,
                        expected_update_column_attributes):
        result = update_column(google=sample_google_sheet_normal,
                               plenty=sample_plenty_data_attributes)

        assert_frame_equal(expected_update_column_attributes, result)
Exemplo n.º 3
0
    def with_inventory(sample_google_sheet_normal,
                       sample_plenty_data_inventory,
                       expected_update_column_inventory):
        result = update_column(google=sample_google_sheet_normal,
                               plenty=sample_plenty_data_inventory)

        assert_frame_equal(expected_update_column_inventory, result)
Exemplo n.º 4
0
    def with_less_ids(sample_google_sheet_normal,
                      sample_plenty_data_less_items):
        result = update_column(google=sample_google_sheet_normal,
                               plenty=sample_plenty_data_less_items)

        # should be unchanged
        assert_frame_equal(sample_google_sheet_normal, result)
Exemplo n.º 5
0
def cli():
    parser = setup_argparser()
    verbose = logger.info if parser.verbose else lambda *a, **k: None

    config = configparser.ConfigParser()
    config.read(CONFIG_PATH)
    if not check_config(config=config):
        sys.exit(1)

    direct_credentials = get_config_credentials(config=config)

    if direct_credentials:
        verbose("Use credentials from configuration.")
        api = plenty_api.PlentyApi(
            base_url=config['General']['plenty_api_url'],
            use_keyring=True, data_format='json',
            username=direct_credentials['user'],
            password=direct_credentials['pw']
        )

    if not direct_credentials or not api.creds['Authorization']:
        verbose("Use credentials from keyring.")
        api = plenty_api.PlentyApi(
            base_url=config['General']['plenty_api_url'],
            use_keyring=True, data_format='json'
        )

    if not get_config_values(config=config):
        logger.error("Invalid configuration.")
        sys.exit(1)

    if not parser.synctype:
        logger.error("Specify the sync type: [inventory, price, text, "
                     "attribute, link, all].")
        sys.exit(1)

    verbose("Load the google-sheet and get the first sheet.")
    google_account = gspread.oauth()
    sheet = google_account.open_by_key(config['General']['google_sheet_id'])
    worksheet = sheet.get_worksheet(0)

    verbose("Read the google-sheet.")
    google = gsheet.gsheet_read(worksheet=worksheet)

    verbose("Get all Plentymarkets variations through the API.")
    variations = api.plenty_api_get_variations(
        refine={'referrerId': config['Mapping']['facebook_referrer'],
                'isActive': True},
        additional=['properties', 'images', 'variationAttributeValues',
                    'stock', 'variationSalesPrices'],
        lang=shared.lang
    )
    if not variations:
        sys.exit(1)
    variations = [var for var in variations if not var['isMain']]
    shared.plenty_variations = variations
    shared.plenty_api_instance = api

    verbose("Fetch necessary data for the specified sync type.")
    sync = plenty.get_data_from_plentymarkets(
        header=HEADER_SYNC_MAP[parser.synctype])

    verbose("Check if new variations were added in Plentymarkets.")
    google = gsheet.add_new_items(google=google, plenty=sync)
    verbose("Check if variations were deleted in PlentyMarkets.")
    google = gsheet.delete_removed_items(google=google, plenty=sync)
    verbose("Update the columns of the google-sheet.")
    google = gsheet.update_column(google=google, plenty=sync)

    if len(google.index) > 0:
        verbose("Write the changes to the google-sheet.")
        gsheet.gsheet_write(worksheet=worksheet, dataframe=google)
        verbose("Resize the google-sheet to it's current size.")
        worksheet.resize(rows=len(google.index)+1)
Exemplo n.º 6
0
    def with_empty_plenty_data(sample_google_sheet_normal):
        result = update_column(google=sample_google_sheet_normal,
                               plenty=pandas.DataFrame())

        # should be unchanged
        assert_frame_equal(sample_google_sheet_normal, result)
Exemplo n.º 7
0
    def with_empty_google_sheet(sample_plenty_data_inventory):
        result = update_column(google=pandas.DataFrame(),
                               plenty=sample_plenty_data_inventory)

        # should be empty
        assert_frame_equal(pandas.DataFrame(), result)
Exemplo n.º 8
0
    def with_price(sample_google_sheet_normal, sample_plenty_data_price,
                   expected_update_column_price):
        result = update_column(google=sample_google_sheet_normal,
                               plenty=sample_plenty_data_price)

        assert_frame_equal(expected_update_column_price, result)