def retrieve_plan(name): manager = get_manager() try: plan = manager.storage.find_plan(name) except storage.PlanNotFoundError: return "plan not found", 404 return json.dumps(plan.to_dict())
def test_find_plan(self): plan = self.storage.find_plan("small") expected = {"name": "small", "description": "some cool plan", "config": {"serviceofferingid": "abcdef123456"}} self.assertEqual(expected, plan.to_dict()) with self.assertRaises(storage.PlanNotFoundError): self.storage.find_plan("something that doesn't exist")
def store_plan(self, plan): plan.validate() d = plan.to_dict() d["_id"] = d["name"] del d["name"] try: self.db[self.plans_collection].insert(d) except pymongo.errors.DuplicateKeyError: raise DuplicateError(plan.name)