def runTest(self): # Log in an administrator self.assertTrue(self.client.login(username=self.admins[0].username, password='******'), "Failed to log in admin user.") # Select users to fetch post_data = { 'submit_user_list': 'true', 'base_list': 'enrolled', 'keys': '', 'finalsent': 'Test List', 'submitform': 'I have my list, go on!', } response = self.client.post('/manage/%s/%s' % (self.program.getUrlBase(), 'commpanel_old'), post_data) self.assertEqual(response.status_code, 200) # Extract filter ID from response s = re.search(r'<input type="hidden" name="filterid" value="([0-9]+)" />', response.content) filterid = s.groups()[0] s = re.search(r'<input type="hidden" name="listcount" value="([0-9]+)" />', response.content) listcount = s.groups()[0] # Enter e-mail information post_data = { 'subject': 'Test Subject 123', 'body': 'Test Body 123', 'from': 'from@email-server', 'replyto': 'replyto@email-server', 'filterid': filterid, } response = self.client.post('/manage/%s/%s' % (self.program.getUrlBase(), 'commfinal'), post_data) self.assertEqual(response.status_code, 200) # Check that a MessageRequest has been created m = MessageRequest.objects.filter(recipients__id=filterid, subject='Test Subject 123') self.assertTrue(m.count() == 1) self.assertFalse(m[0].processed) # Send out e-mail msgs = process_messages() send_email_requests() # Check that the e-mail was sent to all students self.assertEqual(len(mail.outbox), len(self.students)) # Check that the e-mails matched the entered information msg = mail.outbox[0] self.assertEqual(msg.subject, 'Test Subject 123') self.assertEqual(msg.body, 'Test Body 123') self.assertEqual(msg.from_email, 'from@email-server') self.assertEqual(msg.extra_headers.get('Reply-To', ''), 'replyto@email-server') # Check that the MessageRequest was marked as processed m = MessageRequest.objects.filter(recipients__id=filterid, subject='Test Subject 123') self.assertTrue(m.count() == 1) self.assertTrue(m[0].processed)
def runTest(self): # Log in an administrator self.failUnless(self.client.login(username=self.admins[0].username, password='******'), "Failed to log in admin user.") # Select users to fetch post_data = { 'submit_user_list': 'true', 'base_list': 'enrolled', 'keys': '', 'finalsent': 'Test List', 'submitform': 'I have my list, go on!', } response = self.client.post('/manage/%s/%s' % (self.program.getUrlBase(), 'commpanel_old'), post_data) self.assertEqual(response.status_code, 200) # Extract filter ID from response s = re.search(r'<input type="hidden" name="filterid" value="([0-9]+)" />', response.content) filterid = s.groups()[0] s = re.search(r'<input type="hidden" name="listcount" value="([0-9]+)" />', response.content) listcount = s.groups()[0] # Enter e-mail information post_data = { 'subject': 'Test Subject 123', 'body': 'Test Body 123', 'from': 'from@email-server', 'replyto': 'replyto@email-server', 'filterid': filterid, } response = self.client.post('/manage/%s/%s' % (self.program.getUrlBase(), 'commfinal'), post_data) self.assertEqual(response.status_code, 200) # Check that a MessageRequest has been created m = MessageRequest.objects.filter(recipients__id=filterid, subject='Test Subject 123') self.assertTrue(m.count() == 1) self.assertFalse(m[0].processed) # Send out e-mail msgs = process_messages() send_email_requests(msgs) # Check that the e-mail was sent to all students self.assertEqual(len(mail.outbox), len(self.students)) # Check that the e-mails matched the entered information msg = mail.outbox[0] self.assertEqual(msg.subject, 'Test Subject 123') self.assertEqual(msg.body, 'Test Body 123') self.assertEqual(msg.from_email, 'from@email-server') self.assertEqual(msg.extra_headers.get('Reply-To', ''), 'replyto@email-server') # Check that the MessageRequest was marked as processed m = MessageRequest.objects.filter(recipients__id=filterid, subject='Test Subject 123') self.assertTrue(m.count() == 1) self.assertTrue(m[0].processed)
#!/usr/bin/python import sys sys.path += ['/esp/web/esp/'] sys.path += ['/esp/web/esp/esp/'] sys.path += ['/esp/web/esp/django/'] import os os.environ['DJANGO_SETTINGS_MODULE'] = 'esp.settings' from esp import cache_loader import esp.manage from esp.dbmail.cronmail import send_miniblog_messages, process_messages, send_email_requests #send_event_notices_for_day('tomorrow') #send_miniblog_messages() msgs = process_messages() send_email_requests(msgs)
# If the variable isn't defined, then activate our own virtualenv. if os.environ.get('VIRTUAL_ENV') is None: root = os.path.dirname(project) activate_this = os.path.join(root, 'env', 'bin', 'activate_this.py') execfile(activate_this, dict(__file__=activate_this)) import django django.setup() from esp.dbmail.cronmail import process_messages, send_email_requests # This import must be after the evaluation of the Django settings, because # esp.settings modifies tempfile to avoid collisions between sites. import tempfile # lock to ensure only one cron instance runs at a time lock_file_path = os.path.join(tempfile.gettempdir(), 'espweb.dbmailcron.lock') lock_file_handle = open(lock_file_path, 'w') try: fcntl.lockf(lock_file_handle, fcntl.LOCK_EX | fcntl.LOCK_NB) except IOError: # another instance has the lock sys.exit(0) process_messages() send_email_requests() # Release the lock when message sending is complete. fcntl.lockf(lock_file_handle, fcntl.LOCK_UN) lock_file_handle.close()