diff options
author | David Rousselie <dax@happycoders.org> | 2008-05-28 21:51:40 +0400 |
---|---|---|
committer | David Rousselie <dax@happycoders.org> | 2008-05-28 21:51:40 +0400 |
commit | 697e47e2dca4298651a4940532bcdf0bd75ad29e (patch) | |
tree | cc8375a553b708753cbe537ee5c17535abed088b | |
parent | e2124994565632b5ccf3aa638c248fc7214feec2 (diff) |
Change MailAccount.lastcheck semantic. Now store time in second since the Epoch
darcs-hash:20080528175140-86b55-bdc04a37258a53658908fb453a4be45370b82355.gz
-rw-r--r-- | src/jmc/jabber/command.py | 7 | ||||
-rw-r--r-- | src/jmc/jabber/feeder.py | 17 | ||||
-rw-r--r-- | src/jmc/jabber/tests/command.py | 5 | ||||
-rw-r--r-- | src/jmc/jabber/tests/component.py | 57 |
4 files changed, 58 insertions, 28 deletions
diff --git a/src/jmc/jabber/command.py b/src/jmc/jabber/command.py index cfaaeea..01fd1b4 100644 --- a/src/jmc/jabber/command.py +++ b/src/jmc/jabber/command.py @@ -22,6 +22,7 @@ import logging import re +import time from pyxmpp.jabber.dataforms import Form @@ -101,7 +102,8 @@ class MailCommandManager(JCLCommandManager): for account_name in session_context["account_names"]: name, user_jid = self.get_name_and_jid(account_name) _account = account.get_account(user_jid, name) - _account.lastcheck = _account.interval - 1 + _account.lastcheck = int(time.time()) \ + - (_account.interval * self.component.time_unit) accounts.append(_account) else: return self.execute_force_check_root_node(info_query, @@ -111,7 +113,8 @@ class MailCommandManager(JCLCommandManager): else: _account = account.get_account(bare_from_jid, account_name) if _account is not None: - _account.lastcheck = _account.interval - 1 + _account.lastcheck = int(time.time()) \ + - (_account.interval * self.component.time_unit) accounts.append(_account) command_node.setProp("status", command.STATUS_COMPLETED) self.component.check_email_accounts(accounts, lang_class) diff --git a/src/jmc/jabber/feeder.py b/src/jmc/jabber/feeder.py index a496396..8177171 100644 --- a/src/jmc/jabber/feeder.py +++ b/src/jmc/jabber/feeder.py @@ -28,6 +28,7 @@ FeederComponent with JMC Feeder and Sender implementation __revision__ = "$Id: feeder.py,v 1.1 2008/03/05 20:24:07 dax Exp $" import logging +import time from pyxmpp.jid import JID @@ -83,13 +84,15 @@ class MailFeeder(Feeder): """ self.__logger.debug("MailFeeder.feed") result = [] - if _account.first_check and _account.live_email_only: - continue_checking = self.initialize_live_email(_account) - if not continue_checking: - return result - _account.lastcheck += 1 - if _account.lastcheck == _account.interval: - _account.lastcheck = 0 + if _account.first_check: + _account.lastcheck = int(time.time()) + if _account.live_email_only: + continue_checking = self.initialize_live_email(_account) + if not continue_checking: + return result + if (int(time.time()) - _account.lastcheck) \ + >= (_account.interval * self.component.time_unit): + _account.lastcheck = int(time.time()) action = _account.action if action != PresenceAccount.DO_NOTHING: try: diff --git a/src/jmc/jabber/tests/command.py b/src/jmc/jabber/tests/command.py index 42e36bd..c336b1a 100644 --- a/src/jmc/jabber/tests/command.py +++ b/src/jmc/jabber/tests/command.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- ## ## command.py ## Login : David Rousselie <dax@happycoders.org> @@ -26,6 +27,7 @@ from ConfigParser import ConfigParser import os import sys import logging +import time from pyxmpp.iq import Iq from pyxmpp.jabber.dataforms import Field @@ -100,7 +102,8 @@ class MailCommandManagerTestCase(JCLCommandManagerTestCase): def feed(self, _account): self.checked_accounts.append(_account) - assert(_account.lastcheck == (_account.interval - 1)) + assert((int(time.time()) - _account.lastcheck \ + >= (_account.interval * self.component.time_unit))) return [] self.comp.handler.feeder = MockFeederHandler(self.comp) diff --git a/src/jmc/jabber/tests/component.py b/src/jmc/jabber/tests/component.py index 7fa4c45..a88f63b 100644 --- a/src/jmc/jabber/tests/component.py +++ b/src/jmc/jabber/tests/component.py @@ -25,6 +25,7 @@ import unittest import sys import time import logging +import time from sqlobject import * from sqlobject.dbconnection import TheURIOpener @@ -204,6 +205,13 @@ class MailComponent_TestCase(JCLTestCase): self.comp.stream = MockStream() self.comp.stream_class = MockStream + def _account_has_been_checked(self, _account, old_value): + if old_value == _account.lastcheck: + return False + else: + delta = int(time.time()) - _account.lastcheck + return (delta <= 1) and (delta >= 0) + ########################################################################### # 'feed' test methods ########################################################################### @@ -256,11 +264,24 @@ class MailComponent_TestCase(JCLTestCase): jid="account11@jmc.test.com") account11._action = PresenceAccount.DO_NOTHING account11.first_check = False - self.assertEquals(account11.lastcheck, 0) + account11.lastcheck = old_value = int(time.time()) - 2 + account11.interval = 2 + result = self.comp.handler.feeder.feed(account11) + self.assertEquals(result, []) + self.assertFalse(self._account_has_been_checked(account11, + old_value)) + + def test_feed_interval_first_check(self): + account11 = MockIMAPAccount(user=User(jid="test1@test.com"), + name="account11", + jid="account11@jmc.test.com") + account11._action = PresenceAccount.DO_NOTHING + account11.first_check = True + account11.lastcheck = 0 account11.interval = 2 result = self.comp.handler.feeder.feed(account11) self.assertEquals(result, []) - self.assertEquals(account11.lastcheck, 1) + self.assertTrue(self._account_has_been_checked(account11, 0)) def test_feed_interval_check(self): account11 = MockIMAPAccount(user=User(jid="test1@test.com"), @@ -268,11 +289,11 @@ class MailComponent_TestCase(JCLTestCase): jid="account11@jmc.test.com") account11._action = PresenceAccount.DO_NOTHING account11.first_check = False - account11.lastcheck = 1 + account11.lastcheck = 0 account11.interval = 2 result = self.comp.handler.feeder.feed(account11) self.assertEquals(result, []) - self.assertEquals(account11.lastcheck, 0) + self.assertTrue(self._account_has_been_checked(account11, 0)) def test_feed_no_password(self): account11 = MockIMAPAccount(user=User(jid="test1@test.com"), @@ -281,7 +302,7 @@ class MailComponent_TestCase(JCLTestCase): account11._action = MailAccount.RETRIEVE account11.status = account.ONLINE account11.first_check = False - account11.lastcheck = 1 + account11.lastcheck = 0 account11.interval = 2 account11.password = None self.assertFalse(account11.waiting_password_reply) @@ -292,7 +313,7 @@ class MailComponent_TestCase(JCLTestCase): self.assertEquals(len(sent), 1) self.assertEquals(sent[0].get_to(), "test1@test.com") self.assertEquals(sent[0].get_from(), "account11@jmc.test.com") - self.assertEquals(account11.lastcheck, 0) + self.assertTrue(self._account_has_been_checked(account11, 0)) self.assertFalse(account11.connected) self.assertFalse(account11.has_connected) @@ -303,7 +324,7 @@ class MailComponent_TestCase(JCLTestCase): account11._action = 42 # Unknown action account11.status = account.ONLINE account11.first_check = False - account11.lastcheck = 1 + account11.lastcheck = 0 account11.interval = 2 account11.password = "password" account11.get_new_mail_list = lambda: [] @@ -319,7 +340,7 @@ class MailComponent_TestCase(JCLTestCase): self.assertEquals(sent[1].xmlnode.name, "presence") self.assertEquals(sent[1].xmlnode.children.name, "show") self.assertEquals(sent[1].xmlnode.children.content, "dnd") - self.assertEquals(account11.lastcheck, 0) + self.assertTrue(self._account_has_been_checked(account11, 0)) self.assertFalse(account11.connected) self.assertTrue(account11.has_connected) @@ -330,14 +351,14 @@ class MailComponent_TestCase(JCLTestCase): account11._action = MailAccount.RETRIEVE account11.status = account.ONLINE account11.first_check = False - account11.lastcheck = 1 + account11.lastcheck = 0 account11.interval = 2 account11.password = "password" account11.get_new_mail_list = lambda: [] result = self.comp.handler.feeder.feed(account11) self.assertEquals(account11.error, None) self.assertEquals(result, []) - self.assertEquals(account11.lastcheck, 0) + self.assertTrue(self._account_has_been_checked(account11, 0)) self.assertFalse(account11.connected) self.assertTrue(account11.has_connected) self.assertEquals(len(self.comp.stream.sent), 0) @@ -350,14 +371,14 @@ class MailComponent_TestCase(JCLTestCase): account11.status = account.DND account11.error = "An error" account11.first_check = False - account11.lastcheck = 1 + account11.lastcheck = 0 account11.interval = 2 account11.password = "password" account11.get_new_mail_list = lambda: [] result = self.comp.handler.feeder.feed(account11) self.assertEquals(account11.error, None) self.assertEquals(result, []) - self.assertEquals(account11.lastcheck, 0) + self.assertTrue(self._account_has_been_checked(account11, 0)) self.assertFalse(account11.connected) self.assertTrue(account11.has_connected) sent = self.comp.stream.sent @@ -379,14 +400,14 @@ class MailComponent_TestCase(JCLTestCase): account11._action = MailAccount.RETRIEVE account11.status = account.ONLINE account11.first_check = False - account11.lastcheck = 1 + account11.lastcheck = 0 account11.interval = 2 account11.password = "password" account11.get_new_mail_list = lambda: [0, 1] account11.get_mail = mock_get_mail result = self.comp.handler.feeder.feed(account11) self.assertEquals(account11.error, None) - self.assertEquals(account11.lastcheck, 0) + self.assertTrue(self._account_has_been_checked(account11, 0)) self.assertFalse(account11.connected) self.assertTrue(account11.has_connected) self.assertEquals(len(self.comp.stream.sent), 0) @@ -413,14 +434,14 @@ class MailComponent_TestCase(JCLTestCase): account11._action = MailAccount.DIGEST account11.status = account.ONLINE account11.first_check = False - account11.lastcheck = 1 + account11.lastcheck = 0 account11.interval = 2 account11.password = "password" account11.get_new_mail_list = lambda: [] result = self.comp.handler.feeder.feed(account11) self.assertEquals(account11.error, None) self.assertEquals(result, []) - self.assertEquals(account11.lastcheck, 0) + self.assertTrue(self._account_has_been_checked(account11, 0)) self.assertFalse(account11.connected) self.assertTrue(account11.has_connected) self.assertEquals(len(self.comp.stream.sent), 0) @@ -437,14 +458,14 @@ class MailComponent_TestCase(JCLTestCase): account11._action = MailAccount.DIGEST account11.status = account.ONLINE account11.first_check = False - account11.lastcheck = 1 + account11.lastcheck = 0 account11.interval = 2 account11.password = "password" account11.get_new_mail_list = lambda: [0, 1] account11.get_mail_summary = mock_get_mail_summary result = self.comp.handler.feeder.feed(account11) self.assertEquals(account11.error, None) - self.assertEquals(account11.lastcheck, 0) + self.assertTrue(self._account_has_been_checked(account11, 0)) self.assertFalse(account11.connected) self.assertTrue(account11.has_connected) self.assertEquals(len(self.comp.stream.sent), 0) |