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( self, name: str = "", descr: str = "" ) -> AnnotationLayer: annotation_layer = AnnotationLayer(name=name, descr=descr,) db.session.add(annotation_layer) db.session.commit() return annotation_layer
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