def get(self, url): try: response = self.http_request.get(url) cleaned_response = clean_response(response) return cleaned_response except Exception: log.error('\n%s' % traceback.format_exc()) raise AssertionError
def delete(self, url, request_api=True): try: response = self.http_request.delete(url) cleaned_response = clean_response(response) if request_api: check_request_id(self.api_request, cleaned_response['request_id']) return cleaned_response except Exception: log.error('\n%s' % traceback.format_exc()) raise AssertionError
def patch(self, url, data, request_api=True): try: log.info('data to patch\n %s' % data) response = self.http_request.patch(url, data) cleaned_response = clean_response(response) if request_api: check_request_id(self.api_request, cleaned_response['request_id']) return cleaned_response except Exception: log.error('\n%s' % traceback.format_exc()) raise AssertionError
def post(self, url, data, request_api=True): try: log.info("data to post:\n%s" % data) response = self.http_request.post(url, data) cleaned_response = clean_response(response) if request_api: check_request_id(self.api_request, cleaned_response["request_id"]) return cleaned_response except Exception: log.error("\n%s" % traceback.format_exc()) raise AssertionError
def exec_test(config_data): add_test_info = AddTestInfo(17, '\napi/v2/user\n' 'api/v2/user/<pk>') add_test_info.started_info() try: test = Test(**config_data) # --------------- get users -------------- response = test.get(test.user_url) clean_response(response) # --------------- create new users -------------- new_user = UserCreationDefination() new_user.username = names.get_first_name().lower() new_user.email = '*****@*****.**' new_user.password = '******' log.info('new username: %s' % new_user.username) response = test.post(test.user_url, new_user.__dict__) new_user_created = clean_response(response) new_uid = new_user_created['id'] logged_out = test.logout() assert logged_out, "logout failed" # ------------- edit the user details by logging back as the new user --------------- new_config_data = config_data.copy() new_config_data['username'] = new_user.username new_config_data['password'] = new_user.password test2 = Test(**new_config_data) edit = UserCreationDefination() edit.email = '*****@*****.**' response = test2.patch(test.user_url + "/" + str(new_uid), edit.__dict__) clean_response(response) test2.logout() # --------------- delete the created user --------------- test3 = Test(**config_data) response = test3.delete(test3.user_url + "/" + str(new_uid)) clean_response(response) response = test3.get(test2.user_url) clean_response(response) add_test_info.success('test ok') except Exception: log.error('\n%s' % traceback.format_exc()) add_test_info.failed('test error') return add_test_info.completed_info(config_data['log_copy_location'])