def test_manifest_deletion(self):
     _, result = SQLStore.delete_manifest(self.test_model.id)
     self.assertEqual(self.result, 200, msg='Assert Manifest Deleted')
     exists = ManifestAdapter.exists_in_db(self.test_model.id)
     self.assertFalse(exists, msg='Assert manifest does NOT Exist.')
     manifest_sql = ManifestAdapter.find_by_id_name(self.test_model.id)
     self.assertIsNone(manifest_sql)
Beispiel #2
0
    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())
Beispiel #3
0
    def get_manifest(manifest_id: str = None,
                     plan_id: str = None) -> List[Manifest]:
        if manifest_id and plan_id:
            raise Exception('Query Manifests only by manifest_id OR plan_id')

        if plan_id:
            manifests = ManifestSQL.where(
                'plan_id_name', '=', '{}'.format(plan_id)).get().serialize()
            if len(manifests) > 1:
                raise Exception(
                    'Too many manifests {mani_len} returned for the Plan: {plan_id}'
                    .format(mani_len=len(manifests), plan_id=plan_id))
            return [Manifest.from_dict(manifests[0])]

        if manifest_id:
            if ManifestAdapter.exists_in_db(manifest_id):
                model_sql = ManifestAdapter.find_by_id_name(manifest_id)
                model = ManifestAdapter.model_sql_to_model(model_sql)
                model.manifest_content = model.manifest_content.replace(
                    '</br>', '\n')
                return [model]
            else:
                return []
        else:
            manifests = ManifestAdapter.get_all()
            for manifest in manifests:
                manifest.manifest_content = manifest.manifest_content.replace(
                    '</br>', '\n')
            return manifests
 def test_manifest_created(self):
     self.assertEqual(self.result, 200, msg='Assert Successful Add')
     exists = ManifestAdapter.exists_in_db(self.test_model.id)
     self.assertTrue(exists, msg='Assert manifest exists.')
     manifest_sql = ManifestAdapter.find_by_id_name(self.test_model.id)
     self.assertIsInstance(manifest_sql, ManifestSQL)