summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorBruno Wagner <bwagner@thoughtworks.com>2014-10-15 15:55:53 +0200
committerBruno Wagner <bwagner@thoughtworks.com>2014-10-15 15:58:06 +0200
commitd4d0e86b25dc9c478c04d30cb6a86824332c2c7f (patch)
tree1bb49e6b71267026b4b4f55903a537dc69f057e5 /service
parentfca5dc46de7d3cfb0d4c571f9e3040ad05e2cc54 (diff)
#107 Statuses are only used when delivering mails to the front-end, flags are used elsewhere
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/pixelated_mail.py16
-rw-r--r--service/pixelated/adapter/status.py50
-rw-r--r--service/test/support/integration_helper.py2
-rw-r--r--service/test/unit/adapter/test_status.py6
4 files changed, 29 insertions, 45 deletions
diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py
index 735560c9..cd345f13 100644
--- a/service/pixelated/adapter/pixelated_mail.py
+++ b/service/pixelated/adapter/pixelated_mail.py
@@ -44,12 +44,11 @@ class Mail:
return self.headers['Date']
def as_dict(self):
- statuses = [status.name for status in self.status]
return {
'header': {k.lower(): v for k, v in self.headers.items()},
'ident': self.ident,
'tags': list(self.tags),
- 'status': statuses,
+ 'status': list(self.status),
'security_casing': {},
'body': self.body
}
@@ -108,7 +107,7 @@ class InputMail(Mail):
fd[fields.MULTIPART_KEY] = True
fd[fields.RECENT_KEY] = True
fd[fields.TYPE_KEY] = fields.TYPE_FLAGS_VAL
- fd[fields.FLAGS_KEY] = Status.to_flags([status.name for status in self.status])
+ fd[fields.FLAGS_KEY] = Status.to_flags(self.status)
self._fd = fd
return fd
@@ -201,7 +200,6 @@ class PixelatedMail(Mail):
def _get_date(self):
date = self.hdoc.content.get('date', None)
if not date:
-
date = self.hdoc.content['received'].split(";")[-1].strip()
return dateparser.parse(date).isoformat()
@@ -252,19 +250,19 @@ class PixelatedMail(Mail):
return self.tags
def mark_as_read(self):
- self.fdoc.content['flags'].append(Status.PixelatedStatus.SEEN)
+ self.fdoc.content['flags'].append(Status.SEEN)
self.save()
return self
def mark_as_unread(self):
- if Status.PixelatedStatus.SEEN in self.fdoc.content['flags']:
- self.fdoc.content['flags'].remove(Status.PixelatedStatus.SEEN)
+ if Status.SEEN in self.fdoc.content['flags']:
+ self.fdoc.content['flags'].remove(Status.SEEN)
self.save()
return self
def mark_as_not_recent(self):
- if Status.PixelatedStatus.RECENT in self.fdoc.content['flags']:
- self.fdoc.content['flags'].remove(Status.PixelatedStatus.RECENT)
+ if Status.RECENT in self.fdoc.content['flags']:
+ self.fdoc.content['flags'].remove(Status.RECENT)
self.save()
return self
diff --git a/service/pixelated/adapter/status.py b/service/pixelated/adapter/status.py
index 3807359c..5a11ee7b 100644
--- a/service/pixelated/adapter/status.py
+++ b/service/pixelated/adapter/status.py
@@ -17,40 +17,26 @@
class Status:
- class PixelatedStatus:
- SEEN = u'\\Seen'
- ANSWERED = u'\\Answered'
- DELETED = u'\\Deleted'
- RECENT = u'\\Recent'
-
- LEAP_FLAGS_STATUSES = {
- PixelatedStatus.SEEN: 'read',
- PixelatedStatus.ANSWERED: 'replied',
- PixelatedStatus.RECENT: 'recent'
+ SEEN = u'\\Seen'
+ ANSWERED = u'\\Answered'
+ DELETED = u'\\Deleted'
+ RECENT = u'\\Recent'
+
+ FLAGS_TO_STATUSES = {
+ SEEN: 'read',
+ ANSWERED: 'replied',
+ RECENT: 'recent'
}
- @classmethod
- def from_flag(cls, flag):
- return Status(cls.LEAP_FLAGS_STATUSES[flag])
+ @staticmethod
+ def from_flag(flag):
+ return Status.FLAGS_TO_STATUSES[flag]
- @classmethod
- def from_flags(cls, flags):
- return set(cls.from_flag(flag) for flag in flags if flag in cls.LEAP_FLAGS_STATUSES.keys())
+ @staticmethod
+ def from_flags(flags):
+ return set(Status.from_flag(flag) for flag in flags if flag in Status.FLAGS_TO_STATUSES.keys())
- @classmethod
- def to_flags(cls, statuses):
- statuses_to_flags = dict(zip(cls.LEAP_FLAGS_STATUSES.values(), cls.LEAP_FLAGS_STATUSES.keys()))
+ @staticmethod
+ def to_flags(statuses):
+ statuses_to_flags = dict(zip(Status.FLAGS_TO_STATUSES.values(), Status.FLAGS_TO_STATUSES.keys()))
return [statuses_to_flags[status] for status in statuses]
-
- def __init__(self, name):
- self.name = name
- self.ident = name.__hash__()
-
- def __eq__(self, other):
- return self.name == other.name
-
- def __hash__(self):
- return self.name.__hash__()
-
- def __repr__(self):
- return self.name
diff --git a/service/test/support/integration_helper.py b/service/test/support/integration_helper.py
index 1b5b1135..248b7064 100644
--- a/service/test/support/integration_helper.py
+++ b/service/test/support/integration_helper.py
@@ -113,7 +113,7 @@ class MailBuilder:
return self
def with_status(self, status):
- self.mail['status'].append(Status('read'))
+ self.mail['status'].append('read')
return self
def with_ident(self, ident):
diff --git a/service/test/unit/adapter/test_status.py b/service/test/unit/adapter/test_status.py
index bcdbb360..e9ead384 100644
--- a/service/test/unit/adapter/test_status.py
+++ b/service/test/unit/adapter/test_status.py
@@ -22,12 +22,12 @@ class TestStatus(unittest.TestCase):
def test_leap_seen_flag_is_translated_to_read_status(self):
status = Status.from_flag('\\Seen')
- self.assertEquals(Status('read'), status)
+ self.assertEquals('read', status)
def test_leap_answered_flag_is_translated_to_replied_status(self):
status = Status.from_flag('\\Answered')
- self.assertEquals(Status('replied'), status)
+ self.assertEquals('replied', status)
def test_bulk_conversion(self):
statuses = Status.from_flags(['\\Answered', '\\Seen', '\\Recent', 'tag_a_custom'])
- self.assertEquals(set([Status('read'), Status('replied'), Status('recent')]), statuses)
+ self.assertEquals(set(['read', 'replied', 'recent']), statuses)