You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2020/12/03 18:42:38 UTC

[GitHub] [incubator-superset] villebro commented on a change in pull request #11665: feat: add event and interval annotation support to chart data ep

villebro commented on a change in pull request #11665:
URL: https://github.com/apache/incubator-superset/pull/11665#discussion_r535488737



##########
File path: tests/annotation_layers/api_tests.py
##########
@@ -29,77 +27,17 @@
 from superset.models.annotations import Annotation, AnnotationLayer
 
 from tests.base_tests import SupersetTestCase
-
+from tests.annotation_layers.fixtures import (
+    create_annotation_layers,
+    get_end_dttm,
+    get_start_dttm,
+)
 
 ANNOTATION_LAYERS_COUNT = 10
 ANNOTATIONS_COUNT = 5
 
 
 class TestAnnotationLayerApi(SupersetTestCase):
-    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 insert_annotation(
-        self,
-        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
-
-    @pytest.fixture()
-    def create_annotation_layers(self):
-        """
-        Creates ANNOTATION_LAYERS_COUNT-1 layers with no annotations
-        and a final one with ANNOTATION_COUNT childs
-        :return:
-        """
-        with self.create_app().app_context():
-            annotation_layers = []
-            annotations = []
-            for cx in range(ANNOTATION_LAYERS_COUNT - 1):
-                annotation_layers.append(
-                    self.insert_annotation_layer(name=f"name{cx}", descr=f"descr{cx}")
-                )
-            layer_with_annotations = self.insert_annotation_layer(
-                "layer_with_annotations"
-            )
-            annotation_layers.append(layer_with_annotations)
-            for cx in range(ANNOTATIONS_COUNT):
-                annotations.append(
-                    self.insert_annotation(
-                        layer_with_annotations,
-                        short_descr=f"short_descr{cx}",
-                        long_descr=f"long_descr{cx}",
-                    )
-                )
-            yield annotation_layers
-
-            # rollback changes
-            for annotation_layer in annotation_layers:
-                db.session.delete(annotation_layer)
-            for annotation in annotations:
-                db.session.delete(annotation)
-            db.session.commit()
-

Review comment:
       These fixtures were moved to a separate `fixtures.py` file to make them more reusable in different contexts (in this case for testing the chart data endpoint)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org