def test_annotation_json_endpoint(self): # Set up an annotation layer and annotation layer = AnnotationLayer(name="foo", descr="bar") db.session.add(layer) db.session.commit() annotation = Annotation( layer_id=layer.id, short_descr="my_annotation", start_dttm=datetime.datetime(2020, 5, 20, 18, 21, 51), end_dttm=datetime.datetime(2020, 5, 20, 18, 31, 51), ) db.session.add(annotation) db.session.commit() self.login() resp_annotations = json.loads( self.get_resp("annotationlayermodelview/api/read")) # the UI needs id and name to function self.assertIn("id", resp_annotations["result"][0]) self.assertIn("name", resp_annotations["result"][0]) layer = self.get_resp( f"/superset/annotation_json/{layer.id}?form_data=" + quote(json.dumps({"time_range": "100 years ago : now"}))) self.assertIn("my_annotation", layer)
def _insert_annotation( layer: AnnotationLayer, short_descr: str, long_descr: str, json_metadata: Optional[str] = "", start_dttm: Optional[datetime] = None, end_dttm: Optional[datetime] = None, ) -> Annotation: annotation = Annotation( layer=layer, short_descr=short_descr, long_descr=long_descr, json_metadata=json_metadata, start_dttm=start_dttm, end_dttm=end_dttm, ) db.session.add(annotation) db.session.commit() return annotation
def test_annotation_json_endpoint(self): # Set up an annotation layer and annotation layer = AnnotationLayer(name="foo", descr="bar") db.session.add(layer) db.session.commit() annotation = Annotation( layer_id=layer.id, short_descr="my_annotation", start_dttm=datetime.datetime(2020, 5, 20, 18, 21, 51), end_dttm=datetime.datetime(2020, 5, 20, 18, 31, 51), ) db.session.add(annotation) db.session.commit() resp = self.get_resp( f"/superset/annotation_json/{layer.id}?form_data=" + quote(json.dumps({"time_range": "100 years ago : now"}))) assert "my_annotation" in resp