def a_created_product_with_name(self, step, product_name, metadatas=None): """ Creates new product in SDC if not exists, using default values. - Product parameters: * Metadata: Default values if metadatas is None * Attributes: if exist in world.attributes - list - Assertions: * Product response is OK :param step: Lettuce step :param product_name: The name of the product :param metadatas: Metadata list to be used in the new product :return: None """ response = self.api_utils.retrieve_product(headers=world.headers, product_id=product_name) if response.ok: print "WARNING: Product %s already exists. It will not be created." % product_name else: metadata_list = DEFAULT_METADATA[METADATA] if metadatas is None else metadatas if world.attributes is None: body_model = default_product(name=product_name, metadata=metadata_list) else: body_model = product_with_all_parameters(name=product_name, description='QA Test', metadata=metadata_list, attributes=world.attributes) body = body_model_to_body_request(body_model, world.headers[CONTENT_TYPE], body_model_root_element=PRODUCT) response = self.api_utils.add_new_product(headers=world.headers, body=body) assert_true(response.ok, response.content)
def when_i_add_the_new_product_with_all_the_parameters_with_accept_parameter_group1_response(step, accept_content): world.headers[ACCEPT_HEADER] = accept_content body = dict_to_xml(product_with_all_parameters(name=world.product_name, description=world.product_description, metadata=world.metadatas, attributes=world.attributes)) world.response = api_utils.add_new_product(headers=world.headers, body=body)
def when_i_add_the_new_product_with_all_the_parameters_with_accept_parameter_group1_response( step, accept_content): world.headers[ACCEPT_HEADER] = accept_content body = dict_to_xml( product_with_all_parameters(name=world.product_name, description=world.product_description, metadata=world.metadatas, attributes=world.attributes)) world.response = api_utils.add_new_product(headers=world.headers, body=body)