Пример #1
0
    def test_get_methods(self):
        AppLogger.configure_and_get_logger("test_logger")
        AppLogger.set_debug_level()

        temp_dir, file_dir, full_file_name_list = UtilForTesting.file_setup(
            'test_df_3',
            extension="",
            content=
            "col1|col2\ntest1|test2\ntest1|test2\ntest1|test2\ntest1|test2\ntest1|test2",
            count=2)

        response = ApiReponse(
            self.app.post(
                '/load_from_csv/',
                # headers={
                #     'Authorization': 'Bearer ' + JWT.create_access_token(user_name="123", password="******")},
                data={
                    "server_name": "localhost\sqlexpress",
                    "database_name": "master",
                    "schema_name": "dbo",
                    "table_name": "ms_sql_server_proxy_load_from_csv_1",
                    "csv_root_directory": file_dir
                },
                follow_redirects=True))
        self.assertEqual(201, response.status_code)
        for file in full_file_name_list:
            self.assertEqual(True, os.path.exists(f"{file}.done"))

        ms_sql = MsSqlServer(
            "DRIVER={ODBC Driver 13 for SQL Server}; SERVER=localhost\sqlexpress; DATABASE=master; Trusted_Connection=yes;"
        )
        df = ms_sql.read_data_into_dataframe(
            "select count(1) as record_count from [dbo].[ms_sql_server_proxy_load_from_csv_1]"
        )
        self.assertEqual(10, df.iloc[0]['record_count'])
 def main(logger_name):
     config_dict = RunAppBase.get_config_dict()
     AppLogger.configure_and_get_logger(
         logger_name,
         AppLoggerJsonConfigName.default_with_watchtower_format_1(),
         watchtower_log_group=config_dict["APPLICATION_NAME"],
         watchtower_stream_name=config_dict["ENVIRONMENT"])
     if config_dict["DEBUG_MODE"].upper() == "TRUE":
         AppLogger.set_debug_level()
Пример #3
0
    def test_4__configure_logger_method(self):
        AppLogger.logger = logging.getLogger('test_configure_3')
        AppLogger.logger.level = logging.DEBUG
        AppLogger.config_dict = None

        AppLogger._configure_logger(
            AppLoggerJsonConfigName.default_with_watchtower_format_1(),
            'test_log_group', 'test_log_stream')
        AppLogger.set_debug_level()
        AppLogger.logger.debug('This is a test')
Пример #4
0
    def test_start_stop_test_methods(self):
        AppLogger.configure_and_get_logger('start_stop_test')
        AppLogger.set_debug_level()

        with LogCapture() as lc:
            timer = Timer()
            timer.start_timer()
            timer.pause(time_in_seconds=2)
            timer.stop_timer()

            self.assertEqual(timer.time_elapsed_in_seconds, 2)
            lc.check_present(
                ('start_stop_test', 'DEBUG', 'Sleep for [2] seconds'),
            )
Пример #5
0
    def test_write_df_to_csv_creating_instance_method(self):
        AppLogger.configure_and_get_logger(logger_name='test_simple')
        AppLogger.set_debug_level()

        temp_filename = os.path.join(os.path.dirname(__file__), 'temp',
                                     'test_file1')
        os.makedirs(os.path.dirname(temp_filename), exist_ok=True)
        df = pd.DataFrame({
            'seconds': ["3600"],
            'minutes': ["10"]
        },
                          columns=['seconds', 'minutes'])
        bcp_ff = BcpFileFormat(df, temp_filename)
        bcp_temp = BcpTempCsvFile.write_df_to_csv_creating_instance(df, bcp_ff)

        assert_frame_equal(df, bcp_temp.pandas_dataframe)
        self.assertEqual(bcp_ff, bcp_temp.bcp_file_format)
        self.assertEqual(f"{temp_filename}.csv", bcp_temp.csv_full_file_name)
        self.assertEqual(False, bcp_temp.use_index)
        self.assertEqual(True, os.path.exists(f"{temp_filename}.csv"))

        bcp_temp.remove_file()
Пример #6
0
 def test_find_root_of_project(self):
     AppLogger.configure_and_get_logger("test")
     AppLogger.set_debug_level()
     self.assertTrue(
         Root.find_root_of_project(__file__).endswith("zeppos_root"))
Пример #7
0
            # , Read, Upsert, Execute


class App:
    def create_app(self, class_object_list):
        AppLogger.logger.info("creating app")
        flask_app = Flask(__name__)
        # swagger = Swagger(flask_app)
        api = Api(flask_app)
        for class_object in class_object_list:
            class_object.add_routes(api)

        return flask_app

    @staticmethod
    def create_app_instance(class_object_list):
        AppLogger.logger.info("Create App Instance")
        return App().create_app(class_object_list)


if __name__ == '__main__':
    AppLogger.configure_and_get_logger(
        'ms_sql_server_proxy_monitor',
        AppLoggerJsonConfigName.default_with_watchtower_format_1(),
        watchtower_log_group="ms_sql_server_proxy",
        watchtower_stream_name="app"
    )
    AppLogger.set_debug_level()
    RunServer().run_server()