mirror of
https://github.com/apache/superset.git
synced 2026-04-18 07:35:09 +00:00
chore: Test cases for annotations and annotation layers incorrect creation through API (#17246)
* Add/Refactor tests * Add return type * Update api tests
This commit is contained in:
@@ -31,6 +31,8 @@ from tests.integration_tests.annotation_layers.fixtures import (
|
||||
create_annotation_layers,
|
||||
get_end_dttm,
|
||||
get_start_dttm,
|
||||
)
|
||||
from tests.unit_tests.annotation_layers.fixtures import (
|
||||
START_STR,
|
||||
END_STR,
|
||||
)
|
||||
@@ -197,7 +199,6 @@ class TestAnnotationLayerApi(SupersetTestCase):
|
||||
assert data["count"] == 1
|
||||
assert data["result"][0] == expected_result
|
||||
|
||||
@pytest.mark.usefixtures("create_annotation_layers")
|
||||
def test_create_annotation_layer(self):
|
||||
"""
|
||||
Annotation Api: Test create annotation layer
|
||||
@@ -220,6 +221,18 @@ class TestAnnotationLayerApi(SupersetTestCase):
|
||||
db.session.delete(created_model)
|
||||
db.session.commit()
|
||||
|
||||
def test_create_incorrect_annotation_layer(self):
|
||||
"""
|
||||
Annotation Api: Test create incorrect annotation layer
|
||||
"""
|
||||
self.login(username="admin")
|
||||
annotation_layer_data = {}
|
||||
uri = "api/v1/annotation_layer/"
|
||||
rv = self.client.post(uri, json=annotation_layer_data)
|
||||
assert rv.status_code == 400
|
||||
data = json.loads(rv.data.decode("utf-8"))
|
||||
assert data == {"message": {"name": ["Missing data for required field."]}}
|
||||
|
||||
@pytest.mark.usefixtures("create_annotation_layers")
|
||||
def test_create_annotation_layer_uniqueness(self):
|
||||
"""
|
||||
@@ -245,14 +258,15 @@ class TestAnnotationLayerApi(SupersetTestCase):
|
||||
)
|
||||
|
||||
self.login(username="admin")
|
||||
annotation_layer_data = {"name": "changed_name", "descr": "changed_description"}
|
||||
annotation_layer_data = {"name": "changed_name"}
|
||||
uri = f"api/v1/annotation_layer/{annotation_layer.id}"
|
||||
rv = self.client.put(uri, json=annotation_layer_data)
|
||||
assert rv.status_code == 200
|
||||
updated_model = db.session.query(AnnotationLayer).get(annotation_layer.id)
|
||||
assert updated_model is not None
|
||||
assert updated_model.name == annotation_layer_data["name"]
|
||||
assert updated_model.descr == annotation_layer_data["descr"]
|
||||
# make sure the descr hasn't updated
|
||||
assert updated_model.descr == annotation_layer.descr
|
||||
|
||||
@pytest.mark.usefixtures("create_annotation_layers")
|
||||
def test_update_annotation_layer_uniqueness(self):
|
||||
@@ -521,6 +535,29 @@ class TestAnnotationLayerApi(SupersetTestCase):
|
||||
db.session.delete(created_model)
|
||||
db.session.commit()
|
||||
|
||||
@pytest.mark.usefixtures("create_annotation_layers")
|
||||
def test_create_incorrect_annotation(self):
|
||||
"""
|
||||
Annotation Api: Test create incorrect annotation
|
||||
"""
|
||||
layer = self.get_layer_with_annotation()
|
||||
|
||||
self.login(username="admin")
|
||||
annotation_data = {
|
||||
"long_descr": "description",
|
||||
}
|
||||
uri = f"api/v1/annotation_layer/{layer.id}/annotation/"
|
||||
rv = self.client.post(uri, json=annotation_data)
|
||||
data = json.loads(rv.data.decode("utf-8"))
|
||||
assert rv.status_code == 400
|
||||
assert data == {
|
||||
"message": {
|
||||
"end_dttm": ["Missing data for required field."],
|
||||
"short_descr": ["Missing data for required field."],
|
||||
"start_dttm": ["Missing data for required field."],
|
||||
}
|
||||
}
|
||||
|
||||
@pytest.mark.usefixtures("create_annotation_layers")
|
||||
def test_create_annotation_uniqueness(self):
|
||||
"""
|
||||
@@ -558,17 +595,42 @@ class TestAnnotationLayerApi(SupersetTestCase):
|
||||
)
|
||||
|
||||
self.login(username="admin")
|
||||
annotation_layer_data = {
|
||||
annotation_data = {
|
||||
"short_descr": "changed_name",
|
||||
"long_descr": "changed_description",
|
||||
}
|
||||
uri = f"api/v1/annotation_layer/{layer.id}/annotation/{annotation.id}"
|
||||
rv = self.client.put(uri, json=annotation_layer_data)
|
||||
rv = self.client.put(uri, json=annotation_data)
|
||||
assert rv.status_code == 200
|
||||
updated_model: Annotation = db.session.query(Annotation).get(annotation.id)
|
||||
assert updated_model is not None
|
||||
assert updated_model.short_descr == annotation_layer_data["short_descr"]
|
||||
assert updated_model.long_descr == annotation_layer_data["long_descr"]
|
||||
assert updated_model.short_descr == annotation_data["short_descr"]
|
||||
# make sure long_descr hasn't updated
|
||||
assert updated_model.long_descr == annotation.long_descr
|
||||
|
||||
@pytest.mark.usefixtures("create_annotation_layers")
|
||||
def test_update_annotation_null_datetime(self):
|
||||
"""
|
||||
Annotation Api: Test update annotation null datetime
|
||||
"""
|
||||
layer = self.get_layer_with_annotation()
|
||||
annotation = (
|
||||
db.session.query(Annotation)
|
||||
.filter(Annotation.short_descr == "short_descr2")
|
||||
.one_or_none()
|
||||
)
|
||||
|
||||
self.login(username="admin")
|
||||
annotation_data = {"start_dttm": None, "end_dttm": None}
|
||||
uri = f"api/v1/annotation_layer/{layer.id}/annotation/{annotation.id}"
|
||||
rv = self.client.put(uri, json=annotation_data)
|
||||
assert rv.status_code == 400
|
||||
data = json.loads(rv.data.decode("utf-8"))
|
||||
assert data == {
|
||||
"message": {
|
||||
"end_dttm": ["Field may not be null."],
|
||||
"start_dttm": ["Field may not be null."],
|
||||
}
|
||||
}
|
||||
|
||||
@pytest.mark.usefixtures("create_annotation_layers")
|
||||
def test_update_annotation_uniqueness(self):
|
||||
|
||||
Reference in New Issue
Block a user