def verify_product_info(self, api_auth): lcc.log_info("Test Product node being created at: %s" % self.path_to_product) create_product_payload = { "name": product_name, "description": "Test product Setup description", "sling:resourceType": "pantheon/product", "jcr:primaryType": "pant:product", "locale": "en-US", "urlFragment": product_name_uri } # Hit the api for create product response = self.api_auth.post(self.path_to_product, data=create_product_payload) check_that("The Product is created successfully", response.status_code, any_of(equal_to(201), equal_to(200))) # Hit the api to get id of created product get_product_id_endpoint = self.path_to_product + ".json" product_id_request = api_auth.get(get_product_id_endpoint) check_that("%s API status code" % get_product_id_endpoint, product_id_request.status_code, equal_to(200)) product_id = product_id_request.json() lcc.log_info("Response for product creation: %s" % str(product_id)) check_that("Product uuid", product_id["jcr:uuid"], is_not_none()) check_that("sling:resourceType", product_id["sling:resourceType"], equal_to("pantheon/product")) check_that("jcr:primaryType", product_id["jcr:primaryType"], equal_to("pant:product")) check_that("product name", product_id["name"], equal_to(product_name))
def select_repo(driver, title): lcc.log_info("Selecting repo::{}".format(title)) utilities.click_element(driver, By.LINK_TEXT, locators.MENU_SEARCH_PAGE_LINK_TEXT) # Poll until all the repos are listed in the filter poll(lambda: len( driver.find_elements(By.CLASS_NAME, locators. SELECT_REPO_CHECKBOX_CLASS_NAME)) >= 1, ignore_exceptions=[NoSuchElementException], timeout=15, step=1) utilities.enter_text(driver, By.XPATH, locators.FILTER_BY_REPO_SEARCH_BAR_XPATH, title) # Poll until repo matching the search criteria is listed in the filter poll(lambda: len( driver.find_elements(By.CLASS_NAME, locators. SELECT_REPO_CHECKBOX_CLASS_NAME)) == 1, ignore_exceptions=[NoSuchElementException], timeout=15, step=1) # utilities.wait(7) print( len( driver.find_elements(By.CLASS_NAME, locators.SELECT_REPO_CHECKBOX_CLASS_NAME))) utilities.click_element(driver, By.CLASS_NAME, locators.SELECT_REPO_CHECKBOX_CLASS_NAME) utilities.wait(3)
def ack_status_check(self, api_auth): self.request_url = fixture.url + self.path_for_assembly + ".10.json" response = api_auth.get(self.request_url) time.sleep(60) #calling the get request twice response = api_auth.get(self.request_url) lcc.log_info("Checking for ack_status at url: %s" % str(self.request_url)) check_that( "The published assembly now has a released node with ack_status node ", response.json()["en_US"]["variants"][self.variant]["released"], has_entry("ack_status")) lcc.log_info("Ack status node response: %s" % str(response.json()["en_US"]["variants"][self.variant] ["released"]["ack_status"])) check_that( "The published assembly has a successful message from Hydra", response.json()["en_US"]["variants"][self.variant]["released"] ["ack_status"]["pant:message"], equal_to("Solr call for index was successful")) check_that( "The published assembly has a successful ACK from Hydra", response.json()["en_US"]["variants"][self.variant]["released"] ["ack_status"]["pant:status"], equal_to("SUCCESSFUL"))
def view_on_portal_link_test(self): try: utilities.wait(5) utilities.click_element(self.driver, By.CSS_SELECTOR, locators.VIEW_ON_PORTAL_LINK_CSS) utilities.wait(5) utilities.switch_to_latest_tab(self.driver) utilities.wait(7) lcc.log_info( "Find the CP preview in the attachment below for debugging purposes" ) self.driver.save_screenshot("cp_preview_module.png") lcc.save_attachment_file("cp_preview_module.png") check_that("View on Portal URL path", self.driver.current_url, contains_string(constants.view_on_portal_page_url)) module_id_regex = re.compile( r'^[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}$' ) current__module_id = self.driver.current_url.split("/topic/")[1] check_that("View on Portal URL id", current__module_id, match_pattern(module_id_regex)) # content_body_on_portal = utilities.find_element(self.driver, By.CSS_SELECTOR, locators.MODULE_BODY_ON_PORTAL_CSS) except (TimeoutException, StaleElementReferenceException, NoSuchElementException) as e: lcc.log_error("Error finding element!!!") lcc.log_error(e) finally: if (len(self.driver.window_handles) > 1): self.driver.close() utilities.switch_to_first_tab(self.driver)
def create_product_versions(self): # User adds versions to the 'Add Product versions' and verifies if the versions were added successfully. utilities.enter_text(self.driver, By.ID, locators.NEW_PRODUCT_VERSION_TEXTBOX_ID, constants.product_version_1) utilities.enter_text(self.driver,By.ID,locators.VERSION_URL_FRAGMENT_ID, constants.product_version_url_fragment_1) utilities.click_element(self.driver, By.CSS_SELECTOR, locators.PRODUCT_VERSION_SAVE_BUTTON_CSS) utilities.wait(3) utilities.find_element(self.driver, By.ID, locators.NEW_PRODUCT_VERSION_TEXTBOX_ID).clear() utilities.enter_text(self.driver, By.ID, locators.NEW_PRODUCT_VERSION_TEXTBOX_ID, constants.product_version_2) utilities.enter_text(self.driver, By.ID, locators.VERSION_URL_FRAGMENT_ID, constants.product_version_url_fragment_2) utilities.click_element(self.driver, By.CSS_SELECTOR, locators.PRODUCT_VERSION_SAVE_BUTTON_CSS) utilities.wait(3) utilities.find_element(self.driver, By.ID,locators.NEW_PRODUCT_VERSION_TEXTBOX_ID).clear() utilities.enter_text(self.driver, By.ID, locators.NEW_PRODUCT_VERSION_TEXTBOX_ID, constants.product_version_3) utilities.enter_text(self.driver, By.ID, locators.VERSION_URL_FRAGMENT_ID, constants.product_version_url_fragment_3) utilities.click_element(self.driver, By.CSS_SELECTOR, locators.PRODUCT_VERSION_SAVE_BUTTON_CSS) utilities.wait(3) utilities.find_element(self.driver, By.ID, locators.NEW_PRODUCT_VERSION_TEXTBOX_ID).clear() versions_ul = utilities.find_element(self.driver, By.CLASS_NAME, locators.PRODUCT_VERSIONS_UL_CLASS_NAME) versions_list = versions_ul.find_elements_by_tag_name(locators.PRODUCT_VERSIONS_LI_TAG_NAME) versions = [] for version in versions_list: versions.append(version.text) lcc.log_info("Versions added: %s" % str(versions)) check_that("Product version entered is added successfully ", versions, has_item(constants.product_version_1)) check_that("Product version entered is added successfully ", versions, has_item(constants.product_version_2)) check_that("Product version entered is added successfully ", versions, has_item(constants.product_version_3))
def test_echo(): data = {"foo": "bar"} lcc.log_info("POST %s %s" % (URL, json.dumps(data))) resp = requests.post(URL, json=data) require_that("status code", resp.status_code, is_between(200, 299)) for key, value in data.items(): check_that_in(resp.json(), key, equal_to(value))
def setup(setup_test_repo, setup_test_products): lcc.log_info("Initialising the session/auth...") session = requests.Session() session.auth = (username, auth) yield session # This block of code is the teardown method which deletes the repository uploaded for testing lcc.log_info("Deleting the test-repo from QA env...") path_to_repo = url + "bin/cpm/nodes/node.json/content/repositories/" + test_repo_name lcc.log_info("Test repo node being deleted at: %s" % path_to_repo) time.sleep(15) # body = {":operation": "delete"} # body = json.dumps(body) response = requests.delete(path_to_repo, auth=(admin_username, admin_auth)) check_that("The test repo was deleted successfully", response.status_code, equal_to(200)) time.sleep(15) # Deletes the products created using api endpoint lcc.log_info("Deleting test products created as a part of the tests.. ") path_to_new_product_node = url + "bin/cpm/nodes/node.json/content/products/" + product_name_uri lcc.log_info("Test Product node being deleted at: %s" % path_to_new_product_node) response1 = session.delete(path_to_new_product_node) print(str(response1.content)) check_that("Test product version created was deleted successfully", response1.status_code, equal_to(200)) time.sleep(15)
def verify_product_version_info(self, api_auth): path_to_version = self.path_to_product + "/versions/{}".format( constants.product_version) lcc.log_info( "Product version being created for the above product: %s" % path_to_version) create_version_payload = { "name": constants.product_version, "sling:resourceType": "pantheon/productVersion", "jcr:primaryType": "pant:productVersion", "urlFragment": constants.product_version_uri } # Hit the api for create version for the above product response = self.api_auth.post(path_to_version, data=create_version_payload) check_that("The Product version is created successfully", response.status_code, any_of(equal_to(201), equal_to(200))) # Hit the api to get id of product version path_to_product_id = self.path_to_product + "/versions/" + constants.product_version + ".json" product_version_id_req = api_auth.get(path_to_product_id) check_that("%s API status code" % path_to_product_id, product_version_id_req.status_code, equal_to(200)) product_version_id = product_version_id_req.json() check_that("Product version uuid", product_version_id["jcr:uuid"], is_not_none()) check_that("sling:resourceType", product_version_id["sling:resourceType"], equal_to("pantheon/productVersion")) check_that("jcr:primaryType", product_version_id["jcr:primaryType"], equal_to("pant:productVersion")) check_that("product version", product_version_id["name"], equal_to(constants.product_version))
def teardown_suite(self): response = unpublish_module(self, constants.module_to_unpublish, constants.variant) check_that("Unpublish request status code", response.status_code, equal_to(200)) lcc.log_info( "Module published for above test is unpublished successfully..")
def add_metadata(url, path, variant, api_auth, setup_test_products, content_type): if content_type == "module": documentUsecase = constants.documentUsecase urlFragment = constants.urlFragment searchKeywords = constants.searchKeywords elif content_type == "assembly": documentUsecase = constants.assembly_documentusecase urlFragment = constants.assembly_urlfragment searchKeywords = constants.assembly_searchkeywords edit_metadata_url = url + path + "/en_US/variants/" + variant + "/draft/metadata" lcc.log_info("Editing metadata for: %s " % edit_metadata_url) # Fetch the product id from fixtures, ta test product and version was created as setup step. product_id, product_name_uri = setup_test_products print("Data product id::", product_id) payload = { "productVersion": product_id, "documentUsecase": documentUsecase, "urlFragment": urlFragment, "searchKeywords": searchKeywords } # payload = urlencode(payload) print("Payload::", payload) # headers = {'content-type': "application/x-www-form-urlencoded"} response = api_auth.post(edit_metadata_url, data=payload) time.sleep(10) print("Response::", response) return response, product_name_uri
def test_get_asset_holders(self): lcc.set_step("Get all asset holders") self.get_holders() lcc.set_step("Get asset_id and count of holders") params = [self.resp_all_asset_holders["result"][0]["asset_id"], 0, 100] holders_count = self.resp_all_asset_holders["result"][0]["count"] lcc.log_info("Params = {}, holders count = {}".format( params, holders_count)) lcc.set_step("Get list of holders") self.send_request(self.get_request(self.__get_asset_holders, params), self.__identifier) self.__resp = self.get_response() lcc.set_step("Check names of holders in list of expected holders") for i in range(holders_count): expected_keys = ["name", "account_id", "amount"] for j in range(len(expected_keys)): check_that( "'holder №{}'".format(i + 1), self.__resp["result"][i], has_entry( expected_keys[j], ((self.get_expected(self.__get_holders))[i])[j], ), )
def select_product_and_version_filter(self): utilities.click_element(self.driver, By.LINK_TEXT, "Search") utilities.wait(2) utilities.select_value_from_dropdown(self.driver, By.CSS_SELECTOR, locators.SELECT_PRODUCT_NAME_CSS, constants.product_name) utilities.select_value_from_dropdown( self.driver, By.CSS_SELECTOR, locators.SELECT_PRODUCT_VERSION_CSS, constants.product_version) lcc.log_info( "product and version selected and displayed on search page") utilities.find_element( self.driver, By.XPATH, locators.PRODUCT_FILTER_DISPLAY_XPATH).is_displayed() utilities.click_element(self.driver, By.CSS_SELECTOR, locators.SEARCH_BUTTON_CSS) utilities.wait(2) utilities.click_element(self.driver, By.XPATH, locators.SEARCH_MODULE_XPATH) utilities.wait(2) check_that( "verify that 'filter by product and version' functionality filters results correctly", utilities.get_text(self.driver, By.XPATH, locators.PRODUCT_VERSION_DISPLAY_PAGE_XPATH), contains_string(constants.product_name + " " + constants.product_version))
def session_fixture(session_fixture_prerun): lcc.log_info("session_fixture_setup") retval = session_fixture_prerun * 3 marker.append(retval) yield retval marker.append(2) lcc.log_info("session_fixture_teardown")
def read_variant_name_from_pantheon2config(): print(os.getcwd()) pantheon_config = yaml.safe_load(open('./pantheon2.yml', 'r')) for variant in pantheon_config["variants"]: if variant["canonical"] == True: variant = variant["name"] lcc.log_info("Variant name used: %s" % variant) return str(variant)
def verify_module_type_after_publishing(driver, module_type): lcc.log_info("Verifying if module type persists after publishing") display_module_page.add_metadata_and_publish(driver) module_type_on_display_page_again = utilities.get_text( driver, By.CSS_SELECTOR, locators.VIEW_MODULE_TYPE_CSS) check_that("Module type displayed on UI after publishing", module_type_on_display_page_again.upper(), equal_to(module_type.upper()))
def _login_status(response): # Check authorization status try: if response["result"]: lcc.log_info("Login successful") else: lcc.log_info("Login failed") except KeyError: lcc.log_error("Login failed")
def verify_module_type_from_UI(driver, module_type): module_type_on_display_page = utilities.get_text( driver, By.CSS_SELECTOR, locators.VIEW_MODULE_TYPE_CSS) lcc.log_info( "Verifying that the module type is displayed on the UI as: %s " % module_type) check_that("Module type displayed on UI ", module_type_on_display_page.upper(), equal_to(module_type.upper()))
def verify_module_type_from_backend(driver, module_type): # Once landed on the module display page, get path to adoc from the module display page url path_to_adoc_file = display_module_page.get_path_to_adoc(driver) path = path_to_adoc_file + constants.path_for_module_type req = url + path.strip() response = requests.get(url=req, auth=(fixture.username, fixture.api_auth)) lcc.log_info("Verifying the response at endpoint: %s " % req) check_that("Module type saved in the backend", response.text.upper(), contains_string(module_type.upper()))
def switch_to_latest_tab(driver): wait(5) driver.switch_to.window(driver.window_handles[1]) lcc.log_info( "Find the CP preview in the attachment below for debugging purposes") random = generate_random_string(3) file_name = "cp_preview_" + random + ".png" driver.save_screenshot(file_name) lcc.save_attachment_file(file_name)
def setup_suite(self): # Check status of connection lcc.set_step("Open connection") if self.__ws is not None: lcc.log_url(ECHO_DEV) lcc.log_info("Connection successfully created") self.__login_echo() else: lcc.log_error("Connection not established")
def teardown_suite(self): lcc.log_info("Deleting the product created above...") product_name_node = product_name.replace(" ", "_").lower() path_to_product_node = url + "content/products/" + product_name_node lcc.log_info("Test Product node being deleted at: %s" % path_to_product_node) body = {":operation": "delete"} response = requests.post(path_to_product_node, data=body, auth=(fixture.admin_username, fixture.admin_auth)) check_that("The Product created was deleted successfully", response.status_code, equal_to(200))
def fetch_uuid(url, path, variant, api_auth): path = url + path + ".7.json" path_endpoint = api_auth.get(path) print("\n Content path: " + path) lcc.log_info("Content path being checked: %s" % path) lcc.log_info("Variant:" + variant) uuid = path_endpoint.json()["en_US"]["variants"][variant]["jcr:uuid"] print("uuid: " + str(uuid)) return uuid
def fetch_uuid_of_assembly(url, assembly_path, variant): assembly_path = url + "content/" + assembly_path + ".7.json" assembly_path_endpoint = requests.get(assembly_path) print("\n Assembly path: " + assembly_path) lcc.log_info("Assembly path being checked: %s" % assembly_path) assembly_uuid = assembly_path_endpoint.json( )["en_US"]["variants"][variant]["jcr:uuid"] print("Assembly uuid: " + str(assembly_uuid)) return assembly_uuid
def removed_from_solr(self): time.sleep(20) solr_request_url = fixture.solr_url + "solr/docv2/select?indent=on&q=id:" + self.module_uuid + "&wt=json" lcc.log_info("Checking docv2 collection in Solr: %s" % solr_request_url) solr_request = requests.get(solr_request_url) solr_request_json = solr_request.json() lcc.log_info("Response from Solr: %s " % str(solr_request_json)) check_that("The module is removed from docv2 collection in Solr", solr_request_json["response"]["numFound"], equal_to(0))
def verify_login_success(self): # 'driver' param is the webdriver object that is being called from 'setup' fixture and used through the scope # of the session. username = base.config_reader('login', 'username') logged_in_user = login_page.get_logged_in_username(self.driver) lcc.log_info("Logged in username: %s" % logged_in_user) assert_that("Logged in username is visible", logged_in_user, contains_string(username), quiet=False)
def publish_module(self, api_auth): # Get path of the module for which metadata was added publish_url = fixture.url + self.path_for_module print("\n API end point used for publish request: " + publish_url) payload = { ":operation": "pant:publish", "locale": "en_US", "variant": self.variant } print("Payload: ", payload) time.sleep(10) publish_module_request = self.api_auth.post( publish_url, data=payload, headers={'Accept': 'application/json'}) time.sleep(10) check_that("The publish request was successful", publish_module_request.status_code, equal_to(200)) # Check if the publish request response returns "url" for Customer Portal: CCS-3860 cp_url_returned = publish_module_request.json()["location"] check_that("Publish module response contains The Customer Portal URL", cp_url_returned, contains_string(fixture.cp_url + "documentation")) response = api_auth.get(self.request_url) # Check that the node has been marked as released check_that("The published module now has a 'released' node", response.json()["en_US"]["variants"][self.variant], has_entry("released")) self.module_uuid = utilities.fetch_uuid(fixture.url, self.path_for_module, self.variant, api_auth) published_module_url = fixture.url + "api/module/variant.json/" + self.module_uuid print("published module url: \n" + published_module_url) lcc.log_info("Published Module api endpoint: %s" % published_module_url) data_from_published_module = api_auth.get(published_module_url) check_that( "The /api/module/variant.json/<module_uuid> endpoint for a published module", data_from_published_module.status_code, equal_to(200)) # print("Response from published module API endpoint: \n" + str(data_from_published_module.content)) check_that("The response is ", data_from_published_module.json()["message"], equal_to("Module Found")) check_that("The title of the module ", data_from_published_module.json()["module"]["title"], contains_string(module_title_prefix)) check_that("The status of the module ", data_from_published_module.json()["module"]["status"], equal_to("published")) check_that("The body of the module", data_from_published_module.json()["module"]["body"], is_not_none())
def search_titles(driver, title): lcc.log_info("Searching for title::{}".format(title)) try: wait_for_modules(driver) utilities.enter_text(driver, By.CSS_SELECTOR, locators.SEARCH_TITLE_CSS, title) except TimeoutException as e: lcc.log_info( "It appears that the module was not found, please check your test data." ) raise e
def teardown_suite(self): lcc.log_info( "Deleting test products created as a part of the tests.. ") path_to_new_product_node = fixture.url + "bin/cpm/nodes/node.json/content/products/" + product_name_uri lcc.log_info("Test Product node being deleted at: %s" % path_to_new_product_node) response1 = requests.delete(path_to_new_product_node, auth=(fixture.admin_username, fixture.admin_auth)) check_that("Test product version created was deleted successfully", response1.status_code, equal_to(200))
def test_post_req(): body = { "title": 'Title for Devconf.CZ 2020', "body": 'Test title by Anisha', "userId": 500 } response = requests.post(base_url + "/posts", data=body) result= response.json() require_that("the POSt request response", response.status_code, equal_to(201)) lcc.log_info(str(result)) check_that("the response", result, has_entry("title", equal_to("Title for Devconf.CZ 2020")))
def setup_test_products(): lcc.log_info("Creating test product..") path_to_product_node = url + "content/products/" + product_name_uri lcc.log_info("Test Product node being created at: %s" % path_to_product_node) create_product_payload = { "name": product_name, "description": "Test product Setup description", "sling:resourceType": "pantheon/product", "jcr:primaryType": "pant:product", "locale": "en-US", "urlFragment": product_name_uri } # Hit the api for create product response = requests.post(path_to_product_node, data=create_product_payload, auth=(username, auth)) check_that("The Product was created successfully", response.status_code, any_of(equal_to(201), equal_to(200))) lcc.log_info("Creating version for the above product") time.sleep(5) path_to_version = path_to_product_node + "/versions/{}".format( constants.product_version) lcc.log_info("Product version being created for the above product: %s" % path_to_version) create_version_payload = { "name": constants.product_version, "sling:resourceType": "pantheon/productVersion", "jcr:primaryType": "pant:productVersion", "urlFragment": constants.product_version_uri } # Hit the api for create version for the above product response = requests.post(path_to_version, data=create_version_payload, auth=(username, auth)) check_that("The Product version was created successfully", response.status_code, any_of(equal_to(201), equal_to(200))) time.sleep(5) path_to_product_id = path_to_product_node + ".2.json" product_version_id_req = requests.get(path_to_product_id, auth=(username, auth)) print(product_version_id_req.json()) print(path_to_product_id) product_version_id = product_version_id_req.json()["versions"][ constants.product_version]["jcr:uuid"] lcc.log_info( "Fetching product version id of the product created: %s id: %s" % (path_to_product_id, str(product_version_id))) return product_version_id, product_name_uri