def test_update_personality_with_non_default_response_successfully(self): old_response = self.get_a_random_response_in_fixture_data() new_response = self.random_a_new_string() self.__crud_personality.update_personality(old_response, new_response) returned_personality_object = self.__crud_personality.get_value_in_json_response_body( "personality") self.verify_status_code_is(self.SUCCESS_CODE) assert isinstance(self.__crud_personality.get_value_in_json_response_body("personality"), dict) is True, \ f"HTTP response does not contains personality object" APIAssert.should_run_api_successfully( self.assert_container(self.assertEquals, returned_personality_object["id"], self.__fixture_data["id"]), self.assert_container( self.assertEquals, len(returned_personality_object["responses"]), len(self.__fixture_data["responses"])), self.assert_container(self.assertIn, new_response, returned_personality_object["responses"]), self.assert_container(self.assertNotIn, old_response, returned_personality_object["responses"]), self.assert_container( self.assertEquals, returned_personality_object["defaultResponse"], self.__fixture_data["defaultResponse"]))
def test_sign_up_unsuccessfully_with_blank_email_password(self): self.__sign_up.create_new_user_account(username=self.__data.create_name()) APIAssert.should_run_api_successfully( self.assert_container(self.assertEqual, self.__sign_up.response_code, 400), self.assert_container(self.assertEqual, self.INVALID_PARAM, JSONUtils.get_value_json_string(self.__sign_up.response_body, "error")['code']) )
def test_sign_in_unsuccessfully_with_invalid_param_no_email(self): self.__sign_in.sign_in(email="", password=self.DEFAULT_PASSWORD) APIAssert.should_run_api_successfully( self.assert_container(self.assertEqual, self.__sign_in.response_code, 400), self.assert_container( self.assertEqual, self.INVALID_PARAM, JSONUtils.get_value_json_string(self.__sign_in.response_body, "error")['code']))
def test_add_faq_unsuccessfully_with_blank_url(self): self.__add_faq.add_new_faq(url=None) APIAssert.should_run_api_successfully( self.assert_container(self.assertEqual, self.__add_faq.response_code, 200), self.assert_container( self.assertEqual, self.ERROR_MISSING_FAQ_URL, self.__add_faq.get_value_in_json_response_body( 'error', True)['message']))
def test_sign_in_unsuccessfully_with_invalid_email_password(self): self.__sign_in.sign_in(email=self.INVALID_EMAIL, password=self.INVALID_PASSWORD) APIAssert.should_run_api_successfully( self.assert_container(self.assertEqual, self.__sign_in.response_code, 400), self.assert_container( self.assertEqual, self.BLANK_FIELD_CODE, JSONUtils.get_value_json_string(self.__sign_in.response_body, "error")['code']))
def test_init_data_service_return_enough_data(self): data_path = path.join(FAQ_DATA_PATH, KATALON_DATA_FILE_NAME) company_id = self.__data.create_name() with open(data_path, "r", encoding='utf-8') as f: data = f.read() code, body = self.__predict.init_predict_data(company_id, data) _, initialized_faq = self.__predict.get_all_faq_data(company_id) APIAssert.should_run_api_successfully( self.assert_container(self.assertEqual, code, 200), )
def test_sign_in_successfully_with_valid_data(self): self.__sign_in.sign_in(email=self.__email, password=self.DEFAULT_PASSWORD) APIAssert.should_run_api_successfully( self.assert_container(self.assertEqual, self.__sign_in.response_code, 200), self.assert_container( self.assertGreater, len( JSONUtils.get_value_json_string( self.__sign_in.response_body, "jwtToken")), 20))
def test_sign_up_successfully_with_valid_data(self): self.__sign_up.create_new_user_account(username=self.__data.create_name(), email=self.__data.create_email(), password=self.__data.create_password()) APIAssert.should_run_api_successfully( self.assert_container(self.assertEqual, self.__sign_up.response_code, 200), self.assert_container(self.assertIn, self.__sign_up.post_data['username'], self.__sign_up.response_body), self.assert_container(self.assertIn, self.__sign_up.post_data['email'], self.__sign_up.response_body), self.assert_container(self.assertGreater, len(JSONUtils.get_value_json_string(self.__sign_up.response_body, "jwtToken")), 20) )
def test_add_faq_successfully(self): self.__add_faq.add_new_faq(url=self.data[1][0]) APIAssert.should_run_api_successfully( self.assert_container(self.assertEquals, self.__add_faq.response_code, 200), self.assert_container( self.assertEquals, self.__add_faq.get_value_in_json_response_body("knowledges")[0] ["botId"], self.__add_faq.bot_id)) self.verify_faqs_created_in_database( bot_id=YAML_CONFIG.get("sample_app_bot_id"), url=self.data[1][0], expected_number_of_faqs=int(self.data[1][1]))
def test_sign_up_unsuccessfully_with_existing_email(self): username = self.__data.create_name() email = self.__data.create_email() password = self.__data.create_password() self.__sign_up.create_new_user_account(username=username, email=email, password=password) self.API_PAY_LOAD.append(self.__sign_up.post_data) self.__sign_up.create_new_user_account(username=username, email=email, password=password) APIAssert.should_run_api_successfully( self.assert_container(self.assertEqual, self.__sign_up.response_code, 400), self.assert_container(self.assertEqual, self.EXISTING_EMAIL, JSONUtils.get_value_json_string(self.__sign_up.response_body, "error")['code']) )
def test_add_ten_faqs_successfully(self): # TODO(minhhoang): urls.csv only has few url now. Update it len_of_data = len(self.data) for i in range(1, len_of_data): print("Test with URL: {}".format(self.data[i][0])) self.__add_faq.add_new_faq(url=self.data[i][0]) APIAssert.should_run_api_successfully( self.assert_container(self.assertEquals, self.__add_faq.response_code, 200), self.assert_container( self.assertEquals, self.__add_faq.get_value_in_json_response_body( "knowledges")[0]["botId"], self.__add_faq.bot_id)) expected_number_of_this_faq_url = int( self.data[i][1]) if self.data[i][1] else None self.verify_faqs_created_in_database( bot_id=YAML_CONFIG.get("sample_app_bot_id"), url=self.data[i][0], expected_number_of_faqs=expected_number_of_this_faq_url)
def test_add_personality_successfully(self): random_message = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(20)) # Add new message self.__crud_personality.add_personality(responses=[random_message], indexes=[5]) APIAssert.should_run_api_successfully( self.assert_container(self.assertEquals, self.__crud_personality.response_code, 200), self.assert_container( self.assertEquals, self.__crud_personality.get_value_in_json_response_body("personality")["id"], self.__fixture_data["id"] ), self.assert_container( self.assertEquals, len(self.__crud_personality.get_value_in_json_response_body("personality")["responses"]), len(self.__fixture_data["responses"]) + 1 ), self.assert_container( self.assertIn, random_message, self.__crud_personality.get_value_in_json_response_body("personality")["responses"] ) )
def xtest_delete_non_default_response_successfully(self): response = self.get_a_random_response_in_fixture_data() self.__crud_personality.delete_personality([response]) assert self.__crud_personality.response_code == self.SUCCESS_CODE, \ f"Expect status code {self.SUCCESS_CODE} but {self.__crud_personality.response_code} is returned" returned_personality_object = self.__crud_personality.get_value_in_json_response_body( "personality") assert isinstance(returned_personality_object, dict) is True, \ "HTTP response does not contains personality object" APIAssert.should_run_api_successfully( self.assert_container(self.assertEquals, returned_personality_object["id"], self.__fixture_data["id"]), self.assert_container( self.assertEquals, len(returned_personality_object["responses"]), len(self.__fixture_data["responses"]) - 1), self.assert_container(self.assertNotIn, response, returned_personality_object["responses"]), self.assert_container( self.assertEquals, returned_personality_object["defaultResponse"], self.__fixture_data["defaultResponse"]))
def __init__(self): self.assertion = Assert() self.api_assertion = APIAssert() self.assertion.log = self.__log