def wait_for_synced(self): log("Waiting for changes to be uploaded to Etsy") wait_for_assert('up_to_date', lambda: self.db.get_shop_status(self.shop_id), 'Shop not synced', retries=SHOP_SYNC_TIMEOUT) log("Shop synced")
def validate_listings(products, timestamp): assert len( products ) == NUMBER_OF_TEST_LISTINGS, 'Incorrect number of listings found' for i, listing in enumerate( sorted(products, key=lambda item: item['title'])): title = '{}{:02d}'.format(AT_TITLE_PREFIX, i) log('Verifying ', title) assert listing['title'] == title + ' ' + timestamp assert listing['body_html'] == '<p>{}</p>{}'.format( timestamp, AT_DESCRIPTION) image_urls = [image['src'] for image in listing['images']] compare_images(image_urls, AT_IMAGES) assert listing['tags'] == ', '.join(AT_TAGS) assert listing['product_type'] == AT_PRODUCT_TYPE assert listing['vendor'] == AT_VENDOR
def validate_listings(self, listings, timestamp): for i, listing in enumerate(listings[key] for key in sorted(listings.keys())): id = "{}_{:02d}".format(AT_TITLE, i) log("Verifying ", id) assert listing['title'] == id + " " + timestamp assert listing['description'] == AT_DESCRIPTION + " " + timestamp assert listing['taxonomy_id'] == AT_TAXONOMY_ID assert listing['taxonomy_path'] == AT_TAXONOMY_PATH_API image_urls = [ image['url_fullxfull'] for image in listing['Images'] ] compare_images(image_urls, AT_IMAGES) assert listing['tags'] == AT_TAGS assert listing['materials'] == AT_MATERIALS assert listing['Section']['title'] == AT_SECTION attributes = set() for attribute in listing['Attributes']: assert len(attribute['values']) == 1 attributes.add( (attribute['property_name'], attribute['values'][0])) assert attributes == AT_ATTRIBUTES_API products = listing['Inventory'][0]['products'] assert len(products) == len(AT_VAR_OPTION_VALUES) for j, option_name in enumerate(AT_VAR_OPTION_VALUES): assert products[j]['property_values'][0][ 'property_name'] == AT_VAR_PROPERTY_NAME_API assert products[j]['property_values'][0][ 'property_id'] == AT_VAR_PROPERTY_ID assert products[j]['property_values'][0]['values'][ 0] == AT_VAR_OPTION_VALUES[j] assert products[j]['offerings'][0]['price'][ 'currency_formatted_raw'] == AT_PRICE_API assert products[j]['offerings'][0]['quantity'] == AT_QUANTITY assert products[j]['sku'] == AT_SKU
def test_etsy_upload(self): """ Verify that listings can be fetched from Etsy, changed in vela GUI and pushed back to Etsy """ # debug # with open('tests-etsy/data.json') as f: # data = json.load(f) # self.validate_listings(data, '20161124_184056') # return # Delete log files logs = Logs(os.environ['LOG_CLEAN_SCRIPT'], os.environ['LOG_GREP_SCRIPT']) logs.empty() timestamp = strftime("%Y%m%d_%H%M%S") credentials = self.get_credentials() etsy = EtsyApiForATs(credentials) # Delete our section from Etsy log("Deleting section from Etsy") etsy.remove_at_section(AT_SECTION) # Delete and re-create listings on Etsy log("Removing AT listings from Etsy") etsy.remove_at_listings() log("Creating AT listings on Etsy") st_id = etsy.get_shipping_template_id() for i in range(3): title = "{}_{:02d}".format(AT_TITLE, i) etsy.create_listing( dict(self.NEW_LISTING, title=title, taxonomy_id=1, shipping_template_id=st_id)) listings = etsy.get_listings() for listing_id, title in ((l['listing_id'], l['title']) for l in listings if l['title'][:len(AT_TITLE)] == AT_TITLE): print(listing_id, title) # Clean up Vela DB, Load new shop log("Cleaning Vela DB") # Reset feature flags for features that are not in production yet self.db.reset_user_profile_flags(self.user_id, BETA_FEATURE_FLAGS) self.reload_shop() log("Making UI changes") self.go_to_bulk() bp = BulkPage(self.driver) # Edit title log(" title") bp.edit_part('Title').click() bp.select_operation('Add After') send_keys(bp.operation_input(), ' ' + timestamp) bp.operation_apply().click() # Edit description log(" description") bp.edit_part('Description').click() bp.select_operation('Add After') send_keys(bp.operation_input_description(), ' ' + timestamp) bp.operation_apply().click() # Edit category log(" category") bp.edit_part('Category').click() bp.select_category(AT_CATEGORIES) bp.operation_apply().click() # Edit photos log(" photos") bp.edit_part('Photos').click() with Photos(self.driver) as photos: for i, img in enumerate(AT_IMAGES): photos.select_photo( i, os.path.join(photos.photo_dir, img['file'])) bp.operation_apply().click() # Edit tags log(" tags") bp.edit_part('Tags').click() send_keys(bp.operation_input(), ', '.join(AT_TAGS)) bp.operation_apply().click() # Edit materials log(" materials") bp.edit_part('Materials').click() send_keys(bp.operation_input(), ', '.join(AT_MATERIALS)) bp.operation_apply().click() # Edit section log(" section") bp.edit_part('Section').click() bp.operation_select().click() sleep(2) send_keys(bp.operation_menu_new_item_input(), AT_SECTION + Keys.RETURN) bp.operation_apply().click() # Edit Occasion log(" occasion") bp.edit_part('Occasion').click() bp.select_occasion(AT_OCCASION) bp.operation_apply().click() # Edit Holiday log(" holiday") bp.edit_part('Holiday').click() bp.select_holiday(AT_HOLIDAY) bp.operation_apply().click() # Edit variations log(" variations") bp.edit_part('Variations').click() biv = BulkPageInventoryVariations(self.driver, self.ts) bp.select_category(AT_CATEGORIES) bulk_row = biv.bulk_edit_row biv.set_property(bulk_row, 0, AT_VAR_PROPERTY_NAME) for option_name in AT_VAR_OPTION_VALUES: biv.add_option(bulk_row, 0, option_name) bp.operation_apply().click() # Edit price log(" price") bp.edit_part('Price').click() bip = BulkPageInventoryPrice(self.driver, self.ts) bip.select_operation('Change To') input_field = bip.operation_input() send_keys(input_field, AT_PRICE) bp.operation_apply().click() # Edit quantity log(" quantity") bp.edit_part('Quantity').click() biq = BulkPageInventoryQuantity(self.driver, self.ts) biq.select_operation('Change To') input_field = biq.operation_input() send_keys(input_field, str(AT_QUANTITY)) biq.operation_apply().click() # Edit Sku log(" sku") bp.edit_part('SKU').click() bis = BulkPageInventorySku(self.driver, self.ts) input_field = bis.operation_input() send_keys(input_field, AT_SKU) bis.operation_apply().click() # Sync Updates log("Syncing Updates") bp.sync_updates_button().click() sleep(10) self.wait_for_synced() # Get listings from Etsy data = etsy.get_at_listings_details() self.validate_listings(data, timestamp) # Check logs for errors logs.check_for_errors()
def test_shopify_upload(self): """ Verify that listings can be fetched from Shopify, changed in vela GUI and pushed back to Shopify """ # --- Preparation ---- # Delete log files logs = Logs(os.environ['LOG_CLEAN_SCRIPT'], os.environ['LOG_GREP_SCRIPT']) logs.empty() timestamp = strftime("%Y%m%d_%H%M%S") # Remove test listings on shopify and create them again there test_listings = ShopifyTestProducts(self.shop_domain, self.shop_token, AT_TITLE_PREFIX) log('Removing AT listings from Shopify') ids = test_listings.delete_test_products() log('Removed listings: ' + ', '.join(map(str, ids))) log('Creating AT listings on Shopify') ids = test_listings.create_test_products(NUMBER_OF_TEST_LISTINGS) log('Created listings: ' + ', '.join(map(str, ids))) # Reload shop - sync from Shopify and disable beta features we don't want to test self.reload_shopify_shop() self.db.reset_user_profile_flags(self.user_id, BETA_FEATURE_FLAGS) # --- Start testing in UI --- log("Making UI changes") self.go_to_bulk(self.shop_name) bp = BulkPage(self.driver) # Edit title log(" title") bp.edit_part('Title').click() bp.select_operation('Add After') send_keys(bp.operation_input(), ' ' + timestamp) bp.operation_apply().click() # Edit description log(" description") bp.edit_part('Description').click() bp.select_operation('Add Before') send_keys(bp.operation_edit_area_description(), timestamp) bp.operation_apply().click() # Edit photos log(" photos") bp.edit_part('Photos').click() with Photos(self.driver) as photos: for i, img in enumerate(AT_IMAGES): photos.select_photo( i, os.path.join(photos.photo_dir, img['file'])) bp.operation_apply().click() # Edit tags log(" tags") bp.edit_part('Tags').click() send_keys(bp.operation_input(), ', '.join(AT_TAGS)) bp.operation_apply().click() # Edit section log(" product type") bp.edit_part('Product Type').click() bp.operation_select().click() sleep(2) send_keys(bp.operation_menu_new_item_input(), AT_PRODUCT_TYPE + Keys.RETURN) bp.operation_apply().click() # Edit section log(" vendor") bp.edit_part('Vendor').click() bp.operation_select().click() sleep(2) send_keys(bp.operation_menu_new_item_input(), AT_VENDOR + Keys.RETURN) bp.operation_apply().click() # Sync Updates log("Syncing Updates") bp.sync_updates_button().click() sleep(5) self.wait_for_synced() # Get test listings from Shopify and verify them data = test_listings.get_test_products() validate_listings(data, timestamp) # Check logs for errors logs.check_for_errors()