def check_if_product_is_in_list(response, product_release): """ Checks if product is in response list with his attribute and metadatas - Assertions: * Metadata (default metadatas) * Attributes (if exist) * Product existence in list :param response: Response from API - dic :param product_release: Product release version - str :return: None """ found = False for product_and_release in response: if product_and_release[PRODUCT][PRODUCT_NAME] == world.product_name: if product_release is None or product_and_release[VERSION] == product_release: found = True for metadata in DEFAULT_METADATA[METADATA]: # Workaround: xmldict manage Empty values as None value replace_none_value_metadata_to_empty_string(product_and_release[PRODUCT][PRODUCT_METADATAS]) assert_in(metadata, product_and_release[PRODUCT][PRODUCT_METADATAS], "Metadata are not the expected!") if world.attributes is not None: assert_equals(product_and_release[PRODUCT][PRODUCT_ATTRIBUTES], world.attributes, "Attributes are not expected!") break assert_true(found, "Product and release not found in list!")
def check_if_product_is_in_list(response, product_release): """ Checks if product is in response list with his attribute and metadatas - Assertions: * Metadata (default metadatas) * Attributes (if exist) * Product existence in list :param response: Response from API - dic :param product_release: Product release version - str :return: None """ found = False for product_and_release in response: if product_and_release[PRODUCT][PRODUCT_NAME] == world.product_name: if product_release is None or product_and_release[ VERSION] == product_release: found = True for metadata in DEFAULT_METADATA[METADATA]: # Workaround: xmldict manage Empty values as None value replace_none_value_metadata_to_empty_string( product_and_release[PRODUCT][PRODUCT_METADATAS]) assert_in(metadata, product_and_release[PRODUCT][PRODUCT_METADATAS], "Metadata are not the expected!") if world.attributes is not None: assert_equals( product_and_release[PRODUCT][PRODUCT_ATTRIBUTES], world.attributes, "Attributes are not expected!") break assert_true(found, "Product and release not found in list!")
def then_the_metadatas_product_contain_default_metadatas(step): assert_true(world.response.ok, 'RESPONSE: {}'.format(world.response.content)) response_body = response_body_to_dict(world.response, world.headers[ACCEPT_HEADER], xml_root_element_name=PRODUCT_METADATAS, is_list=True) assert_equals(len(response_body), 6) # Add default metadata 'tenant_id' metadatas_with_tenant = list(DEFAULT_METADATA[METADATA]) metadatas_with_tenant.append({"key": "tenant_id", "value": world.tenant_id}) # Workaround: xmldict manage Empty values as None value replace_none_value_metadata_to_empty_string(response_body) assert_equals(response_body, metadatas_with_tenant)
def then_the_metadatas_product_contain_default_metadatas(step): assert_true(world.response.ok, 'RESPONSE: {}'.format(world.response.content)) response_body = response_body_to_dict( world.response, world.headers[ACCEPT_HEADER], xml_root_element_name=PRODUCT_METADATAS, is_list=True) assert_equals(len(response_body), 6) # Add default metadata 'tenant_id' metadatas_with_tenant = list(DEFAULT_METADATA[METADATA]) metadatas_with_tenant.append({ "key": "tenant_id", "value": world.tenant_id }) # Workaround: xmldict manage Empty values as None value replace_none_value_metadata_to_empty_string(response_body) assert_equals(response_body, metadatas_with_tenant)