def test_interval_tolerance(self): create( Builder('digest').having(userid=self.regular_user.getId(), last_dispatch=datetime(2017, 10, 15, 12, 30, tzinfo=pytz.utc))) create( Builder('digest').having(userid=self.dossier_responsible.getId(), last_dispatch=datetime(2017, 10, 16, 9, tzinfo=pytz.utc))) # test interval expired because of tolerance Mailing(self.portal).reset() with freeze(datetime(2017, 10, 16, 11, 30, tzinfo=pytz.utc)): DigestMailer().send_digests() process_mail_queue() messages = [ message_from_string(mail) for mail in Mailing(self.portal).get_messages() ] self.assertEquals(1, len(messages)) self.assertEquals('*****@*****.**', messages[0].get('To'))
def test_notifies_only_new_responsible_per_mail(self, browser): self.task = self.add_task(browser) Mailing(self.portal).reset() self.reassign(browser, 'hugo.boss', u'Bitte Abkl\xe4rungen erledigen.') self.assertEqual(1, len(Mailing(self.portal).get_messages())) mail = email.message_from_string(Mailing(self.portal).pop()) self.assertEquals('*****@*****.**', get_header(mail, 'To'))
def test_mail_dispatcher_respects_dispatcher_roles(self, browser): """By default only the responsible should be notified by mail, when a task gets added. """ self.login(self.dossier_responsible, browser) browser.open(self.dossier, view='++add++opengever.task.task') self.create_task_via_browser(browser) self.assertEquals(1, len(Mailing(self.portal).get_messages())) mail = email.message_from_string(Mailing(self.portal).pop()) self.assertEquals('*****@*****.**', get_header(mail, 'To'))
def test_notifies_only_new_responsible_per_mail(self, browser): process_mail_queue() Mailing(self.portal).reset() self.reassign(browser, self.meeting_user, u'Bitte Abkl\xe4rungen erledigen.') process_mail_queue() self.assertEqual(1, len(Mailing(self.portal).get_messages())) mail = email.message_from_string(Mailing(self.portal).pop()) self.assertEquals('*****@*****.**', get_header(mail, 'To'))
def test_if_mail_sender_sending_mail_incl_attachement(self): """Test if the mail sent by linkchecker can be received correctly. """ # setUp Mailing(self.layer['portal']).set_up() portal = self.layer['portal'] setSite(portal) # Get configuration, collect links and send report configuration = ConfigurationMock( 'In real I would be *args comming from argparser.') site = PerSiteConfiguration(portal, configuration) accumulator = Accumulator(site) accumulator.discover_broken_links() self.paths_from = [ link_obj.link_origin for link_obj in accumulator.internal_broken_link_objs + accumulator.external_broken_link_objs ] report_handler = ReportHandler(site, accumulator) report_handler.send_report() # get the two mails sent before from queue mail2 = Mailing(portal).pop() mail1 = Mailing(portal).pop() mail_obj1 = email.message_from_string(mail1) mail_obj2 = email.message_from_string(mail2) # make sure both mails are sent and have the correct address self.assertEqual( mail_obj1.get('To'), '*****@*****.**', 'The email is expected to be sent to [email protected].') self.assertEqual( mail_obj2.get('To'), '*****@*****.**', 'The email is expected to be sent to [email protected].') # make sure both emails send the attachment self.assertEqual( mail_obj1.get_payload()[1].get_content_type(), 'application/octet-stream', 'The emails attachement is expected to be a binary file.') self.assertEqual( mail_obj2.get_payload()[1].get_content_type(), 'application/octet-stream', 'The emails attachement is expected to be a binary file.') # tearDown Mailing(self.layer['portal']).tear_down()
def test_ploneformgen_adapters_dont_run(self, browser): Mailing(self.layer['portal']).set_up() form_folder = create(Builder('FormFolder')) form_folder.manage_delObjects(['mailer']) transaction.commit() browser.login().visit(form_folder) browser.find_form_by_field('Subject').fill({ 'Your E-Mail Address': '*****@*****.**', 'Subject': 'Foo', 'Comments': 'Bar' }).submit() self.assertFalse(Mailing(self.portal).has_messages())
def test_subject_is_title(self, browser): self.login(self.dossier_responsible, browser) self.create_task_via_browser(browser) process_mail_queue() mail = email.message_from_string(Mailing(self.portal).pop()) self.assertEquals('GEVER Activity: Test Task', mail.get('Subject'))
def test_only_send_digest_when_interval_has_been_expired(self): create( Builder('digest').having(userid=self.regular_user.getId(), last_dispatch=datetime(2017, 10, 15, 12, 30, tzinfo=pytz.utc))) create( Builder('digest').having(userid=self.dossier_responsible.getId(), last_dispatch=datetime(2017, 10, 16, 9, tzinfo=pytz.utc))) with freeze(datetime(2017, 10, 16, 14, 30, tzinfo=pytz.utc)): DigestMailer().send_digests() messages = [ message_from_string(mail) for mail in Mailing(self.portal).get_messages() ] self.assertEquals(1, len(messages)) self.assertEquals('*****@*****.**', messages[0].get('To'))
def test_mail_dispatcher_respects_dispatcher_roles(self, browser): """By default only the responsible should be notified by mail, when a task gets added. """ browser.login().open(self.dossier, view='++add++opengever.task.task') browser.fill({'Title': 'Test Task', 'Task Type': 'comment'}) form = browser.find_form_by_field('Responsible') form.find_widget('Responsible').fill(self.org_unit.id() + ':hugo.boss') browser.css('#form-buttons-save').first.click() self.assertEquals(1, len(Mailing(self.portal).get_messages())) mail = email.message_from_string(Mailing(self.portal).pop()) self.assertEquals( '*****@*****.**', get_header(mail, 'To'))
def test_send_mail_with_site_email_if_activity_actor_lookup_failed(self): self.note1.sent_in_digest = True self.note2.sent_in_digest = True activity = create( Builder('activity').having( title=u'Bitte \xc4nderungen nachvollziehen', created=pytz.UTC.localize(datetime(2017, 10, 15, 18, 24)), resource=self.resource, actor_id="NOT_AN_EXISTING_ACTOR")) create( Builder('notification').having( activity=activity, is_digest=True, userid=self.dossier_responsible.getId())) DigestMailer().send_digests() process_mail_queue() messages = [ message_from_string(mail) for mail in Mailing(self.portal).get_messages() ] self.assertEquals(1, len(messages)) self.assertIn(self.portal.email_from_address, messages[0].get('From'))
def test_from_and_to_addresses(self, browser): self.login(self.dossier_responsible, browser) self.create_task_via_browser(browser) mail = email.message_from_string(Mailing(self.portal).pop()) self.assertEquals('*****@*****.**', mail.get('To')) self.assertEquals('Ziegler Robert <*****@*****.**>', get_header(mail, 'From'))
def setUp(self): super(TestSuccesssorHandling, self).setUp() # we need to setup the mock mailhost to avoid problems when using # transaction savepoints Mailing(self.portal).set_up() create( Builder('ogds_user').id('peter.meier').assign_to_org_units( [self.org_unit])) create( Builder('ogds_user').id('james.meier').assign_to_org_units( [self.org_unit])) create( Builder('ogds_user').id('hugo.boss').assign_to_org_units( [self.org_unit])) self.center = notification_center() self.dossier = create(Builder('dossier').titled(u'Dosssier A')) self.predecessor = create( Builder('task').having(responsible='peter.meier', issuer='james.meier')) self.center.add_task_responsible(self.predecessor, 'peter.meier') self.center.add_task_issuer(self.predecessor, 'james.meier') self.center.add_watcher_to_resource(self.predecessor, 'hugo.boss', WATCHER_ROLE)
def setUp(self): self.portal = self.layer['portal'] setRoles(self.portal, TEST_USER_ID, ['Manager']) login(self.portal, TEST_USER_NAME) alsoProvides(self.portal, IShopRoot) create(Builder('cart portlet')) Mailing(self.portal).set_up()
def setUp(self): super(TestSendDocument, self).setUp() self.grant('Member', 'Contributor', 'Manager') create_client('plone') set_current_client_id(self.portal, clientid=u'plone') create_ogds_user(TEST_USER_ID) Mailing(self.portal).set_up()
def setUp(self): portal = self.layer['portal'] setRoles(portal, TEST_USER_ID, ['Manager']) login(portal, TEST_USER_NAME) create(Builder('cart portlet')) Mailing(portal).set_up() transaction.commit()
def setUp(self): super(IntegrationTestCase, self).setUp() self.portal = self.layer['portal'] self.request = self.layer['request'] self.deactivate_extjs() map(self.activate_feature, self.features) if 'activity' in self.features: Mailing(self.portal).set_up() insert_notification_defaults(self.portal)
def test_task_title_is_linked_to_resolve_notification_view(self, browser): self.login(self.dossier_responsible, browser) self.create_task_via_browser(browser) process_mail_queue() raw_mail = Mailing(self.portal).pop() link = '<p><a href=3D"http://nohost/plone/@@resolve_notification?notification=\n_id=3D1">Test Task</a></p>' self.assertIn(link, raw_mail.strip())
def setUp(self): super(TestSendDocument, self).setUp() create(Builder('fixture') .with_user(firstname="Test", lastname="User") .with_org_unit() .with_admin_unit(public_url='http://nohost/plone')) Mailing(self.portal).set_up()
def test_sends_mail_to_all_notified_users(self): DigestMailer().send_digests() messages = [ message_from_string(mail) for mail in Mailing(self.portal).get_messages() ] self.assertEquals(2, len(messages)) self.assertEquals(['*****@*****.**', '*****@*****.**'], [message.get('To') for message in messages])
def checkout_and_get_mail(self, *items): mailing = Mailing(self.portal) for item in items: checkout.visit_checkout_with_one_item_in_cart(item) checkout.goto(checkout.ORDER_REVIEW).finish() self.assertEquals( 1, len(mailing.get_messages()), 'Notifying shop owner is disabled by default, therefore' ' only one mail (to the customer) should be sent.') return email.message_from_string(mailing.pop())
def test_sends_only_not_yet_sended_notifications(self): self.note2.sent_in_digest = True DigestMailer().send_digests() process_mail_queue() messages = [ message_from_string(mail) for mail in Mailing(self.portal).get_messages() ] self.assertEquals(1, len(messages)) self.assertEquals('*****@*****.**', messages[0].get('To'))
def test_notification_summary_is_split_into_paragraphs(self, browser): self.login(self.dossier_responsible, browser) self.create_task_via_browser(browser) process_mail_queue() # Discard the first mail Mailing(self.portal).pop() # XXX - did not find a neater way to get the task quickly browser.open(Task.query.all()[-1], view='addcommentresponse') browser.fill({'Response': 'Multi\n\nline\ncomment'}) browser.css('#form-buttons-save').first.click() process_mail_queue() mails = Mailing(self.portal).get_messages() self.assertEqual(len(mails), 1) raw_mail = mails[0] self.assertIn('<p>Multi</p>', raw_mail) self.assertIn('<p></p>', raw_mail) self.assertIn('<p>line</p>', raw_mail) self.assertIn('<p>comment</p>', raw_mail)
def test_from_and_to_addresses(self, browser): browser.login().open(self.dossier, view='++add++opengever.task.task') browser.fill({'Title': 'Test Task', 'Task Type': 'comment'}) form = browser.find_form_by_field('Responsible') form.find_widget('Responsible').fill(self.org_unit.id() + ':hugo.boss') browser.css('#form-buttons-save').first.click() mail = email.message_from_string(Mailing(self.portal).pop()) self.assertEquals('*****@*****.**', mail.get('To')) self.assertEquals( 'Test User <*****@*****.**>', get_header(mail, 'From'))
def test_subject_is_title(self, browser): browser.login().open(self.dossier, view='++add++opengever.task.task') browser.fill({'Title': 'Test Task', 'Task Type': 'comment'}) form = browser.find_form_by_field('Responsible') form.find_widget('Responsible').fill(self.org_unit.id() + ':hugo.boss') browser.css('#form-buttons-save').first.click() mail = email.message_from_string(Mailing(self.portal).pop()) self.assertEquals('GEVER Task: Test Task', mail.get('Subject'))
def test_notification_add_task_summary_is_split_into_lines(self, browser): self.login(self.dossier_responsible, browser) self.create_task_via_browser(browser, description='Multi\nline\ncomment') process_mail_queue() mails = Mailing(self.portal).get_messages() self.assertEqual(len(mails), 1) raw_mail = mails[0] mail = raw_mail.decode("quopri") self.assertIn('<td>Multi<br />', mail) self.assertIn('line<br />', mail) self.assertIn('comment</td>', mail)
def test_mail_dispatcher_respects_dispatcher_roles_even_if_its_a_group(self, browser): """By default only the responsible should be notified by mail, when a task gets added. """ inbox_group = self.org_unit.inbox_group inbox_group.users.append(self.hugo) inbox_group.users.append(self.franz) browser.login().open(self.dossier, view='++add++opengever.task.task') browser.fill({'Title': 'Test Task', 'Task Type': 'comment'}) form = browser.find_form_by_field('Responsible') form.find_widget('Responsible').fill( self.org_unit.id() + ':franz.michel') form.find_widget('Issuer').fill('inbox:client1') browser.css('#form-buttons-save').first.click() self.assertEquals(1, len(Mailing(self.portal).get_messages())) mail = email.message_from_string(Mailing(self.portal).pop()) self.assertEquals( '*****@*****.**', get_header(mail, 'To'))
def test_notification_mailer_handle_empty_activity_description( self, browser): self.login(self.dossier_responsible, browser) self.create_task_via_browser(browser) process_mail_queue() # Discard the first mail Mailing(self.portal).pop() # reassign task task = self.dossier.objectValues()[-1] data = {'form.widgets.transition': 'task-transition-reassign'} browser.open(task, data, view='assign-task') form = browser.find_form_by_field('Responsible') form.find_widget('Responsible').fill(self.secretariat_user) browser.click_on('Assign') process_mail_queue() mails = Mailing(self.portal).get_messages() mails.sort(key=lambda data: email.message_from_string(data).get('To')) self.assertEqual(len(mails), 1) raw_mail = mails[0] self.assertIn('Reassigned from', raw_mail)
def test_mail_contains_date_activity_summaries(self, browser): with freeze(datetime(2017, 10, 16, 0, 0, tzinfo=pytz.utc)): DigestMailer().send_digests() messages = [ message_from_string(mail) for mail in Mailing(self.portal).get_messages() ] browser.open_html(str(messages[0].get_payload()[0])) self.assertEquals('Oct 16, 201= 7', browser.css('table p').text[0]) self.assertEquals(['Daily Digest for B=C3=A4rfuss K=C3=A4thi'], browser.css('h1').text) self.assertEquals(['Bitte =C3=84nderungen nachvollzie= hen'], browser.css('h2 a').text)
def test_task_title_is_linked_to_resolve_notification_view(self, browser): browser.login().open(self.dossier, view='++add++opengever.task.task') browser.fill({'Title': 'Test Task', 'Task Type': 'comment'}) form = browser.find_form_by_field('Responsible') form.find_widget('Responsible').fill(self.org_unit.id() + ':hugo.boss') browser.css('#form-buttons-save').first.click() mail = email.message_from_string(Mailing(self.portal).pop()) html_part = mail.get_payload()[0].as_string() link = '<p><a href=3D"http://example.com/@@resolve_notification' \ '?notification_id=\n=3D1">Test Task</a></p>' self.assertIn(link, html_part)
def test_notification_mailer_handle_empty_activity_description( self, browser): self.login(self.dossier_responsible, browser) self.create_task_via_browser(browser) # reassign task task = self.dossier.objectValues()[-1] data = {'form.widgets.transition': 'task-transition-reassign'} browser.open(task, data, view='assign-task') responsible = 'fa:{}'.format(self.secretariat_user.getId()) form = browser.find_form_by_field('Responsible') form.find_widget('Responsible').fill(responsible) browser.click_on('Assign') mails = Mailing(self.portal).get_messages() self.assertEqual(len(mails), 2) raw_mail = mails[-1] self.assertIn('Reassigned from', raw_mail)