def test_query_codes_range_query(self): _ = self.dal.code.create(Code(self.code_input_dict)) _ = self.dal.code.create(Code(self.code_input_dict)) _ = self.dal.code.create(Code(self.code_input_dict)) codes = self.dal.code.query( {}, sort_key="created_at", sort_order="descending") result = self.dal.code.query({ "created_at": { "$lt": codes[1].created_at.strftime('%Y-%m-%dT%H:%M:%S.%fZ') } }) assert len(codes) == 3 assert len(result) == 1
def test_init_with_id(self): self.input_dict['id'] = "test" code_entity = Code(self.input_dict) for k, v in self.input_dict.items(): assert getattr(code_entity, k) == v assert code_entity.created_at assert code_entity.updated_at
def test_init_no_id(self): code_entity = Code(self.input_dict) for k, v in self.input_dict.items(): assert getattr(code_entity, k) == v assert code_entity.id == None assert code_entity.created_at assert code_entity.updated_at
def test_delete_code(self): code = self.dal.code.create(Code(self.code_input_dict)) self.dal.code.delete(code.id) deleted = False try: self.dal.code.get_by_id(code.id) except EntityNotFound: deleted = True assert deleted
def test_create_code_by_dictionary(self): code = self.dal.code.create(Code(self.code_input_dict)) assert code.id assert code.model_id == self.code_input_dict['model_id'] assert code.driver_type == self.code_input_dict['driver_type'] assert code.commit_id == self.code_input_dict['commit_id'] assert code.created_at assert code.updated_at code_2 = self.dal.code.create(Code(self.code_input_dict)) assert code_2.id != code.id test_code_input_dict = self.code_input_dict.copy() test_code_input_dict['id'] = "id_1" code_3 = self.dal.code.create(Code(test_code_input_dict)) assert code_3.id == test_code_input_dict['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_update_code(self): code = self.dal.code.create(Code(self.code_input_dict)) # Update required and optional parameters updated_code_input_dict = self.code_input_dict.copy() updated_code_input_dict['id'] = code.id updated_code_input_dict['driver_type'] = "new_driver" updated_code_input_dict['created_at'] = datetime.utcnow() updated_code = self.dal.code.update(updated_code_input_dict) assert code.id == updated_code.id assert code.updated_at < updated_code.updated_at assert updated_code.driver_type == updated_code_input_dict['driver_type'] assert updated_code.created_at == updated_code_input_dict['created_at']
def create(self, commit_id=None): """Create a Code object Parameters ---------- commit_id : str, optional if commit_id is already present, will not make a new reference and commit Returns ------- Code an object representing the code reference created Raises ------ RequiredArgumentMissing if any arguments above are not provided. """ # Validate Inputs create_dict = { "model_id": self.model.id, } ## Required args for Code entity required_args = ["driver_type", "commit_id"] for required_arg in required_args: # Handle Id if provided or not if required_arg == "driver_type": create_dict[required_arg] = self.code_driver.type elif required_arg == "commit_id": if commit_id: create_dict[required_arg] = commit_id else: create_dict[required_arg] = \ self.code_driver.create_ref() # If code object with commit id exists, return it results = self.dal.code.query({ "commit_id": create_dict[required_arg], "model_id": self.model.id }) if results: return results[0] else: raise NotImplementedError() # Create code and return return self.dal.code.create(Code(create_dict))
def test_get_by_shotened_id_code(self): code = self.dal.code.create(Code(self.code_input_dict)) result = self.dal.code.get_by_shortened_id(code.id[:10]) assert code.id == result.id
def test_get_by_id_code(self): code = self.dal.code.create(Code(self.code_input_dict)) result = self.dal.code.get_by_id(code.id) assert code.id == result.id
def test_query_codes(self): code = self.dal.code.create(Code(self.code_input_dict)) assert len(self.dal.code.query({"id": code.id})) == 1
def test_to_dictionary(self): code_entity = Code(self.input_dict) output_dict = code_entity.to_dictionary() for k, v in output_dict.items(): assert v == getattr(code_entity, k)
def test_eq(self): code_entity_1 = Code(self.input_dict) code_entity_2 = Code(self.input_dict) assert code_entity_1 == code_entity_2