]> khamidou — GitHub mirrors - kite.git/commitdiff
fixed failing test
authorkarim hamidou <khamidou@gmail.com>
Fri, 29 Nov 2013 09:22:22 +0000 (10:22 +0100)
committerkarim hamidou <khamidou@gmail.com>
Fri, 29 Nov 2013 09:22:22 +0000 (10:22 +0100)
src/back/kite/filterdaemon.py
src/back/tests/test_filterdaemon.py

index 7e037aba590998273fd035667e28e3cc248f4aac..def39d9c3c0b487091c9d5e8f2805e4f318dd0ae 100644 (file)
@@ -72,9 +72,7 @@ class DumperThread(threading.Thread):
             print "Dumping threads index"
             threads_index.save()
             
-def process_new_email(path):
-    global threads_index
-
+def process_new_email(path, threads_index):
     with open(path, "r") as fd:
         parser = email.parser.HeaderParser()
         email_headers = parser.parse(fd)
@@ -82,11 +80,11 @@ def process_new_email(path):
 
         if subject != None:
             subject = headers.cleanup_subject(subject)
-            if subject in threads_index.data:
-                threads_index.data[subject].append(path)
+            if subject in threads_index["data"]:
+                threads_index["data"][subject].append(path)
             else:
                 # create a new thread
-                threads_index.data[subject] = [path]
+                threads_index["data"][subject] = [path]
 
 
 class ProcessorThread(threading.Thread):
@@ -94,10 +92,9 @@ class ProcessorThread(threading.Thread):
         threading.Thread.__init__(self)
         self.path = path
 
-        global threads_index
-        threads_index = JsonFile(os.path.join(self.path, "threads_index.json"))
-        if threads_index.data == None:
-            threads_index.data = {}
+        self.threads_index = JsonFile(os.path.join(self.path, "threads_index.json"))
+        if self.threads_index.data == None:
+            self.threads_index.data = {}
 
     def run(self):
         while True:
@@ -105,7 +102,7 @@ class ProcessorThread(threading.Thread):
                 event = events_queue.pop(0)
                 if event["type"] == "create":
                     try:
-                        self.process_new_email(event["path"])
+                        self.process_new_email(event["path"], self.threads_index)
                     except IOError:
                         # This may be a Postfix/Dovecot temporary file. Ignore it.
                         pass
index 9ecfb5d55682ea57bcb83a80af2f6ca88daf9d58..1867cc663d61357f77e40232f95fafbd1272dea7 100644 (file)
@@ -1,10 +1,9 @@
 import unittest
 import kite.filterdaemon as filterdaemon
 
-threads_index = {"data": {}}
 
 class TestEmailProcessor(unittest.TestCase):
     def test_process_email(self):
-        global threads_index
-        filterdaemon.process_new_email("mocks/test_process_email.txt")
+        threads_index = {"data": {}}
+        filterdaemon.process_new_email("mocks/test_process_email.txt", threads_index)
         self.assertTrue("Hey, How are you ?" in threads_index["data"])