Esempio n. 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()
Esempio n. 3
0
 def test_cloud_watch_logging_method(self):
     AppLogger.configure_and_get_logger(
         logger_name='test_cloud_watch',
         config_section_name=AppLoggerJsonConfigName.
         default_with_watchtower_format_1(),
         watchtower_log_group='test_log_group',
         watchtower_stream_name='local')
     with LogCapture() as lc:
         AppLogger.logger.info("test_me_aws")
         lc.check(('test_cloud_watch', 'INFO', 'test_me_aws'), )
    def test_2_get_json_from_file_method(self):
        AppLogger.configure_and_get_logger('2_get_json_from_file')
        with LogCapture() as lc:
            temp_dir, file_dir, full_file_name_list = UtilForTesting.file_setup(sub_directory="file_action",
                                                                                content='{"test1":"test2"')
            self.assertEqual(None, FileAction.get_json_from_file(full_file_name_list[0]))
            UtilForTesting.file_teardown(temp_dir)

            UtilForTesting.check_log_capture(
                self, lc, [('2_get_json_from_file', 'ERROR', "Error get_json_from_file: Expecting ',' delimiter")],
                ("exact", "exact", "startswith")
            )
Esempio n. 5
0
    def test_google_cloud_logging_method(self):
        AppLogger.configure_and_get_logger(
            logger_name='test_google',
            config_section_name=AppLoggerJsonConfigName.
            default_with_google_cloud_format_1(),
            google_project_name='sandbox')
        self.assertEqual('sandbox', AppLogger.get_google_project_name())

        with LogCapture() as lc:
            data = {"data": "{'field1': 'test1', 'field2': 'test2'}"}
            AppLogger.logger.info(f"test_me_gcp", extra=data)
            lc.check(('test_google', 'INFO', 'test_me_gcp'), )
Esempio n. 6
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'),
            )
Esempio n. 7
0
    def test_set_logging_level_with_aws_logging_method(self):
        AppLogger.configure_and_get_logger(
            logger_name='test_logging_level',
            config_section_name=AppLoggerJsonConfigName.
            default_with_watchtower_format_1(),
            watchtower_log_group="test_log_group",
            watchtower_stream_name="test_log_stream")

        AppLogger.logger.debug("debug test1")
        AppLogger.logger.info("info test1")
        AppLogger.logger.error("error test1")
        AppLogger.set_level(logging.DEBUG)
        AppLogger.logger.debug("debug test2")
        AppLogger.logger.info("info test2")
        AppLogger.logger.error("error test2")
Esempio n. 8
0
    def test_set_logging_level_method(self):
        AppLogger.configure_and_get_logger(logger_name='test_logging_level',
                                           logging_level=logging.INFO)

        with LogCapture() as lc:
            AppLogger.logger.debug("debug test1")
            AppLogger.logger.info("info test1")
            AppLogger.logger.error("error test1")
            AppLogger.set_level(logging.DEBUG)
            AppLogger.logger.debug("debug test2")
            AppLogger.logger.info("info test2")
            AppLogger.logger.error("error test2")
            lc.check(
                ('test_logging_level', 'INFO', 'info test1'),
                ('test_logging_level', 'ERROR', 'error test1'),
                ('test_logging_level', 'DEBUG', 'debug test2'),
                ('test_logging_level', 'INFO', 'info test2'),
                ('test_logging_level', 'ERROR', 'error test2'),
            )
Esempio n. 9
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()
Esempio n. 10
0
    def test_simple_logging_method(self):
        AppLogger.configure_and_get_logger(logger_name='test_simple')

        with LogCapture() as lc:
            AppLogger.logger.info("test_me_simple")
            lc.check(('test_simple', 'INFO', 'test_me_simple'), )
Esempio n. 11
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"))
Esempio n. 12
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()