def setUpClass(cls): mdb, datastore = run_environment('mysql', config) cls.mdb = mdb models = cls.mdb.get_models() models = [x['name'] for x in models] if TEST_PREDICTOR_NAME in models: cls.mdb.delete_model(TEST_PREDICTOR_NAME) test_csv_path = get_test_csv(TEST_CSV['name'], TEST_CSV['url']) query('create database if not exists test') test_tables = query('show tables from test') test_tables = [x[0] for x in test_tables] if TEST_DATA_TABLE not in test_tables: print('creating test data table...') query(f''' CREATE TABLE test.{TEST_DATA_TABLE} ( number_of_rooms int, number_of_bathrooms int, sqft int, location varchar(100), days_on_market int, initial_price int, neighborhood varchar(100), rental_price int ) ''') with open(test_csv_path) as f: csvf = csv.reader(f) i = 0 for row in csvf: if i > 0: number_of_rooms = int(row[0]) number_of_bathrooms = int(row[1]) sqft = int(float(row[2].replace(',', '.'))) location = str(row[3]) days_on_market = int(row[4]) initial_price = int(row[5]) neighborhood = str(row[6]) rental_price = int(float(row[7])) query(f'''INSERT INTO test.{TEST_DATA_TABLE} VALUES ( {number_of_rooms}, {number_of_bathrooms}, {sqft}, '{location}', {days_on_market}, {initial_price}, '{neighborhood}', {rental_price} )''') i += 1 print('done') ds = datastore.get_datasource(EXTERNAL_DS_NAME) if ds is not None: datastore.delete_datasource(EXTERNAL_DS_NAME) short_csv_file_path = get_test_csv(f'{EXTERNAL_DS_NAME}.csv', TEST_CSV['url'], lines_count=300, rewrite=True) datastore.save_datasource(EXTERNAL_DS_NAME, 'file', 'test.csv', short_csv_file_path)
def setUpClass(cls): run_container('mongo-config') ready = wait_port(27000, DOCKER_TIMEOUT) assert ready run_container('mongo-instance') ready = wait_port(27001, DOCKER_TIMEOUT) assert ready cls.config_client = MongoClient('mongodb://localhost:27000/') cls.instance_client = MongoClient('mongodb://localhost:27001/') print('init replconf') try: r = cls.config_client.admin.command( 'replSetInitiate', { '_id': 'replconf', 'members': [{ '_id': 0, 'host': '127.0.0.1:27000' }] }) except Exception as e: print('already initialized') if str(e) == 'already initialized': r = {'ok': 1} if bool(r['ok']) is not True: assert False print('init replmain') try: r = cls.instance_client.admin.command( 'replSetInitiate', { '_id': 'replmain', 'members': [{ '_id': 0, 'host': '127.0.0.1:27001' }] }) except Exception as e: print('already initialized') if str(e) == 'already initialized': r = {'ok': 1} if bool(r['ok']) is not True: assert False mdb, datastore = run_environment('mongodb', config, run_apis='mongodb') cls.mdb = mdb models = cls.mdb.get_models() models = [x['name'] for x in models] if TEST_PREDICTOR_NAME in models: cls.mdb.delete_model(TEST_PREDICTOR_NAME) test_csv_path = get_test_csv(TEST_CSV['name'], TEST_CSV['url']) db = cls.instance_client['test_data'] colls = db.list_collection_names() if 'home_rentals' not in colls: print('creatating test data') with open(test_csv_path) as f: csvf = csv.reader(f) data = [] for i, row in enumerate(csvf): if i > 0: data.append( dict(number_of_rooms=int(row[0]), number_of_bathrooms=int(row[1]), sqft=int(float(row[2].replace(',', '.'))), location=str(row[3]), days_on_market=int(row[4]), initial_price=int(row[5]), neighborhood=str(row[6]), rental_price=int(float(row[7])))) db['home_rentals'].insert_many(data) print('done') run_container('mongo-mongos') ready = wait_port(27002, DOCKER_TIMEOUT) assert ready cls.mongos_client = MongoClient('mongodb://localhost:27002/') cls.mongos_client.admin.command('addShard', 'replmain/127.0.0.1:27001') cls.mongos_client.admin.command( 'addShard', f"127.0.0.1:{config['api']['mongodb']['port']}")
def setUpClass(cls): mdb, datastore = run_environment('mssql', config) cls.mdb = mdb models = cls.mdb.get_models() models = [x['name'] for x in models] if TEST_PREDICTOR_NAME in models: cls.mdb.delete_model(TEST_PREDICTOR_NAME) test_csv_path = get_test_csv(TEST_CSV['name'], TEST_CSV['url']) res = query( "SELECT name FROM master.dbo.sysdatabases where name = 'mindsdb_test'", fetch=True) if len(res) == 0: query("create database mindsdb_test") res = query(''' select * from sys.schemas where name = 'mindsdb_schema'; ''', fetch=True) if len(res) == 0: query(''' create schema [mindsdb_schema]; ''') # query('create database if not exists test') # show tables from test test_tables = query(f''' select 1 from sysobjects where name='{TEST_DATA_TABLE}' and xtype='U'; ''', fetch=True) if len(test_tables) == 0: print('creating test data table...') query(f''' CREATE TABLE mindsdb_schema.{TEST_DATA_TABLE} ( number_of_rooms int, number_of_bathrooms int, sqft int, location varchar(100), days_on_market int, initial_price int, neighborhood varchar(100), rental_price int ) ''') with open(test_csv_path) as f: csvf = csv.reader(f) i = 0 for row in csvf: if i > 0: number_of_rooms = int(row[0]) number_of_bathrooms = int(row[1]) sqft = int(float(row[2].replace(',', '.'))) location = str(row[3]) days_on_market = int(row[4]) initial_price = int(row[5]) neighborhood = str(row[6]) rental_price = int(float(row[7])) query(f''' INSERT INTO mindsdb_schema.{TEST_DATA_TABLE} VALUES ( {number_of_rooms}, {number_of_bathrooms}, {sqft}, '{location}', {days_on_market}, {initial_price}, '{neighborhood}', {rental_price} )''') i += 1 if i % 100 == 0: print(i) print('done') ds = datastore.get_datasource(EXTERNAL_DS_NAME) if ds is not None: datastore.delete_datasource(EXTERNAL_DS_NAME) short_csv_file_path = get_test_csv(f'{EXTERNAL_DS_NAME}.csv', TEST_CSV['url'], lines_count=300, rewrite=True) datastore.save_datasource(EXTERNAL_DS_NAME, 'file', 'test.csv', short_csv_file_path)