def insert_status(self, data) -> int: try: new_status = CmdbStatus(**data) ack = self.dbm.insert(CmdbStatus.COLLECTION, new_status.to_database()) except (CMDBError, Exception) as err: LOGGER.error(err) raise ObjectManagerInsertError(err) return ack
def update_status(self, data): try: updated_status = CmdbStatus(**data) ack = self._update(CmdbStatus.COLLECTION, updated_status.get_public_id(), updated_status.to_database()) except (CMDBError, Exception) as err: LOGGER.error(err) raise ObjectManagerUpdateError(err) return ack.acknowledged
def test_short_truncat(self): short_init_params = {'public_id': 1, 'name': 'test'} short_instance = CmdbStatus(**short_init_params) assert short_instance.get_short() == 'TEST' short_init_params['name'] = 'test2test' short_instance2 = CmdbStatus(**short_init_params) assert short_instance2.get_short() == 'TEST2' short_init_params['short'] = 't' short_instance3 = CmdbStatus(**short_init_params) assert short_instance3.get_short() == 'T'
def get_status(self, public_id) -> CmdbStatus: try: return CmdbStatus(**self.dbm.find_one( collection=CmdbStatus.COLLECTION, public_id=public_id)) except (CMDBError, Exception) as err: LOGGER.error(err) raise ObjectManagerGetError(err)
def test_init_function(self, status_instance_class): right_init_params = { 'public_id': 1, 'name': 'test', 'label': 'Test', 'short': 'T', 'events': [] } init_instance = CmdbStatus(**right_init_params) assert isinstance(init_instance, status_instance_class) wrong_init_params = { 'public_id': 1, 'label': 'Test', 'short': 'T', 'events': [] } with pytest.raises(RequiredInitKeyNotFoundError): CmdbStatus(**wrong_init_params)
def get_statuses(self) -> list: status_list = list() try: collection_resp = self.dbm.find_all( collection=CmdbStatus.COLLECTION) except (CMDBError, Exception) as err: LOGGER.error(err) raise ObjectManagerGetError(err) for collection in collection_resp: try: status_list.append(CmdbStatus(**collection)) except (CMDBError, Exception) as err: LOGGER.error(err) continue return status_list
def test_getters(self): right_init_params = { 'public_id': 1, 'name': 'test', 'label': 'Test', 'short': 'T', 'events': [] } getter_instance = CmdbStatus(**right_init_params) assert getter_instance.get_public_id() == 1 assert getter_instance.get_name() == 'test' assert getter_instance.get_label() == 'Test' assert getter_instance.get_short() == 'T' assert len(getter_instance.get_events()) == 0