bkyryliuk commented on a change in pull request #10605:
URL:
https://github.com/apache/incubator-superset/pull/10605#discussion_r481275317
##########
File path: tests/alerts_tests.py
##########
@@ -40,115 +54,259 @@
@pytest.yield_fixture(scope="module")
def setup_database():
with app.app_context():
- slice_id = db.session.query(Slice).all()[0].id
- database_id = utils.get_example_database().id
-
- alerts = [
- Alert(
- id=1,
- label="alert_1",
- active=True,
- crontab="*/1 * * * *",
- sql="SELECT 0",
- alert_type="email",
- slice_id=slice_id,
- database_id=database_id,
- ),
- Alert(
- id=2,
- label="alert_2",
- active=True,
- crontab="*/1 * * * *",
- sql="SELECT 55",
- alert_type="email",
- slice_id=slice_id,
- recipients="[email protected]",
- slack_channel="#test_channel",
- database_id=database_id,
- ),
- Alert(
- id=3,
- label="alert_3",
- active=False,
- crontab="*/1 * * * *",
- sql="UPDATE 55",
- alert_type="email",
- slice_id=slice_id,
- database_id=database_id,
- ),
- Alert(id=4, active=False, label="alert_4", database_id=-1),
- Alert(id=5, active=False, label="alert_5",
database_id=database_id),
- ]
-
- db.session.bulk_save_objects(alerts)
+ example_database = utils.get_example_database()
+ example_database.get_sqla_engine().execute(
+ "CREATE TABLE test_table AS SELECT 1 as first, 2 as second"
+ )
+ example_database.get_sqla_engine().execute(
+ "INSERT INTO test_table (first, second) VALUES (3, 4)"
+ )
+
+ no_observer_alert = Alert(crontab="* * * * *", label="No Observer")
+ db.session.add(no_observer_alert)
db.session.commit()
yield db.session
+ db.session.query(SQLObservation).delete()
+ db.session.query(SQLObserver).delete()
+ db.session.query(Validator).delete()
db.session.query(AlertLog).delete()
db.session.query(Alert).delete()
-@patch("superset.tasks.schedules.deliver_alert")
-@patch("superset.tasks.schedules.logging.Logger.error")
-def test_run_alert_query(mock_error, mock_deliver_alert, setup_database):
+def create_alert(dbsession, sql: str, validator_args: Optional[Dict[str, str]]
= None):
Review comment:
validator args are usually done through the keyword args:
```
def create_alert(dbsession, sql: str, validator_type=None,
validator_config=None):
```
----------------------------------------------------------------
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]