コード例 #1
0
 def setUp(self):
     super().setUp()
     self.sign_in_for_ui_test(
         email=YAML_CONFIG.get("visual_test_user"),
         password=YAML_CONFIG.get("visual_test_password"),
         # Use is_debugging flag to login instead of register new account
         is_debugging=True)
    def sign_in_for_ui_test(self,
                            username=None,
                            email=None,
                            password=None,
                            bot_name=None,
                            faq_url=None,
                            is_debugging=False):
        try:
            if not is_debugging:
                # Generate data
                email = email or self.__data.create_email()
                username = username or self.__data.create_name()
                password = password or self.__data.create_password()
                bot_name = bot_name or self.__data.create_uuid_number()
                invalid_faq = faq_url or YAML_CONFIG.get(
                    "stub_invalid_faq_url")

                self.__register.open_register_page()
                self.__register.login_with_new_account(username, email,
                                                       password)
                self.__create_bot.wait_for_create_page()
                self.__create_bot.create_bot_with_data(bot_name, invalid_faq)
            else:
                email = email or YAML_CONFIG.get("email_for_debugging")
                password = password or YAML_CONFIG.get("pass_for_debugging")
                self.__login.login_with_account(email, password)
                self.__dashboard.wait_for_dashboard_page()

        except Exception as e:
            raise TestContextException(e)
 def sign_in_successfully(self,
                          email=YAML_CONFIG.get("sample_app_user"),
                          password=YAML_CONFIG.get("sample_app_pass")):
     self.post_data = {"email": email, "password": password}
     self.post(data=self.post_data)
     token = self.get_value_in_json_response_body("jwtToken")
     self.__jwt_token = f'JWT {token}'
     return self.response_code, self.response_body
コード例 #4
0
class BaseModel(object):
    '''
    We don't need to close mongodb connection
    because it will auto close
    '''
    __mongodb_client_host = YAML_CONFIG.get('database_url')
    __mongodb_client_port = YAML_CONFIG.get('database_port')
    mongodb_connection = connect(db=YAML_CONFIG.get("mongodb_db_name"),
                                 host=f'mongodb://{__mongodb_client_host}:{__mongodb_client_port}')
コード例 #5
0
 def test_crate_bot_successfully_with_invalid_url(self):
     self.__create_bot.create_new_bot(
         YAML_CONFIG.get("stub_invalid_faq_url"), "test_auto")
     assert self.__create_bot.response_code == 200, self.__create_bot.response_body
     assert len(
         self.__create_bot.get_bot_data_in_db(
             self.__create_bot.default_user_email)
     ) > 0, self.__create_bot.get_bot_data_in_db(
         self.__create_bot.default_user_email)
     assert self.__create_bot.get_bot_data_in_db(
         self.__create_bot.default_user_email
     )['website'] == YAML_CONFIG.get(
         "stub_invalid_faq_url"), self.__create_bot.get_bot_data_in_db(
             self.__create_bot.default_user_email)
 def __init__(self, *args, **kwargs):
     super(KnowledgeFeatureTests, self).__init__(*args, **kwargs)
     self.__data = DataGenerateUtils()
     self.__login = LoginPage()
     self.__create_bot = CreateBotPage()
     self.__register = RegisterPage()
     self.__appearance = AppearancePage()
     self.__knowledge_validation = KnowledgeValidation()
     self.__dashboard = DashboardPage()
     self.__knowledge = KnowledgePage()
     self.__data_set = DataUtils()
     self.valid_email = self.__data.create_email()
     self.valid_username = self.__data.create_name()
     self.valid_password = self.__data.create_password()
     self.faq_url = YAML_CONFIG.get("stub_manual_faq_url")
     self.invalid_faq = YAML_CONFIG.get("stub_invalid_faq_url")
コード例 #7
0
 def __init__(self, bot_id=YAML_CONFIG.get("sample_app_bot_id")):
     super().__init__("/bot/{}/knowledges/train".format(bot_id))
     self.__bot_id = bot_id
     self.__sign_in = SignIn()
     self.__get_token_by_sign_in()
     self.__pending_faqs = TrainFaq.PendingFAQ(bot_id,
                                               self.__sign_in.jwt_token)
コード例 #8
0
 def __init__(self):
     super().__init__()
     os.environ['API_HOST'] = PROTOCOL + "://" + YAML_CONFIG.get(
         "predict_host")
     os.environ['API_PROTOCOL'] = PROTOCOL
     self.__init_data = PredictService.PredictInitData()
     self.__predict = PredictService.PredictGetAnswer()
     self.__faq_data = PredictService.PredictGetAllData()
コード例 #9
0
 def test_create_bot_unsuccessfully_with_empty_bot_name(self):
     self.__create_bot.create_new_bot(YAML_CONFIG.get("stub_faq_url"), "")
     assert self.__create_bot.response_code == 400, self.__create_bot.response_body
     assert self.__create_bot.get_value_in_json_response_body(
         "error"
     )['code'] == CreateBotTest.REQUIRED_FILED_ERROR_CODE, self.__create_bot.response_body
     assert self.__create_bot.get_value_in_json_response_body(
         "error"
     )["message"] == CreateBotTest.REQUIRED_FILED_ERROR_MSG, self.__create_bot.response_body
コード例 #10
0
 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 __init__(self, *args, **kwargs):
     super(CreateBotFeatureTests, self).__init__(*args, **kwargs)
     self.__data = DataGenerateUtils()
     self.__login = LoginPage()
     self.__create_bot = CreateBotPage()
     self.__register = RegisterPage()
     self.__appearance = AppearancePage()
     self.__create_bot_validation = CreateBotValidation()
     self.__drop_down_list = DropDownList()
     self.__data_set = DataUtils()
     self.valid_email = self.__data.create_email()
     self.valid_username = self.__data.create_name()
     self.valid_password = self.__data.create_password()
     self.faq_url = YAML_CONFIG.get("stub_faq_url")
コード例 #12
0
    def __init__(self, *args, **kwargs):
        super(TestAuthenticationPages, self).__init__(*args, **kwargs)
        self.__login = LoginPage()
        self.__register = RegisterPage()
        self.__forgot_password = ForgotPasswordPage()

        self.__data = DataGenerateUtils()
        self.valid_email = self.__data.create_email()
        self.valid_username = self.__data.create_name()
        self.valid_password = self.__data.create_password()

        self.bot_name = "Test"
        self.invalid_faq = "google.com"
        self.eyes = Eyes()
        self.eyes.api_key = YAML_CONFIG.get("eyes_api_key")
コード例 #13
0
 def __init__(self, *args, **kwargs):
     super(AppearanceTests, self).__init__(*args, **kwargs)
     self.__data = DataGenerateUtils()
     self.__login = LoginPage()
     self.__create_bot = CreateBotPage()
     self.__register = RegisterPage()
     self.__appearance = AppearancePage()
     self.__create_bot_validation = CreateBotValidation()
     self.__drop_down_list = DropDownList()
     self.__chat_box_simulator = ClientSimulator()
     self.__loader = LoaderComponent()
     self.__data_set = DataUtils()
     self.valid_email = self.__data.create_email()
     self.valid_username = self.__data.create_name()
     self.valid_password = self.__data.create_password()
     self.bot_name = self.__data.create_uuid_number()
     self.faq_url = YAML_CONFIG.get("stub_faq_url")
コード例 #14
0
 def test_forgot_password_page_appearance(self):
     try:
         self.eyes.open(driver=self.__login.driver.core_driver,
                        app_name='sample_app',
                        test_name='Forgot Password Page',
                        viewport_size={'width': 1440, 'height': 887})
         self.__forgot_password.open_forgot_password_page()
         self.__forgot_password.wait_for_forgot_password_page()
         self.eyes.check_window("Default Forgot password page")
         self.__forgot_password.submit_email("")
         self.eyes.check_window("Submit empty email")
         self.__forgot_password.submit_email("*****@*****.**")
         self.eyes.check_window("Submit with wrong email format")
         self.__forgot_password.submit_email(YAML_CONFIG.get("sample_app_user"))
         self.eyes.check_window("Submit successfully")
     finally:
         res = self.eyes.close(raise_ex=True)
         print(res)
         self.eyes.abort_if_not_closed()
コード例 #15
0
 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 __init__(self, *args, **kwargs):
     super(TestConversationDuration, self).__init__(*args, **kwargs)
     self.__data = DataGenerateUtils()
     self.__create_bot = CreateBotPage()
     self.__register = RegisterPage()
     self.__appearance = AppearancePage()
     self.__integration = IntegrationPage()
     self.__create_bot_validation = CreateBotValidation()
     self.__html_file = HTMLFileUtils()
     self.__client_simulator = ClientSimulator()
     self.__conversation = ConversationPage()
     self.valid_email = self.__data.create_email()
     self.valid_username = self.__data.create_name()
     self.valid_password = self.__data.create_password()
     self.bot_name = self.__data.create_uuid_number()
     self.invalid_faq = YAML_CONFIG.get("stub_invalid_faq_url")
     self.integrated_page_path = ""
     self.root_path = os.path.dirname(
         os.path.dirname(os.path.abspath(__file__)))
     self.file_path = os.path.normpath(
         os.path.join(self.root_path, 'TestGUI', 'index.html'))
コード例 #17
0
 def __init__(self, *args, **kwargs):
     super(TestAdminPages, self).__init__(*args, **kwargs)
     self.__data = DataGenerateUtils()
     self.__login = LoginPage()
     self.__create_bot = CreateBotPage()
     self.__register = RegisterPage()
     self.__dashboard = DashboardPage()
     self.__appearance = AppearancePage()
     self.__create_bot_validation = CreateBotValidation()
     self.__drop_down_list = DropDownList()
     self.__change_password = ChangePasswordPage()
     self.__knowledge = KnowledgePage()
     self.__data_set = DataUtils()
     self.__faq_knowledge_data_table_component = FaqKnowledgeDataTableComponent(
     )
     self.valid_email = self.__data.create_email()
     self.valid_username = self.__data.create_name()
     self.valid_password = self.__data.create_password()
     self.bot_name = "Test"
     self.invalid_faq = "google.com"
     self.eyes = Eyes()
     self.eyes.api_key = YAML_CONFIG.get("eyes_api_key")
     self.eyes.force_full_page_screenshot = True
     self.eyes.stitch_mode = StitchMode.CSS
コード例 #18
0
 def __init__(self, bot_id=YAML_CONFIG.get("sample_app_bot_id")):
     super().__init__("/bot/{}/personality".format(bot_id))
     self.__bot_id = bot_id
     self.__crud_personality = None
     self.__sign_in = SignIn()
     self.__get_token_by_sign_in()
コード例 #19
0
class RedisQuery(DatabaseQuery):
    redisdb_name = 0
    redisdb_ssh_host = YAML_CONFIG.get("database_url")
    redisdb_ssh_username = YAML_CONFIG.get("mongodb_user")
    redisdb_ssh_password = YAML_CONFIG.get("mongodb_pass")
    redisdb_client_host = YAML_CONFIG.get("redis_host")
    redisdb_client_port = YAML_CONFIG.get("redis_port")

    def __init__(self, database_name, host, username, password, client_host,
                 client_port):
        self.__db_name = database_name or self.redisdb_name
        self.__redis_host = host or self.redisdb_ssh_host
        self.__redis_username = username or self.redisdb_ssh_username
        self.__redis_password = password or self.redisdb_ssh_password
        self.__redis_client_host = client_host or self.redisdb_client_host
        self.__redis_client_port = client_port or self.redisdb_client_port
        self.__server = None
        self.__client = None
        self.__db = None

    @DatabaseQuery.query_invoke
    def get_object_by_id(self, collection, object_id):
        return self.get_object(collection, "id", object_id)

    @DatabaseQuery.query_invoke
    def get_object(self, collection, key, value):
        keys = self.__db.keys("*{}*".format(collection))
        for item in keys:
            # convert to dict
            obj = ast.literal_eval(self.__db.get(item))
            try:
                if obj[key] == value:
                    break
            except KeyError:
                # continue loop when encountering object where "key" does not exist
                continue
        else:
            raise Exception("No object matches provided key and value.")
        return obj

    def get_collection(self, collection):
        self.create_connection()
        return self.__db.keys("*{}*".format(collection))

    @DatabaseQuery.query_invoke
    def get_all_item_in_collection(self, collection):
        return [
            ast.literal_eval(self.__db.get(key))
            for key in self.__db.keys("*{}*".format(collection))
        ]

    @DatabaseQuery.query_invoke
    def get_item_in_collection(self, collection, filter_query):
        return ast.literal_eval(
            self.__db.get(
                self.__db.keys("*{0}*{1}*".format(collection,
                                                  filter_query))[0]))

    @DatabaseQuery.query_invoke
    def get_list_item_in_collection(self, collection, filter_query):
        return [
            ast.literal_eval(self.__db.get(key))
            for key in self.__db.keys("*{0}*{1}*".format(
                collection, filter_query))
        ]

    @DatabaseQuery.query_invoke
    def count_item_in_query(self, collection, filter_query):
        return len(self.__db.keys(filter_query))

    def create_connection(self):
        if not self.__db:
            self.__server = SSHTunnelForwarder(
                self.__redis_host,
                ssh_username=self.__redis_username,
                ssh_password=self.__redis_password,
                remote_bind_address=(self.__redis_client_host,
                                     self.__redis_client_port),
                local_bind_address=('localhost', 8080))
            self.__server.start()
            self.__db = redis.StrictRedis(
                host=self.__server.local_bind_address[0],
                port=self.__server.local_bind_address[1],
                db=self.__db_name,
                charset="utf-8",
                decode_responses=True)

    def close_connection(self):
        self.close_server()
        self.close_client_connection()
        self.__db = None

    def close_client_connection(self):
        if self.__client:
            self.__client.close()

    def close_server(self):
        if self.__server:
            self.__server.stop()

    __module__ = "redis"
class MongoQuery(DatabaseQuery):
    mongodb_name = YAML_CONFIG.get("mongodb_db_name")
    mongodb_host = YAML_CONFIG.get("mongodb_host")
    mongodb_username = YAML_CONFIG.get("mongodb_user")
    mongodb_password = YAML_CONFIG.get("mongodb_pass")
    mongodb_client_host = YAML_CONFIG.get('database_url')
    mongodb_client_port = YAML_CONFIG.get('database_port')

    def __init__(self, database_name, host, username, password, client_host,
                 client_port):
        self.__db_name = database_name or self.mongodb_name
        self.__mongo_host = host or self.mongodb_host
        self.__mongo_username = username or self.mongodb_username
        self.__mongo_password = password or self.mongodb_password
        self.__mongo_client_host = client_host or self.mongodb_client_host
        self.__mongo_client_port = client_port or self.mongodb_client_port
        self.__server = None
        self.__client = None
        self.__db = None

    @DatabaseQuery.query_invoke
    def get_object_by_id(self, collection, object_id):
        return self.__db[collection].find({"_id": object_id})

    @DatabaseQuery.query_invoke
    def get_object(self, collection, key, value):
        return self.__db[collection].find({key: value})

    def get_collection(self, collection):
        self.create_connection()
        return self.__db[collection]

    @DatabaseQuery.query_invoke
    def get_all_item_in_collection(self, collection):
        result = self.__db[collection].find()
        list_items = []
        for r in result:
            list_items.append(r)
        return list_items

    @DatabaseQuery.query_invoke
    def get_item_in_collection(self, collection, filter_query):
        return self.__db[collection].find_one(filter_query)

    @DatabaseQuery.query_invoke
    def get_list_item_in_collection(self, collection, filter_query):
        c = self.__db[collection]
        result = []
        for item in c.find(filter_query):
            result.append(item)
        return result

    @DatabaseQuery.query_invoke
    def count_item_in_query(self, collection, filter_query):
        return self.__db[collection].find(filter_query).count()

    def create_connection(self):
        """
                for connect via ssh tunnel
                self.__server = SSHTunnelForwarder(
                        self.__host,
                        ssh_username=self.__user,
                        ssh_password=self.__pass,
                        remote_bind_address=(YAML_CONFIG.get('database_url'), YAML_CONFIG.get('database_port'))
                    )
                    self.__server.start()
                :return:
        """
        if not self.__db:
            self.__client = MongoClient(self.__mongo_client_host,
                                        self.__mongo_client_port)
            self.__db = self.__client[self.__db_name]

    def close_connection(self):
        self.close_client_connection()
        self.close_server()
        self.__db = None

    def close_client_connection(self):
        if self.__client:
            self.__client.close()

    def close_server(self):
        if self.__server:
            self.__server.close()

    __module__ = "mongo"
コード例 #21
0
 def __init__(self, bot_id=YAML_CONFIG.get("sample_app_bot_id")):
     super().__init__(f"/bot/{bot_id}")
     self.bot_id = bot_id
     self.__sign_in = SignIn()
     self.__get_token_by_sign_in()
コード例 #22
0
 def __init__(self, bot_id=YAML_CONFIG.get("sample_app_bot_id")):
     super().__init__("/bot/{}/knowledges/faq_url".format(bot_id))
     self.__bot_id = bot_id
     self.__sign_in = SignIn()
     self.__get_token_by_sign_in()