def test_get_by_id_model_same_dir(self): test_dir = "test-dir" datadriver = BlitzDBDALDriver("file", test_dir) dal = LocalDAL(datadriver) model1 = dal.model.create(Model(self.model_input_dict)) del datadriver del dal datadriver = BlitzDBDALDriver("file", test_dir) dal = LocalDAL(datadriver) model2 = dal.model.create(Model(self.model_input_dict)) del datadriver del dal datadriver = BlitzDBDALDriver("file", test_dir) dal = LocalDAL(datadriver) model3 = dal.model.create(Model(self.model_input_dict)) model1 = dal.model.get_by_id(model1.id) model2 = dal.model.get_by_id(model2.id) model3 = dal.model.get_by_id(model3.id) assert model1 assert model2 assert model3 shutil.rmtree(test_dir)
def test_multiple_blitzdb_objects(self): database_2 = BlitzDBDALDriver("file", self.temp_dir) test_obj_dict = {"foo": "bar"} test_obj = database_2.set(self.collection, test_obj_dict) # new_test_obj = database_2.get(self.collection, test_obj.get('id')) results_2 = database_2.query(self.collection, {}) # Try a new data base database_3 = BlitzDBDALDriver("file", self.temp_dir) results_3 = database_3.query(self.collection, {}) assert len(results_2) == len(results_3)
def test_multiple_blitzdb_objects_intermediate_creation(self): # Test to check failure for intermediate creation database_2 = BlitzDBDALDriver("file", self.temp_dir) database_3 = BlitzDBDALDriver("file", self.temp_dir) test_obj_dict = {"foo": "bar"} # Set value after instantiation of database_3 test_obj = database_2.set(self.collection, test_obj_dict) # Try to retrieve value from database_3 test_obj_3 = database_3.get(self.collection, test_obj['id']) # Test to ensure the intermediate object is found assert test_obj_3['id'] == test_obj['id']
def setup_method(self): # provide mountable tmp directory for docker tempfile.tempdir = "/tmp" if not platform.system( ) == "Windows" else None test_datmo_dir = os.environ.get('TEST_DATMO_DIR', tempfile.gettempdir()) self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir) self.datadriver = BlitzDBDALDriver("file", self.temp_dir) self.dal = LocalDAL(self.datadriver) model_name = "model_1" model = self.dal.model.create(Model({"name": model_name})) session_name = "session_1" session = self.dal.session.create( Session({ "name": session_name, "model_id": model.id })) self.snapshot_input_dict = { "model_id": model.id, "session_id": session.id, "message": "my message", "code_id": "code_id", "environment_id": "environment_id", "file_collection_id": "file_collection_id", "config": { "test": 0.45 }, "stats": { "test": 0.98 } }
def setup_method(self): # provide mountable tmp directory for docker tempfile.tempdir = "/tmp" if not platform.system( ) == "Windows" else None test_datmo_dir = os.environ.get('TEST_DATMO_DIR', tempfile.gettempdir()) self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir) self.datadriver = BlitzDBDALDriver("file", self.temp_dir) self.dal = LocalDAL(self.datadriver) model_name = "model_1" model = self.dal.model.create(Model({"name": model_name})) session_name = "session_1" session = self.dal.session.create( Session({ "name": session_name, "model_id": model.id })) self.task_input_dict = { "model_id": model.id, "session_id": session.id, "command": "task_1", "start_time": datetime.utcnow(), "end_time": datetime.utcnow(), "duration": 0.004, }
def setup_class(self): # provide mountable tmp directory for docker tempfile.tempdir = "/tmp" if not platform.system( ) == "Windows" else None test_datmo_dir = os.environ.get('TEST_DATMO_DIR', tempfile.gettempdir()) self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir) self.datadriver = BlitzDBDALDriver("file", self.temp_dir)
def is_initialized(self): if os.path.isdir(self.driver_options['connection_string']): self._is_initialized = True # set the driver so it is available if not self.driver: if self.driver_type == "blitzdb": self.driver = BlitzDBDALDriver(**self.driver_options) return self._is_initialized self._is_initialized = False return self._is_initialized
def setup_class(self): # provide mountable tmp directory for docker tempfile.tempdir = "/tmp" if not platform.system( ) == "Windows" else None test_datmo_dir = os.environ.get('TEST_DATMO_DIR', tempfile.gettempdir()) self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir) # TODO: Automatically create Document class from collection # For now, use one of pre-defined collections: self.collection = 'model' self.database = BlitzDBDALDriver("file", self.temp_dir)
def test_get_by_id_model_new_driver_instance(self): model = self.dal.model.create(Model(self.model_input_dict)) # create new dal with new driver instance (success) new_driver_instance = BlitzDBDALDriver("file", self.temp_dir) new_dal_instance = LocalDAL(new_driver_instance) new_model_1 = new_dal_instance.model.get_by_id(model.id) assert new_model_1.id == model.id # create new dal instance with same driver (success) new_dal_instance = LocalDAL(self.datadriver) new_model_2 = new_dal_instance.model.get_by_id(model.id) assert new_model_2.id == model.id
def test_get_by_id_code_new_driver_instance(self): code = self.dal.code.create(Code(self.code_input_dict)) # create new dal with new driver instance (success) new_driver_instance = BlitzDBDALDriver("file", self.temp_dir) new_dal_instance = LocalDAL(new_driver_instance) new_code_1 = new_dal_instance.code.get_by_id(code.id) assert new_code_1.id == code.id # create new dal instance with same driver (success) new_dal_instance = LocalDAL(self.datadriver) new_code_2 = new_dal_instance.code.get_by_id(code.id) assert new_code_2.id == code.id
def test_get_by_id_user_new_driver_instance(self): user = self.dal.user.create(User(self.user_input_dict)) # create new dal with new driver instance (fails) new_driver_instance = BlitzDBDALDriver("file", self.temp_dir) new_dal_instance = LocalDAL(new_driver_instance) new_user_1 = new_dal_instance.user.get_by_id(user.id) assert new_user_1.id == user.id # create new dal instance with same driver (success) new_dal_instance = LocalDAL(self.datadriver) new_user_2 = new_dal_instance.user.get_by_id(user.id) assert new_user_2.id == user.id
def test_get_by_id_snapshot_new_driver_instance(self): snapshot = self.dal.snapshot.create(Snapshot(self.snapshot_input_dict)) # create new dal with new driver instance (fails) new_driver_instance = BlitzDBDALDriver("file", self.temp_dir) new_dal_instance = LocalDAL(new_driver_instance) new_snapshot_1 = new_dal_instance.snapshot.get_by_id(snapshot.id) assert new_snapshot_1.id == snapshot.id # create new dal instance with same driver (success) new_dal_instance = LocalDAL(self.datadriver) new_snapshot_2 = new_dal_instance.snapshot.get_by_id(snapshot.id) assert new_snapshot_2.id == snapshot.id
def test_get_by_id_environment_new_driver_instance(self): environment = self.dal.environment.create(Environment(self.environment_input_dict)) # create new dal with new driver instance (success) new_driver_instance = BlitzDBDALDriver("file", self.temp_dir) new_dal_instance = LocalDAL(new_driver_instance) new_environment_1 = new_dal_instance.environment.get_by_id(environment.id) assert new_environment_1.id == environment.id # create new dal instance with same driver (success) new_dal_instance = LocalDAL(self.datadriver) new_environment_2 = new_dal_instance.environment.get_by_id(environment.id) assert new_environment_2.id == environment.id
def test_get_by_id_task_new_driver_instance(self): task = self.dal.task.create(Task(self.task_input_dict)) # create new dal with new driver instance (success) new_driver_instance = BlitzDBDALDriver("file", self.temp_dir) new_dal_instance = LocalDAL(new_driver_instance) new_task_1 = new_dal_instance.task.get_by_id(task.id) assert new_task_1.id == task.id # create new dal instance with same driver (success) new_dal_instance = LocalDAL(self.datadriver) new_task_2 = new_dal_instance.task.get_by_id(task.id) assert new_task_2.id == task.id
def setup_method(self): # provide mountable tmp directory for docker tempfile.tempdir = "/tmp" if not platform.system( ) == "Windows" else None test_datmo_dir = os.environ.get('TEST_DATMO_DIR', tempfile.gettempdir()) self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir) self.datadriver = BlitzDBDALDriver("file", self.temp_dir) self.dal = LocalDAL(self.datadriver) model_name = "model_1" self.model_input_dict = {"name": model_name}
def setup_class(self): # provide mountable tmp directory for docker tempfile.tempdir = "/tmp" if not platform.system( ) == "Windows" else None test_datmo_dir = os.environ.get('TEST_DATMO_DIR', tempfile.gettempdir()) self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir) self.datadriver = BlitzDBDALDriver("file", self.temp_dir) self.dal = LocalDAL(self.datadriver) self.user_input_dict = { "name": "user_1", "email": "*****@*****.**", }
def test_get_by_id_file_collection_new_driver_instance(self): file_collection = self.dal.file_collection.create( FileCollection(self.file_collection_input_dict)) # create new dal with new driver instance (success) new_driver_instance = BlitzDBDALDriver("file", self.temp_dir) new_dal_instance = LocalDAL(new_driver_instance) new_file_collection_1 = new_dal_instance.file_collection.get_by_id( file_collection.id) assert new_file_collection_1.id == file_collection.id # create new dal instance with same driver (success) new_dal_instance = LocalDAL(self.datadriver) new_file_collection_2 = new_dal_instance.file_collection.get_by_id( file_collection.id) assert new_file_collection_2.id == file_collection.id
def setup_class(self): # provide mountable tmp directory for docker tempfile.tempdir = "/tmp" if not platform.system() == "Windows" else None test_datmo_dir = os.environ.get('TEST_DATMO_DIR', tempfile.gettempdir()) self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir) self.datadriver = BlitzDBDALDriver("file", self.temp_dir) self.dal = LocalDAL(self.datadriver) model_name = "model_1" model = self.dal.model.create(Model({"name": model_name})) self.code_input_dict = { "model_id": model.id, "driver_type": "git", "commit_id": "commit_id" }
def setup_method(self): # provide mountable tmp directory for docker tempfile.tempdir = "/tmp" if not platform.system( ) == "Windows" else None test_datmo_dir = os.environ.get('TEST_DATMO_DIR', tempfile.gettempdir()) self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir) self.datadriver = BlitzDBDALDriver("file", self.temp_dir) self.dal = LocalDAL(self.datadriver) model_name = "model_1" model = self.dal.model.create(Model({"name": model_name})) self.file_collection_input_dict = { "model_id": model.id, "driver_type": "local", "filehash": "myhash", "path": "test_path", }
def setup_class(self): # provide mountable tmp directory for docker tempfile.tempdir = "/tmp" if not platform.system() == "Windows" else None test_datmo_dir = os.environ.get('TEST_DATMO_DIR', tempfile.gettempdir()) self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir) self.datadriver = BlitzDBDALDriver("file", self.temp_dir) self.dal = LocalDAL(self.datadriver) model_name = "model_1" model = self.dal.model.create(Model({"name": model_name})) self.environment_input_dict = { "model_id": model.id, "driver_type": "docker", "file_collection_id": "test_file_id", "definition_filename": "Dockerfile", "hardware_info": {"system": "macosx"}, "unique_hash": "slkdjfa23dk", "language": "python3" }
def test_remote_db_init(self): mongo_connection = "mongodb://localhost:27017" # Make mongo db connection required for testing? database = BlitzDBDALDriver("service", mongo_connection) assert database != None
def test_file_db_init(self): database = BlitzDBDALDriver("file", self.temp_dir) assert database != None
def init(self): if not self.driver: if self.driver_type == "blitzdb": self.driver = BlitzDBDALDriver(**self.driver_options)