def test_deliver_dashboard_as_attachment(self, mtime, send_email_smtp, driver_class): element = Mock() driver = Mock() mtime.sleep.return_value = None driver_class.return_value = driver # Ensure that we are able to login with the driver driver.find_elements_by_id.side_effect = [True, False] driver.find_element_by_id.return_value = element driver.find_element_by_class_name.return_value = element element.screenshot_as_png = read_fixture("sample.png") schedule = (db.session.query(DashboardEmailSchedule).filter_by( id=self.dashboard_schedule).one()) schedule.delivery_type = EmailDeliveryType.attachment deliver_dashboard( schedule.dashboard_id, schedule.recipients, schedule.slack_channel, schedule.delivery_type, schedule.deliver_as_group, ) mtime.sleep.assert_called_once() driver.screenshot.assert_not_called() send_email_smtp.assert_called_once() self.assertIsNone(send_email_smtp.call_args[1]["images"]) self.assertEqual( send_email_smtp.call_args[1]["data"]["screenshot"], element.screenshot_as_png, )
def test_deliver_email_options(self, mtime, send_email_smtp, driver_class): element = Mock() driver = Mock() mtime.sleep.return_value = None driver_class.return_value = driver # Ensure that we are able to login with the driver driver.find_elements_by_id.side_effect = [True, False] driver.find_element_by_class_name.return_value = element element.screenshot_as_png = read_fixture("sample.png") schedule = (db.session.query(DashboardEmailSchedule).filter_by( id=self.dashboard_schedule).one()) # Send individual mails to the group schedule.deliver_as_group = False # Set a bcc email address app.config["EMAIL_REPORT_BCC_ADDRESS"] = self.BCC deliver_dashboard( schedule.dashboard_id, schedule.recipients, schedule.slack_channel, schedule.delivery_type, schedule.deliver_as_group, ) mtime.sleep.assert_called_once() driver.screenshot.assert_not_called() self.assertEqual(send_email_smtp.call_count, 2) self.assertEqual(send_email_smtp.call_args[1]["bcc"], self.BCC)
def test_deliver_email_options(self, mtime, send_email_smtp, driver_class): element = Mock() driver = Mock() mtime.sleep.return_value = None driver_class.return_value = driver # Ensure that we are able to login with the driver driver.find_elements_by_id.side_effect = [True, False] driver.find_element_by_class_name.return_value = element element.screenshot_as_png = read_fixture('sample.png') schedule = db.session.query(DashboardEmailSchedule).filter_by( id=self.dashboard_schedule).all()[0] # Send individual mails to the group schedule.deliver_as_group = False # Set a bcc email address app.config['EMAIL_REPORT_BCC_ADDRESS'] = self.BCC deliver_dashboard(schedule) mtime.sleep.assert_called_once() driver.screenshot.assert_not_called() self.assertEquals(send_email_smtp.call_count, 2) self.assertEquals(send_email_smtp.call_args[1]['bcc'], self.BCC)
def test_deliver_dashboard_inline(self, mtime, send_email_smtp, driver_class): element = Mock() driver = Mock() mtime.sleep.return_value = None driver_class.return_value = driver # Ensure that we are able to login with the driver driver.find_elements_by_id.side_effect = [True, False] driver.find_element_by_class_name.return_value = element element.screenshot_as_png = read_fixture("sample.png") schedule = (db.session.query(DashboardEmailSchedule).filter_by( id=self.dashboard_schedule).all()[0]) deliver_dashboard( schedule.dashboard_id, schedule.recipients, schedule.slack_channel, schedule.delivery_type, schedule.deliver_as_group, ) mtime.sleep.assert_called_once() driver.screenshot.assert_not_called() send_email_smtp.assert_called_once()
def test_dashboard_chrome_like(self, mtime, send_email_smtp, driver_class): # Test functionality for chrome driver which does not support # element snapshots element = Mock() driver = Mock() mtime.sleep.return_value = None type(element).screenshot_as_png = PropertyMock(side_effect=WebDriverException) driver_class.return_value = driver # Ensure that we are able to login with the driver driver.find_elements_by_id.side_effect = [True, False] driver.find_element_by_id.return_value = element driver.find_element_by_class_name.return_value = element driver.screenshot.return_value = read_fixture('sample.png') schedule = db.session.query(DashboardEmailSchedule).filter_by( id=self.dashboard_schedule).all()[0] deliver_dashboard(schedule) mtime.sleep.assert_called_once() driver.screenshot.assert_called_once() send_email_smtp.assert_called_once() self.assertEquals(send_email_smtp.call_args[0][0], self.RECIPIENTS) self.assertEquals( list(send_email_smtp.call_args[1]['images'].values())[0], driver.screenshot.return_value, )
def test_deliver_dashboard_as_attachment(self, mtime, send_email_smtp, driver_class): element = Mock() driver = Mock() mtime.sleep.return_value = None driver_class.return_value = driver # Ensure that we are able to login with the driver driver.find_elements_by_id.side_effect = [True, False] driver.find_element_by_id.return_value = element driver.find_element_by_class_name.return_value = element element.screenshot_as_png = read_fixture('sample.png') schedule = db.session.query(DashboardEmailSchedule).filter_by( id=self.dashboard_schedule).all()[0] schedule.delivery_type = EmailDeliveryType.attachment deliver_dashboard(schedule) mtime.sleep.assert_called_once() driver.screenshot.assert_not_called() send_email_smtp.assert_called_once() self.assertIsNone(send_email_smtp.call_args[1]['images']) self.assertEquals( send_email_smtp.call_args[1]['data']['screenshot.png'], element.screenshot_as_png, )
def test_dashboard_chrome_like(self, mtime, send_email_smtp, driver_class): # Test functionality for chrome driver which does not support # element snapshots element = Mock() driver = Mock() mtime.sleep.return_value = None type(element).screenshot_as_png = PropertyMock( side_effect=WebDriverException) driver_class.return_value = driver # Ensure that we are able to login with the driver driver.find_elements_by_id.side_effect = [True, False] driver.find_element_by_id.return_value = element driver.find_element_by_class_name.return_value = element driver.screenshot.return_value = read_fixture("sample.png") schedule = (db.session.query(DashboardEmailSchedule).filter_by( id=self.dashboard_schedule).all()[0]) deliver_dashboard(schedule) mtime.sleep.assert_called_once() driver.screenshot.assert_called_once() send_email_smtp.assert_called_once() self.assertEquals(send_email_smtp.call_args[0][0], self.RECIPIENTS) self.assertEquals( list(send_email_smtp.call_args[1]["images"].values())[0], driver.screenshot.return_value, )
def test_deliver_dashboard_inline(self, mtime, send_email_smtp, driver_class): element = Mock() driver = Mock() mtime.sleep.return_value = None driver_class.return_value = driver # Ensure that we are able to login with the driver driver.find_elements_by_id.side_effect = [True, False] driver.find_element_by_class_name.return_value = element element.screenshot_as_png = read_fixture('sample.png') schedule = db.session.query(DashboardEmailSchedule).filter_by( id=self.dashboard_schedule).all()[0] deliver_dashboard(schedule) mtime.sleep.assert_called_once() driver.screenshot.assert_not_called() send_email_smtp.assert_called_once()