async def post(self): """ Add a schema and its classes. Request body: { "url": <schema_url>, "namespace": <schema_name> } This is the logical document structure in HTTP API, different from that of the underylying registry layer. Protect core schema namespace from overwrite. """ namespace = self.args.namespace url = self.args.url if self.args.source: # current arbitrary design decision raise HTTPError(400, reason="provide url only.") if namespace in CORE_SCHEMA_NS: raise HTTPError(409, reason="conflict with core schemas.") if namespace in RESERVED_SCHEMA_NS: raise HTTPError(400, reason=f"'{namespace}' is reserved.") if schemas.exists(namespace): raise HTTPError(409, reason="namespace already registered.") if schemas.exists(url): raise HTTPError(409, reason="url already registered.") try: # load schema json from url response = await AsyncHTTPClient().fetch(url, request_timeout=10) doc = json.loads(response.body) except Exception as exc: # TODO be specific raise HTTPError(400, reason=str(exc)) count = schemas.add(namespace, url, self.current_user, doc) self.finish({ 'success': True, 'result': 'created', 'total': count, 'url': self.request.full_url() + '/' + namespace, }) self.report(notify.schema, "add", namespace=namespace, num_classes=count)
def setup(): if not schemas.exists("niaid"): schemas.add("niaid", NIAID_SCHEMA_URL, '*****@*****.**') if datasets.exists("83dc3401f86819de"): # wellderly datasets.delete("83dc3401f86819de") if datasets.exists("e87b433020414bad"): # systems_bio_cdiff_0002 datasets.delete("e87b433020414bad") if datasets.exists("ecf3767159a74988"): # systems_bio_cdiff_0001 datasets.delete("ecf3767159a74988")
def test_30_post(self): if schemas.exists('bts'): schemas.delete('bts') doc = {'url': BTS_URL, 'namespace': 'bts'} self.query(q='BiologicalEntity', hits=False) self.request('registry/bts', expect=404) self.request('registry', method='POST', json=doc, headers=self.auth_user) self.request('registry/bts', expect=200) self.refresh() self.query(q='BiologicalEntity')
def head(self, namespace): """ Check if a schema exists. """ if not schemas.exists(namespace): self.set_status(404)
def setup(): if not schemas.exists('bts'): schemas.add(namespace='bts', url=BTS_URL, user='******')