def test_sample_model_with_plans(self): self.assertIsInstance(self.test_model, Manifest) model_sql = ManifestAdapter.find_by_id_name(self.test_model.id) self.assertIsInstance(model_sql, ManifestSQL) ''' query associated service ''' service = model_sql.service self.assertIsInstance(service, ServiceTypeSQL) ''' verify relations ''' plans = service.plans plan = model_sql.plan self.assertTrue(plan in plans) ''' manifest also deleted ''' PlanAdapter.delete(plan.id_name) self.assertFalse(ManifestAdapter.exists_in_db(model_sql.id_name)) ''' service updated (has to be re-query-ed) ''' ''' this is not correct! >> service = model_sql.service ''' service = ServiceTypeAdapter.find_by_id_name(service.id_name) plans = service.plans ''' verify plans reduced ''' self.assertEqual(len(plans), 1) ''' verify service has no manifest now ''' self.assertTrue(service.manifests.is_empty())
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 test_sample_model_with_plans(self): self.assertIsInstance(self.test_model, ServiceType) model_sql = ServiceTypeAdapter.find_by_id_name(self.test_model.id) self.assertIsInstance(model_sql, ServiceTypeSQL) self.assertFalse(model_sql.plans.is_empty()) plans = PlanAdapter.plans_from_service_sql(model_sql) self.assertGreater(len(plans), 1) model = ServiceTypeAdapter.model_sql_to_model(model_sql) self.assertGreater(len(model.plans), 1)
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)