-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add event and interval annotation support to chart data ep #11665
feat: add event and interval annotation support to chart data ep #11665
Conversation
Codecov Report
@@ Coverage Diff @@
## master #11665 +/- ##
===========================================
- Coverage 67.59% 54.98% -12.62%
===========================================
Files 928 421 -507
Lines 45053 14812 -30241
Branches 4309 3822 -487
===========================================
- Hits 30455 8144 -22311
+ Misses 14495 6668 -7827
+ Partials 103 0 -103
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@john-bodley sure thing, I'll add some tests, will ping you shortly once it's done. |
4e5d3d8
to
d48f5d4
Compare
d48f5d4
to
c6168bb
Compare
c6168bb
to
70114ce
Compare
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() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
@john-bodley this is now ready for review if you have time, sorry for the delay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just of couple of comments
@@ -1383,3 +1386,44 @@ def test_import_chart_invalid(self): | |||
assert response == { | |||
"message": {"metadata.yaml": {"type": ["Must be equal to Slice."]}} | |||
} | |||
|
|||
@pytest.mark.usefixtures("create_annotation_layers") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should think about moving all these tests away from unittest.TestCase
if possible, there are some really cool pytest features that we are missing out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, some functions like login, get_table_by_name should be already available as direct ( not object ) methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good, just 2 nits / suggestions
@@ -1383,3 +1386,44 @@ def test_import_chart_invalid(self): | |||
assert response == { | |||
"message": {"metadata.yaml": {"type": ["Must be equal to Slice."]}} | |||
} | |||
|
|||
@pytest.mark.usefixtures("create_annotation_layers") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, some functions like login, get_table_by_name should be already available as direct ( not object ) methods
SUMMARY
Implements event, interval and line annotations on V1 chart data endpoint and ECharts Timeseries plugin. Also refactor the annotation unit test fixtures by moving them into
tests/annotation_layers/fixtures.py
so they can more easily be used in other tests.SCREENSHOT
TEST PLAN
ADDITIONAL INFORMATION