def add_service(service: ServiceType) -> tuple: if ServiceTypeAdapter.exists_in_db(service.id): return 'The service already exists in the catalog.', 409 PlanAdapter.create_table() PlanServiceTypeAdapter.create_table() ServiceTypeAdapter.save(service) if ServiceTypeAdapter.exists_in_db(service.id): return 'Service added successfully', 200 else: return 'Could not save the Service in the DB', 500
def test_service_deletion(self): _, result = SQLStore.delete_service(self.test_model.id) self.assertEqual(self.result, 200, msg='Assert Service Deleted') exists = ServiceTypeAdapter.exists_in_db(self.test_model.id) self.assertFalse(exists, msg='Assert service does NOT Exist.') service_sql = ServiceTypeAdapter.find_by_id_name(self.test_model.id) self.assertIsNone(service_sql)
def get_service(service_id: str = None) -> List[ServiceType]: if service_id: if ServiceTypeAdapter.exists_in_db(service_id): model_sql = ServiceTypeAdapter.find_by_id_name(service_id) model = ServiceTypeAdapter.model_sql_to_model(model_sql) return [model] else: return [] else: return ServiceTypeAdapter.get_all()
def add_manifest(manifest) -> tuple: if ManifestAdapter.exists_in_db(manifest.id): return 'The Manifest already exists in the catalog.', 409 ''' Attempt to Create Table ''' PlanAdapter.create_table() ServiceTypeAdapter.create_table() if ServiceTypeAdapter.exists_in_db( manifest.service_id) and PlanAdapter.exists_in_db( manifest.plan_id): ManifestAdapter.save(manifest) else: return 'Could not save the Manifest in the DB, Plan and Service don\'t exist', 500 if ManifestAdapter.exists_in_db(manifest.id): return 'Manifest added successfully', 200 else: return 'Could not save the Manifest in the DB', 500
def delete_service(service_id: str = None) -> tuple: if service_id: if ServiceTypeAdapter.exists_in_db(service_id): ServiceTypeAdapter.delete(service_id) return 'Service Deleted', 200 else: return 'Service ID not found', 500 else: PlanServiceTypeAdapter.delete_all() LastOperationAdapter.delete_all() ServiceInstanceAdapter.delete_all() ManifestAdapter.delete_all() ServiceTypeAdapter.delete_all() PlanAdapter.delete_all() return 'Deleted all Services', 200
def test_service_created(self): self.assertEqual(self.result, 200, msg='Assert Successful Add') exists = ServiceTypeAdapter.exists_in_db(self.test_model.id) self.assertTrue(exists, msg='Assert service service exists.') service_sql = ServiceTypeAdapter.find_by_id_name(self.test_model.id) self.assertIsInstance(service_sql, ServiceTypeSQL)
def test_adapter_save_to_update(self): self.test_model.name = 'new-name' model_sql = ServiceTypeAdapter.save(self.test_model) exists = ServiceTypeAdapter.exists_in_db(model_sql.id_name) self.assertTrue(exists)