Commits

Christophe Combelles committed 2bb5a0a

fixed mail plugin and tests

  • Participants
  • Parent commits deee852

Comments (0)

Files changed (4)

File atomisator/main/__init__.py

 
 # we'll use two processes per CPU
 PROCESSES = cpu_count() * 2
-
+PROCESSES = 1

File atomisator/main/tests/test_main.py

 
 
 saved = None
+test_dir = os.path.dirname(__file__)
+test_conf = os.path.join(test_dir, 'atomisator.cfg')
 
 def setup():
     global saved
     saved = sys.argv
 
+    template = open(os.path.join(test_dir, 'atomisator.cfg_tmpl')).read()
+    cfg = template % {'test_dir': test_dir}
+    f = open(test_conf, 'w')
+    f.write(cfg)
+    f.close()
+
 def teardown():
     sys.argv = saved
+    if os.path.exists(test_conf):
+        os.remove(test_conf)
 
 @with_setup(setup, teardown)
 def test_options():
 
 @with_setup(setup, teardown)
 def test_load_data():
-
     DataProcessor(test_conf).load_data()
 
 @with_setup(setup, teardown)
     proc.generate_data()
 
     # as usual but in memory
-    assert len(proc.existing_entries) > 50
+    assert len(proc.existing_entries) > 1
 
 @with_setup(setup, teardown)
 def test_mono_proc():

File atomisator/outputs/mail.py

 
         # XXX not keeping entries with no diff
         # this should be its own plugin so email plugin stay generic
-        entries = [entry for entry in entries if entry.diff not in ('', None)]
+        #entries = [entry for entry in entries if getattr(entry, 'diff', None) not in ('', None)]
 
         # lines
         # should be generic
         lines = [values['entry_template'] % {'title': entry.title,
                                              'link': entry.link,
-                                             'diff': entry.diff}
+                                             'diff': getattr(entry, 'diff', '')}
                  for entry in entries]
 
         lines = [line for line in lines if line.strip() != 'None']
 
         # we don't mail an empty mail
         if ''.join(lines).strip() == '':
+            logging.warn("We don't mail en empty mail!")
             return
 
         # mail content
         msg['To'] = ','.join(values['tos'])
         msg['From'] = values['from']
         msg['Date'] = datetime.now().isoformat()
-        msg.set_charset('utf8')
+        msg.set_charset('utf-8')
         msg = msg.as_string()
 
         # let's send it
         try:
             s.sendmail(values['from'], values['tos'], msg)
             logging.info('Mail sent to %s' % ','.join(values['tos']))
+        except Exception, e:
+            logging.warn(e.message)
         finally:
             s.close()
 

File atomisator/outputs/tests/test_mail.py

 To: tarek@ziade.org
 From: admin@atomisator
 Date: NOW
-Content-Type: text/plain; charset="utf8"
+Content-Type: text/plain; charset="utf-8"
 
 Atomisator has triggered an alert. Check out for: