def test_instance_deletion(self): _, result = SQLStore.delete_service_instance(self.id_name) self.assertEqual(self.result, 200, msg='Assert Instance Deleted') exists = Adapter.exists_in_db(self.id_name) self.assertFalse(exists, msg='Assert Instance does NOT Exist.') model_sql = Adapter.find_by_id_name(self.id_name) self.assertIsNone(model_sql)
def test_sample_model(self): self.assertIsInstance(self.test_model, ServiceInstance) model_sql = Adapter.find_by_id_name(self.id_name) self.assertIsInstance(model_sql, ServiceInstanceSQL) ''' query associated service ''' service = model_sql.service self.assertIsInstance(service, ServiceTypeSQL) ''' verify relations ''' instances = service.instances self.assertGreater(len(instances), 0)
def get_last_operation(instance_id: str = None) -> List[ServiceInstance]: if instance_id: if ServiceInstanceAdapter.exists_in_db(instance_id): model_sql = ServiceInstanceAdapter.find_by_id_name(instance_id) model = ServiceInstanceAdapter.model_sql_to_model(model_sql) return [model.state] else: return [] else: LOG.warning('No instance ID was provided') return []
def get_service_instance(instance_id: str = None) -> List[ServiceInstance]: if instance_id: if ServiceInstanceAdapter.exists_in_db(instance_id): model_sql = ServiceInstanceAdapter.find_by_id_name(instance_id) model = ServiceInstanceAdapter.model_sql_to_model(model_sql) return [model] else: return [] else: models = ServiceInstanceAdapter.get_all() return models
def delete_last_operation(self, instance_id: str = None) -> tuple: if ServiceInstanceAdapter.exists_in_db(instance_id): instance = ServiceInstanceAdapter.find_by_id_name(instance_id) ''' Attempt to Create Table ''' PlanAdapter.create_table() ServiceTypeAdapter.create_table() ServiceTypeAdapter.create_table() ServiceInstanceAdapter.create_table() LastOperationAdapter.create_table() instance.state = None ServiceInstanceAdapter.save(instance) id_name = ServiceInstanceAdapter.get_id(instance) if ServiceInstanceAdapter.exists_in_db(id_name): return 'Instance added successfully', 200 else: return 'Could not save the Instance in the DB', 500 else: raise Exception('Service Instance not found')
def test_instance_created(self): self.assertEqual(self.result, 200, msg='Assert Successful Add') exists = Adapter.exists_in_db(self.id_name) self.assertTrue(exists, msg='Assert Instance exists.') model_sql = Adapter.find_by_id_name(self.id_name) self.assertIsInstance(model_sql, ServiceInstanceSQL)