def test_import_mails(self): diverted_mail = EmailTool.divert_mail() self.portal.imported.maintainer_email = 'someone@somehost' do_import_object(self, 'Naaya URL', csv_data, 'imported') # only the bulk csv import mail should have been sent self.assertEqual(len(diverted_mail), 1) expected_subject = u'CSV Import - imported' expected_body = (u'This is automatically generated message' ' to inform you that the following 2 items' ' have been uploaded in imported' ' (http://nohost/portal/imported):\n' ' - My URL 1\n - Eau de Web\n\n' 'Uploaded by Anonymous User on') expected_recipients = ['someone@somehost', # folder_maintainer '*****@*****.**'] # administrator_email expected_sender = '*****@*****.**' mail = diverted_mail[0] self.assertTrue(expected_body in mail[0]) self.assertEqual(expected_recipients, mail[1]) self.assertEqual(expected_sender, mail[2]) self.assertEqual(expected_subject, mail[3]) EmailTool.divert_mail(False)
def test_import_mails(self): diverted_mail = EmailTool.divert_mail() #Enable instant notifications notification_tool = self.portal.getNotificationTool() notification_tool.config['enable_instant'] = True self.portal.getNotificationTool().add_account_subscription( 'contributor', '', 'instant', 'en') self.portal.imported.maintainer_email = 'someone@somehost' do_import_object(self, 'Naaya URL', csv_data, 'imported') self.assertEqual(len(diverted_mail), 3) expected_subject = u'CSV Import - imported' expected_body = (u'This is automatically generated message' ' to inform you that the following 2 items' ' have been uploaded in imported' ' (http://nohost/portal/imported):\n' ' - My URL 1\n - Eau de Web\n\n' 'Uploaded by Anonymous User on') expected_recipients = ['*****@*****.**',# administrator_email 'someone@somehost', # folder_maintainer '*****@*****.**'] # subscriber expected_sender = '*****@*****.**' mail = diverted_mail[0] self.assertTrue(expected_body in mail[0]) self.assertEqual(expected_recipients[0], diverted_mail[0][1][0]) self.assertEqual(expected_recipients[1], diverted_mail[1][1][0]) self.assertEqual(expected_recipients[2], diverted_mail[2][1][0]) self.assertEqual(expected_sender, mail[2]) self.assertEqual(expected_subject, mail[3]) EmailTool.divert_mail(False)
def test_import_mails(self): diverted_mail = EmailTool.divert_mail() self.test_folder.maintainer_email = 'someone@somehost' self.test_folder.zip_import.do_import(data=folder_with_files) # only the bulk csv import mail should have been sent self.assertEqual(len(diverted_mail), 1) expected_subject = u'Zip Import - zip_imported' expected_body = ('This is automatically generated message to inform ' 'you that a Zip archive was uploaded in zip_imported ' '(http://nohost/portal/zip_imported):\n\n' ' - one_folder/\n' ' - one_folder/one_file\n' ' - one_folder/three_file\n' ' - one_folder/two_file') expected_recipients = ['someone@somehost', # folder_maintainer '*****@*****.**'] # administrator_email expected_sender = '*****@*****.**' mail = diverted_mail[0] self.assertTrue(expected_body in mail[0]) self.assertEqual(expected_recipients, mail[1]) self.assertEqual(expected_sender, mail[2]) self.assertEqual(expected_subject, mail[3]) EmailTool.divert_mail(False)
def test_import_mails(self): diverted_mail = EmailTool.divert_mail() #Enable instant notifications notification_tool = self.portal.getNotificationTool() notification_tool.config['enable_instant'] = True self.portal.getNotificationTool().add_account_subscription( 'contributor', '', 'instant', 'en') self.portal.imported.maintainer_email = 'someone@somehost' do_import_object(self, 'Naaya URL', csv_data, 'imported') self.assertEqual(len(diverted_mail), 3) expected_subject = u'CSV Import - imported' expected_body = (u'This is automatically generated message' ' to inform you that the following 2 items' ' have been uploaded in imported' ' (http://nohost/portal/imported):\n' ' - My URL 1\n - Eau de Web\n\n' 'Uploaded by Anonymous User on') expected_recipients = [ '*****@*****.**', # administrator_email 'someone@somehost', # folder_maintainer '*****@*****.**' ] # subscriber expected_sender = '*****@*****.**' mail = diverted_mail[0] self.assertTrue(expected_body in mail[0]) self.assertEqual(expected_recipients[0], diverted_mail[0][1][0]) self.assertEqual(expected_recipients[1], diverted_mail[1][1][0]) self.assertEqual(expected_recipients[2], diverted_mail[2][1][0]) self.assertEqual(expected_sender, mail[3]) self.assertEqual(expected_subject, mail[4]) EmailTool.divert_mail(False)
def test_anonymous_account_subscription(self): """ Add anonymous notification. This sends an email with a confirmation key. Confirm with confirm method and verify if subscription is in the container. """ diverted_mail = EmailTool.divert_mail() notif_tool = self.portal.getNotificationTool() notif_tool.add_anonymous_subscription(email='*****@*****.**', lang='en', location='', notif_type='instant', content_types=[]) assert diverted_mail[0][1] == ['*****@*****.**'] assert diverted_mail[0][3] == '*****@*****.**' assert diverted_mail[0][0].find('confirm?key=') != -1 confirm_key = re.search('confirm\?key=(\w+)', diverted_mail[0][0]).group(1) notif_tool.confirm(key=confirm_key) for obj, n, sub in walk_subscriptions(self.portal): if sub.email == '*****@*****.**': break else: raise "No subscription found" EmailTool.divert_mail(False)
def test_import_mails(self): diverted_mail = EmailTool.divert_mail() notification_tool = self.portal.getNotificationTool() notification_tool.config['enable_instant'] = True self.portal.getNotificationTool().add_account_subscription( 'contributor', '', 'instant', 'en') self.test_folder.maintainer_email = 'someone@somehost' self.test_folder.zip_import.do_import(data=folder_with_files) self.assertEqual(len(diverted_mail), 3) expected_subject = u'Zip Import - zip_imported' expected_body = ('This is automatically generated message to inform ' 'you that a Zip archive was uploaded in zip_imported ' '(http://nohost/portal/zip_imported):\n\n' ' - one_folder/\n' ' - one_folder/one_file\n' ' - one_folder/three_file\n' ' - one_folder/two_file') expected_recipients = ['*****@*****.**',# administrator_email 'someone@somehost', # folder_maintainer '*****@*****.**'] # subscriber expected_sender = '*****@*****.**' mail = diverted_mail[0] self.assertTrue(expected_body in mail[0]) self.assertEqual(expected_recipients[0], diverted_mail[0][1][0]) self.assertEqual(expected_recipients[1], diverted_mail[1][1][0]) self.assertEqual(expected_recipients[2], diverted_mail[2][1][0]) self.assertEqual(expected_sender, mail[3]) self.assertEqual(expected_subject, mail[4]) EmailTool.divert_mail(False)
def _update(self, portal): context = portal.restrictedTraverse('who-who/destinet-users') cat = portal['portal_catalog'] acl_users = portal['acl_users'] users = acl_users.getUsers() auth_tool = portal.getAuthenticationTool() #manager = self.request.AUTHENTICATED_USER.getUserName() # first, cleanup wrongly created users wrong = [o for o in context.objectValues() if o._owner[1] == 'tibiadmin'] self.log.info("Deleting %s wrong contacts" % len(wrong)) for obj in wrong: cat.uncatalog_object(ofs_path(obj)) context.manage_delObjects([o.id for o in wrong]) self.log.info("Migration: start migration of contacts for old users") EmailTool.divert_mail() counter = 0 for user in users: fullname = auth_tool.getUserFullNameByID(user.name) contacts = cat.searchResults(path=ofs_path(context), contributor=user.name) if not contacts: counter += 1 id = uniqueId( slugify(user.name or 'contact', removelist=[]), lambda x: context._getOb(x, None) is not None) ob = _create_NyContact_object(context, id, user.name) ob.approveThis(1, user.name) # 1, manager ob.submitThis() ob.set_localpropvalue('title', 'en', fullname) ob.set_localpropvalue('description', 'en', "") #ob.release_date = DateTime() new_user = user.__of__(acl_users) ob.changeOwnership(user=new_user) ob.giveEditRights() context.recatalogNyObject(ob) #crashes with unicodedecodeerror: #notify(NyContentObjectAddEvent(ob, user.name, {})) #log post date auth_tool.changeLastPost(user.name) self.log.info("Migration: %s - added contact for user: %s", counter, id) EmailTool.divert_mail(False) self.log.info("Migration: end migration") return True
def test_import_mails(self): diverted_mail = EmailTool.divert_mail() notification_tool = self.portal.getNotificationTool() notification_tool.config['enable_instant'] = True self.portal.getNotificationTool().add_account_subscription( 'contributor', '', 'instant', 'en') self.test_folder.maintainer_email = 'someone@somehost' self.test_folder.zip_import.do_import(data=folder_with_files) self.assertEqual(len(diverted_mail), 3) expected_subject = u'Zip Import - zip_imported' expected_body = ('This is automatically generated message to inform ' 'you that a Zip archive was uploaded in zip_imported ' '(http://nohost/portal/zip_imported):\n\n' ' - one_folder/\n' ' - one_folder/one_file\n' ' - one_folder/three_file\n' ' - one_folder/two_file') expected_recipients = ['*****@*****.**',# administrator_email 'someone@somehost', # folder_maintainer '*****@*****.**'] # subscriber expected_sender = '*****@*****.**' mail = diverted_mail[0] self.assertTrue(expected_body in mail[0]) self.assertEqual(expected_recipients[0], diverted_mail[0][1][0]) self.assertEqual(expected_recipients[1], diverted_mail[1][1][0]) self.assertEqual(expected_recipients[2], diverted_mail[2][1][0]) self.assertEqual(expected_sender, mail[2]) self.assertEqual(expected_subject, mail[3]) EmailTool.divert_mail(False)
def _update(self, portal): EmailTool.divert_mail() eionet_surveys = ['eionet-survey', 'eionet-survey-nfp-meeting', 'eionet-survey-nrc-webinar'] meetings = portal.getCatalogedObjects(meta_type='Naaya Meeting') for meeting in meetings: for survey_id in eionet_surveys: survey = getattr(meeting, survey_id, None) if survey: meeting_start = DateTime(meeting.interval.start_date.year, meeting.interval.start_date.month, meeting.interval.start_date.day) if meeting_start > DateTime() - 14: if (survey.releasedate == meeting_start and survey.expirationdate == meeting_start + 13): self.log.debug( 'Interval already correct for survey %s' % survey.absolute_url()) elif survey.releasedate < meeting_start: self.log.debug('Survey %s might be too old!' % survey.absolute_url()) else: survey.releasedate = meeting_start survey.expirationdate = meeting_start + 13 self.log.debug('Interval set for survey %s' % survey.absolute_url()) return True
def _update(self, portal): EmailTool.divert_mail() eionet_surveys = ['eionet-survey', 'eionet-survey-nfp-meeting', 'eionet-survey-nrc-webinar'] meetings = portal.getCatalogedObjects(meta_type='Naaya Meeting') for meeting in meetings: for survey_id in eionet_surveys: survey = getattr(meeting, survey_id, None) if survey: changed = False for widget in survey.objectValues( ['Naaya Radio Widget', 'Naaya Radio Matrix Widget']): # The Eionet Forum has only one language: en choices = widget._local_properties['choices'][ 'en'][0] if 'I prefer not to answer' not in choices: choices.append('I prefer not to answer') widget.set_localpropvalue('choices', 'en', choices) changed = True if changed: self.log.debug('Choice added on survey %s' % survey.absolute_url()) else: self.log.debug('Choice already present on survey %s' % survey.absolute_url()) return True
def _update(self, portal): cat = portal['portal_catalog'] contacts = cat.searchResults(meta_type="Naaya Contact") map_tool = portal['portal_map'] mgsc = map_tool.getSymbolChildren mgpt = map_tool.getParentByTitle tfs = lambda s: map_tool.getSymbol(s).title #import pdb; pdb.set_trace() organizations_symbols = [s.id for s in mgsc(mgpt("ORGANIZATIONS").id)] market_symbols = [s.id for s in mgsc(mgpt("MARKET PLACE").id)] solutions_symbols = [s.id for s in mgsc(mgpt("MARKET SOLUTIONS").id)] businesses = map_tool.getSymbolByTitle("Businesses").id self.log.info("Migration: start migration of geo_types") EmailTool.divert_mail() counter = 0 for brain in contacts: contact = brain.getObject() symbol = contact.geo_type if symbol: self.log.info("Migrating contact %s", contact.absolute_url()) if symbol in market_symbols: contact.__dict__['category-organization'] = businesses contact.__dict__['category-marketplace'] = symbol contact.__dict__['category-supporting-solutions'] = '' self.log.info( "Set category-marketplace to (marketplace) %s", tfs(symbol)) elif symbol in solutions_symbols: contact.__dict__['category-organization'] = businesses contact.__dict__['category-marketplace'] = '' contact.__dict__['category-supporting-solutions'] = symbol self.log.info( "Set category-supporting-solutions to (solutions) %s", tfs(symbol)) elif symbol in organizations_symbols: contact.__dict__['category-organization'] = symbol contact.__dict__['category-marketplace'] = '' contact.__dict__['category-supporting-solutions'] = '' self.log.info( "Set category-organization to (organizations) %s", tfs(symbol)) else: self.log.info("Symbol without parent: %s", tfs(symbol)) contact._p_changed = True counter += 1 EmailTool.divert_mail(False) self.log.info("Migration: end migration") return True
def _update(self, portal): cat = portal['portal_catalog'] contacts = cat.searchResults(meta_type="Naaya Contact") map_tool = portal['portal_map'] mgsc = map_tool.getSymbolChildren mgpt = map_tool.getParentByTitle tfs = lambda s:map_tool.getSymbol(s).title #import pdb; pdb.set_trace() organizations_symbols = [s.id for s in mgsc(mgpt("ORGANIZATIONS").id)] market_symbols = [s.id for s in mgsc(mgpt("MARKET PLACE").id)] solutions_symbols = [s.id for s in mgsc(mgpt("MARKET SOLUTIONS").id)] businesses = map_tool.getSymbolByTitle("Businesses").id self.log.info("Migration: start migration of geo_types") EmailTool.divert_mail() counter = 0 for brain in contacts: contact = brain.getObject() symbol = contact.geo_type if symbol: self.log.info("Migrating contact %s", contact.absolute_url()) if symbol in market_symbols: contact.__dict__['category-organization'] = businesses contact.__dict__['category-marketplace'] = symbol contact.__dict__['category-supporting-solutions'] = '' self.log.info("Set category-marketplace to (marketplace) %s", tfs(symbol)) elif symbol in solutions_symbols: contact.__dict__['category-organization'] = businesses contact.__dict__['category-marketplace'] = '' contact.__dict__['category-supporting-solutions'] = symbol self.log.info("Set category-supporting-solutions to (solutions) %s", tfs(symbol)) elif symbol in organizations_symbols: contact.__dict__['category-organization'] = symbol contact.__dict__['category-marketplace'] = '' contact.__dict__['category-supporting-solutions'] = '' self.log.info("Set category-organization to (organizations) %s", tfs(symbol)) else: self.log.info("Symbol without parent: %s", tfs(symbol)) contact._p_changed = True counter += 1 EmailTool.divert_mail(False) self.log.info("Migration: end migration") return True
def _update(self, portal): diverted_mail = EmailTool.divert_mail() meetings = portal.getCatalogedObjects(meta_type='Naaya Meeting') for meeting in meetings: subscriptions = meeting.getParticipants().getSubscriptions() self.log.debug('Found meeting object at %s' % meeting.absolute_url(1)) for attendee in meeting.getParticipants().getAttendees(): if not (subscriptions._is_signup(attendee) or subscriptions.getAccountSubscription(attendee)): subscriptions._add_account_subscription(attendee, accept=True) self.log.debug('Added account subscription for user %s' % attendee) EmailTool.divert_mail(False) return True
def _update(self, portal): cat = portal['portal_catalog'] users = portal['acl_users'].getUsers() auth_tool = portal.getAuthenticationTool() context = portal.restrictedTraverse('who-who/destinet-users') #approved, approved_by = 1, self.request.AUTHENTICATED_USER.getUserName() approved, approved_by = 0, None self.log.info("Migration: start migration of contacts for old users") EmailTool.divert_mail() counter = 0 for user in users: fullname = auth_tool.getUserFullNameByID(user.name) contacts = cat.searchResults(meta_type='Naaya Contact', title=fullname) if not contacts: counter += 1 id = uniqueId(slugify(user.name or 'contact', removelist=[]), lambda x: context._getOb(x, None) is not None) ob = _create_NyContact_object(context, id, user.name) ob.approveThis(approved, approved_by) ob.submitThis() ob.title = auth_tool.getUserFullNameByID(id) ob.description = '' context.recatalogNyObject(ob) #crashes with unicodedecodeerror: #notify(NyContentObjectAddEvent(ob, user.name, {})) #log post date auth_tool.changeLastPost(user.name) self.log.info("Migration: %s - added contact for user: %s", counter, id) EmailTool.divert_mail(False) self.log.info("Migration: end migration") return True
def test_anonymous_account_subscription(self): """ Add anonymous notification. This sends an email with a confirmation key. Confirm with confirm method and verify if subscription is in the container. """ diverted_mail = EmailTool.divert_mail() notif_tool = self.portal.getNotificationTool() notif_tool.add_anonymous_subscription(email='*****@*****.**', lang='en', location='', notif_type='instant') assert diverted_mail[0][1] == ['*****@*****.**'] assert diverted_mail[0][2] == '*****@*****.**' assert diverted_mail[0][0].find('confirm?key=') != -1 confirm_key = re.search('confirm\?key=(\w+)', diverted_mail[0][0]).group(1) notif_tool.confirm(key=confirm_key) for obj, n, sub in walk_subscriptions(self.portal): if sub.email == '*****@*****.**': break else: raise "No subscription found" EmailTool.divert_mail(False)