def test_companies_download_by_urllist(self): src_conf_path = os.path.join(WEB_SOURCES_CONFIG_DIR, 'web_statgov_companies.json') json_raw = Utils.read_file(src_conf_path) handler = HandlersFactory.get_handler( Downloader.handler_name(json_raw)) service = Downloader(json_raw, handler) file_paths = service.download() self.assertTrue(Utils.all_exists(file_paths))
def test_wrong_address_download_by_url(self): src_conf_path = os.path.join(WEB_SOURCES_CONFIG_DIR, 'web_kgdgov_wrong_address.json') json_raw = Utils.read_file(src_conf_path) handler = HandlersFactory.get_handler( Downloader.handler_name(json_raw)) service = Downloader(json_raw, handler) file_path = service.download() self.assertTrue(os.path.exists(file_path))
def test_pseudo_company_download_by_url(self): src_conf_path = os.path.join(WEB_SOURCES_CONFIG_DIR, 'web_kgdgov_pseudo_company.json') with open(src_conf_path, "r", encoding="utf8") as f: json_raw = f.read() handler = HandlersFactory.get_handler( Downloader.handler_name(json_raw)) service = Downloader(json_raw, handler) file_path = service.download() self.assertTrue(os.path.exists(file_path))
def test_kato_file_extract(self): src_conf_path = os.path.join(WEB_SOURCES_CONFIG_DIR, 'web_statgov_kato.json') json_raw = Utils.read_file(src_conf_path) download_handler = HandlersFactory.get_handler( Downloader.handler_name(json_raw)) service = Downloader(json_raw, download_handler) file_path = service.download() extract_handler = HandlersFactory.get_handler( Extractor.handler_name(json_raw)) service = Extractor(json_raw, file_path, extract_handler) file_paths = service.extract() self.assertTrue(Utils.all_exists(file_paths))
def test_companies_files_extract(self): src_conf_path = os.path.join(WEB_SOURCES_CONFIG_DIR, 'web_statgov_companies.json') json_raw = Utils.read_file(src_conf_path) download_handler = HandlersFactory.get_handler( Downloader.handler_name(json_raw)) service = Downloader(json_raw, download_handler) downloaded_files_path = service.download() extract_handler = HandlersFactory.get_handler( Extractor.handler_name(json_raw)) service = Extractor(json_raw, downloaded_files_path, TEMP_PATH, extract_handler) all_files = service.extract() self.assertTrue(Utils.all_exists(all_files))
def test_kurk_parse_to_csv(self): srconf_path = os.path.join(WEB_SOURCES_CONFIG_DIR, 'web_statgov_kurk.json') jobconf_path = os.path.join(JOBS_CONFIG_DIR, 'to_csv.json') src_json = Utils.read_file(srconf_path) job_json = Utils.read_file(jobconf_path) download_handler = HandlersFactory.get_handler( Downloader.handler_name(src_json)) service = Downloader(src_json, download_handler) downloaded_file = service.download() parse_handler = HandlersFactory.get_handler( XLSParser.handler_name(src_json, job_json)) service = XLSParser(src_json, job_json, downloaded_file, self.data_path, parse_handler) csvfile = service.path(src_json, job_json, self.data_path) rows_cnt = service.parse() self.assertTrue(os.path.exists(csvfile)) self.assertGreater(rows_cnt, 0)