You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2021/02/23 06:22:00 UTC

[superset] branch master updated: fix schedules tests (#12870)

This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new a5a31e0  fix schedules tests (#12870)
a5a31e0 is described below

commit a5a31e0e6027494983dbed8b2ffa43fbc0c4b71b
Author: Karol Kostrzewa <ka...@gmail.com>
AuthorDate: Tue Feb 23 07:21:19 2021 +0100

    fix schedules tests (#12870)
    
    Co-authored-by: Ville Brofeldt <vi...@gmail.com>
---
 tests/schedules_test.py | 90 ++++++++++++++++++++++++++-----------------------
 1 file changed, 47 insertions(+), 43 deletions(-)

diff --git a/tests/schedules_test.py b/tests/schedules_test.py
index 45693f4..bc7f4a0 100644
--- a/tests/schedules_test.py
+++ b/tests/schedules_test.py
@@ -23,9 +23,7 @@ import pytest
 from selenium.common.exceptions import WebDriverException
 from slack import errors, WebClient
 
-from tests.fixtures.world_bank_dashboard import (
-    load_world_bank_dashboard_with_slices_module_scope,
-)
+from tests.fixtures.world_bank_dashboard import load_world_bank_dashboard_with_slices
 from tests.test_app import app
 from superset import db
 from superset.models.dashboard import Dashboard
@@ -44,9 +42,6 @@ from superset.tasks.schedules import (
 from superset.models.slice import Slice
 from tests.base_tests import SupersetTestCase
 from tests.utils import read_fixture
-from tests.fixtures.birth_names_dashboard import (
-    load_birth_names_dashboard_with_slices_module_scope,
-)
 
 
 class TestSchedules(SupersetTestCase):
@@ -55,31 +50,31 @@ class TestSchedules(SupersetTestCase):
     BCC = "bcc@superset.com"
     CSV = read_fixture("trends.csv")
 
-    @classmethod
-    def setUpClass(cls):
+    @pytest.fixture()
+    def add_schedule_slice_and_dashboard(self):
         with app.app_context():
-            cls.common_data = dict(
+            self.common_data = dict(
                 active=True,
                 crontab="* * * * *",
-                recipients=cls.RECIPIENTS,
+                recipients=self.RECIPIENTS,
                 deliver_as_group=True,
                 delivery_type=EmailDeliveryType.inline,
             )
             # Pick up a sample slice and dashboard
-            slce = db.session.query(Slice).filter_by(slice_name="Participants").one()
+            slice = db.session.query(Slice).filter_by(slice_name="Region Filter").one()
             dashboard = (
                 db.session.query(Dashboard)
                 .filter_by(dashboard_title="World Bank's Data")
                 .one()
             )
 
-            dashboard_schedule = DashboardEmailSchedule(**cls.common_data)
+            dashboard_schedule = DashboardEmailSchedule(**self.common_data)
             dashboard_schedule.dashboard_id = dashboard.id
             dashboard_schedule.user_id = 1
             db.session.add(dashboard_schedule)
 
-            slice_schedule = SliceEmailSchedule(**cls.common_data)
-            slice_schedule.slice_id = slce.id
+            slice_schedule = SliceEmailSchedule(**self.common_data)
+            slice_schedule.slice_id = slice.id
             slice_schedule.user_id = 1
             slice_schedule.email_format = SliceEmailReportFormat.data
             slice_schedule.slack_channel = "#test_channel"
@@ -87,21 +82,20 @@ class TestSchedules(SupersetTestCase):
             db.session.add(slice_schedule)
             db.session.commit()
 
-            cls.slice_schedule = slice_schedule.id
-            cls.dashboard_schedule = dashboard_schedule.id
+            self.slice_schedule = slice_schedule.id
+            self.dashboard_schedule = dashboard_schedule.id
+
+        yield
 
-    @classmethod
-    def tearDownClass(cls):
         with app.app_context():
             db.session.query(SliceEmailSchedule).filter_by(
-                id=cls.slice_schedule
+                id=self.slice_schedule
             ).delete()
             db.session.query(DashboardEmailSchedule).filter_by(
-                id=cls.dashboard_schedule
+                id=self.dashboard_schedule
             ).delete()
             db.session.commit()
 
-    @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices_module_scope")
     def test_crontab_scheduler(self):
         crontab = "* * * * *"
 
@@ -129,7 +123,6 @@ class TestSchedules(SupersetTestCase):
         self.assertEqual(schedules[-1], stop_at - timedelta(seconds=12 * 60))
         self.assertEqual(len(schedules), 5)
 
-    @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices_module_scope")
     def test_wider_schedules(self):
         crontab = "*/15 2,10 * * *"
 
@@ -145,10 +138,6 @@ class TestSchedules(SupersetTestCase):
             else:
                 self.assertEqual(len(schedules), 0)
 
-    @pytest.mark.usefixtures(
-        "load_world_bank_dashboard_with_slices_module_scope",
-        "load_birth_names_dashboard_with_slices_module_scope",
-    )
     def test_complex_schedule(self):
         # Run the job on every Friday of March and May
         # On these days, run the job at
@@ -176,7 +165,6 @@ class TestSchedules(SupersetTestCase):
         self.assertEqual(schedules[59], datetime.strptime("2018-03-30 17:40:00", fmt))
         self.assertEqual(schedules[60], datetime.strptime("2018-05-04 17:10:00", fmt))
 
-    @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices_module_scope")
     @patch("superset.tasks.schedules.firefox.webdriver.WebDriver")
     def test_create_driver(self, mock_driver_class):
         mock_driver = Mock()
@@ -186,7 +174,9 @@ class TestSchedules(SupersetTestCase):
         create_webdriver(db.session)
         mock_driver.add_cookie.assert_called_once()
 
-    @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices_module_scope")
+    @pytest.mark.usefixtures(
+        "load_world_bank_dashboard_with_slices", "add_schedule_slice_and_dashboard"
+    )
     @patch("superset.tasks.schedules.firefox.webdriver.WebDriver")
     @patch("superset.tasks.schedules.send_email_smtp")
     @patch("superset.tasks.schedules.time")
@@ -220,7 +210,9 @@ class TestSchedules(SupersetTestCase):
         driver.screenshot.assert_not_called()
         send_email_smtp.assert_called_once()
 
-    @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices_module_scope")
+    @pytest.mark.usefixtures(
+        "load_world_bank_dashboard_with_slices", "add_schedule_slice_and_dashboard"
+    )
     @patch("superset.tasks.schedules.firefox.webdriver.WebDriver")
     @patch("superset.tasks.schedules.send_email_smtp")
     @patch("superset.tasks.schedules.time")
@@ -264,7 +256,9 @@ class TestSchedules(SupersetTestCase):
             element.screenshot_as_png,
         )
 
-    @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices_module_scope")
+    @pytest.mark.usefixtures(
+        "load_world_bank_dashboard_with_slices", "add_schedule_slice_and_dashboard"
+    )
     @patch("superset.tasks.schedules.firefox.webdriver.WebDriver")
     @patch("superset.tasks.schedules.send_email_smtp")
     @patch("superset.tasks.schedules.time")
@@ -308,7 +302,9 @@ class TestSchedules(SupersetTestCase):
             driver.screenshot.return_value,
         )
 
-    @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices_module_scope")
+    @pytest.mark.usefixtures(
+        "load_world_bank_dashboard_with_slices", "add_schedule_slice_and_dashboard"
+    )
     @patch("superset.tasks.schedules.firefox.webdriver.WebDriver")
     @patch("superset.tasks.schedules.send_email_smtp")
     @patch("superset.tasks.schedules.time")
@@ -350,7 +346,9 @@ class TestSchedules(SupersetTestCase):
         self.assertEqual(send_email_smtp.call_count, 2)
         self.assertEqual(send_email_smtp.call_args[1]["bcc"], self.BCC)
 
-    @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices_module_scope")
+    @pytest.mark.usefixtures(
+        "load_world_bank_dashboard_with_slices", "add_schedule_slice_and_dashboard"
+    )
     @patch("superset.tasks.slack_util.WebClient.files_upload")
     @patch("superset.tasks.schedules.firefox.webdriver.WebDriver")
     @patch("superset.tasks.schedules.send_email_smtp")
@@ -399,12 +397,14 @@ class TestSchedules(SupersetTestCase):
             {
                 "channels": "#test_channel",
                 "file": element.screenshot_as_png,
-                "initial_comment": f"\n        *Participants*\n\n        <http://0.0.0.0:8080/superset/slice/{schedule.slice_id}/|Explore in Superset>\n        ",
-                "title": "[Report]  Participants",
+                "initial_comment": f"\n        *Region Filter*\n\n        <http://0.0.0.0:8080/superset/slice/{schedule.slice_id}/|Explore in Superset>\n        ",
+                "title": "[Report]  Region Filter",
             },
         )
 
-    @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices_module_scope")
+    @pytest.mark.usefixtures(
+        "load_world_bank_dashboard_with_slices", "add_schedule_slice_and_dashboard"
+    )
     @patch("superset.tasks.slack_util.WebClient.files_upload")
     @patch("superset.tasks.schedules.firefox.webdriver.WebDriver")
     @patch("superset.tasks.schedules.send_email_smtp")
@@ -454,12 +454,14 @@ class TestSchedules(SupersetTestCase):
             {
                 "channels": "#test_channel",
                 "file": element.screenshot_as_png,
-                "initial_comment": f"\n        *Participants*\n\n        <http://0.0.0.0:8080/superset/slice/{schedule.slice_id}/|Explore in Superset>\n        ",
-                "title": "[Report]  Participants",
+                "initial_comment": f"\n        *Region Filter*\n\n        <http://0.0.0.0:8080/superset/slice/{schedule.slice_id}/|Explore in Superset>\n        ",
+                "title": "[Report]  Region Filter",
             },
         )
 
-    @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices_module_scope")
+    @pytest.mark.usefixtures(
+        "load_world_bank_dashboard_with_slices", "add_schedule_slice_and_dashboard"
+    )
     @patch("superset.tasks.slack_util.WebClient.files_upload")
     @patch("superset.tasks.schedules.urllib.request.OpenerDirector.open")
     @patch("superset.tasks.schedules.urllib.request.urlopen")
@@ -501,12 +503,14 @@ class TestSchedules(SupersetTestCase):
             {
                 "channels": "#test_channel",
                 "file": self.CSV,
-                "initial_comment": f"\n        *Participants*\n\n        <http://0.0.0.0:8080/superset/slice/{schedule.slice_id}/|Explore in Superset>\n        ",
-                "title": "[Report]  Participants",
+                "initial_comment": f"\n        *Region Filter*\n\n        <http://0.0.0.0:8080/superset/slice/{schedule.slice_id}/|Explore in Superset>\n        ",
+                "title": "[Report]  Region Filter",
             },
         )
 
-    @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices_module_scope")
+    @pytest.mark.usefixtures(
+        "load_world_bank_dashboard_with_slices", "add_schedule_slice_and_dashboard"
+    )
     @patch("superset.tasks.slack_util.WebClient.files_upload")
     @patch("superset.tasks.schedules.urllib.request.urlopen")
     @patch("superset.tasks.schedules.urllib.request.OpenerDirector.open")
@@ -546,8 +550,8 @@ class TestSchedules(SupersetTestCase):
             {
                 "channels": "#test_channel",
                 "file": self.CSV,
-                "initial_comment": f"\n        *Participants*\n\n        <http://0.0.0.0:8080/superset/slice/{schedule.slice_id}/|Explore in Superset>\n        ",
-                "title": "[Report]  Participants",
+                "initial_comment": f"\n        *Region Filter*\n\n        <http://0.0.0.0:8080/superset/slice/{schedule.slice_id}/|Explore in Superset>\n        ",
+                "title": "[Report]  Region Filter",
             },
         )