def test_get_customers(): # make a call to get all customers r = RequestUtility() rs_api = r.get(endpoint='customers',payload=None,headers=None,expected_status_code=200) # verify whether the responce is not empty assert rs_api ,f"No customer is present" #import pdb ; pdb.set_trace() # validate response is not empty
class CustomerHelper(object): def __init__(self): self.request_utility = RequestUtility() #For creating the new customer def create_customer(self, email=None, password=None, **kwargs): if not email: email = random_email_and_password()['email'] if not password: password = random_email_and_password()['password'] payload = dict() payload['email'] = email payload['password'] = password payload.update(kwargs) #import pdb;pdb.set_trace() # Make the api call rs_pi = self.request_utility.post('customers', payload, expected_status_code=201, headers=None) #import pdb;pdb.set_trace() return rs_pi
class Product_Helper(): def __init__(self): self.product_utility = RequestUtility() def get_product_by_id(self,id): api_rs = self.product_utility.get(f"products/{id}") return api_rs def call_create_product(self,payload = None): rs_api = self.product_utility.post(endpoint='products',payload = payload,expected_status_code=201) return rs_api def call_product_by_date(self, payload=None): return self.product_utility.get('products', payload=payload) # def call_product_by_date(self, payload=None): # # max_pages = 1000 # all_products = [] # for i in range(1, max_pages + 1): # logger.debug(f"List products page number: {i}") # # if not payload: # payload = {} # # if not 'per_page' in payload.keys(): # payload['per_page'] = 100 # # # add the current page number to the call # payload['page'] = i # rs_api = self.product_utility.get('products', payload=payload) # # # if there is not response then stop the loop b/c there are no more products # if not rs_api: # break # else: # all_products.extend(rs_api) # else: # raise Exception(f"Unable to find all products after {max_pages} pages.") # # return all_products
def test_get_list_of_products(): # make a call rs_api = RequestUtility().get(endpoint='products', payload=None, headers=None, expected_status_code=200) #import pdb; pdb.set_trace() assert rs_api, f"No product in the list"
def create_order(self, addtion_arg=None): payload_path = os.path.join(self.cur_file_dir, '..', 'data', 'create_order.json') with open(payload_path) as f: payload = json.load(f) payload.update(addtion_arg) rs_api = RequestUtility().post(endpoint='orders', payload=payload, headers=None, expected_status_code=201) return rs_api
def test_existing_cusomter(): rs_db = DB_Customer().get_random_user() db_id = rs_db[0]['ID'] endpoint = f"customers/{db_id}" db_un = rs_db[0]['display_name'] # import pdb ; pdb.set_trace() rs_api = RequestUtility().post(endpoint=endpoint, headers=None, expected_status_code=200, payload=None) rs_un = rs_api[1]['username'] assert db_un == rs_un, f" db user name doesnot match with rs_un"
def test_customer_create_same_email(): rs_db = DB_Customer().get_random_user() db_email = rs_db[0]['user_email'] payload = dict() payload['email'] = db_email payload['passowrd'] = 'password' rs_api = RequestUtility().post(endpoint='customers', headers=None, expected_status_code=400, payload=payload) # import pdb ; pdb.set_trace() assert rs_api[1][ 'code'] == 'registration-error-email-exists', f"Expected code message was {'registration-error-email-exists'}" message = f"""An account is already registered with your email address. <a href="#" class="showlogin">Please log in.</a>""" assert len(rs_api[1]['message']) == len(message), f"Incorrect message"
def __init__(self): self.product_utility = RequestUtility()
def __init__(self): self.request_utility = RequestUtility()