summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2014-08-12 13:45:07 -0300
committerDuda Dornelles <ddornell@thoughtworks.com>2014-08-12 13:45:07 -0300
commitfa75c5ddd40d15f1ccbfc593d6f3ab0d50acaf9e (patch)
treed1cc1e76fff67d606a21221444bdf8b0261674a9
parente7db94a986f411e1a86b9a6cc2af21a7e74e1fcf (diff)
marking mail as read in fake-service
-rw-r--r--py-fake-service/app/adapter/mail.py9
-rw-r--r--py-fake-service/app/adapter/mail_service.py6
-rw-r--r--py-fake-service/app/adapter/mailset.py4
-rw-r--r--py-fake-service/app/adapter/tag.py3
-rw-r--r--py-fake-service/app/adapter/tagsset.py5
-rw-r--r--py-fake-service/app/pixelated_user_agent.py1
6 files changed, 26 insertions, 2 deletions
diff --git a/py-fake-service/app/adapter/mail.py b/py-fake-service/app/adapter/mail.py
index 859eb50c..380d1e2c 100644
--- a/py-fake-service/app/adapter/mail.py
+++ b/py-fake-service/app/adapter/mail.py
@@ -9,7 +9,14 @@ class Mail:
self.body = mbox_mail.get_payload()
self.tags = self._get_tags(mbox_mail)
self.security_casing = {}
- self.status = []
+ self.status = self._get_status()
+
+ def _get_status(self):
+ status = []
+ if 'sent' in self.tags:
+ status.append('read')
+
+ return status
def _get_headers(self, mbox_mail):
headers = {}
diff --git a/py-fake-service/app/adapter/mail_service.py b/py-fake-service/app/adapter/mail_service.py
index 649ea96e..7073e549 100644
--- a/py-fake-service/app/adapter/mail_service.py
+++ b/py-fake-service/app/adapter/mail_service.py
@@ -36,3 +36,9 @@ class MailService:
def search_contacts(self, query):
return self.contacts.search(query)
+ def mark_as_read(self, mail_id):
+ self.mailset.mark_as_read(mail_id)
+ self.tagsset.mark_as_read(self.mail(mail_id).tags)
+
+
+
diff --git a/py-fake-service/app/adapter/mailset.py b/py-fake-service/app/adapter/mailset.py
index 2b1627ae..2568e33b 100644
--- a/py-fake-service/app/adapter/mailset.py
+++ b/py-fake-service/app/adapter/mailset.py
@@ -17,4 +17,6 @@ class MailSet:
def get(self, mail_id):
return self.mails.get(int(mail_id))
-
+ def mark_as_read(self, mail_id):
+ mail = self.mails.get(int(mail_id))
+ mail.status.append('read')
diff --git a/py-fake-service/app/adapter/tag.py b/py-fake-service/app/adapter/tag.py
index bc98669d..73103490 100644
--- a/py-fake-service/app/adapter/tag.py
+++ b/py-fake-service/app/adapter/tag.py
@@ -15,3 +15,6 @@ class Tag:
def increment_count(self):
self.counts['total'] += 1
+
+ def increment_read(self):
+ self.counts['read'] += 1
diff --git a/py-fake-service/app/adapter/tagsset.py b/py-fake-service/app/adapter/tagsset.py
index 23941735..04c712d4 100644
--- a/py-fake-service/app/adapter/tagsset.py
+++ b/py-fake-service/app/adapter/tagsset.py
@@ -14,3 +14,8 @@ class TagsSet:
def all_tags(self):
return self.tags.values()
+
+ def mark_as_read(self, tags):
+ for tag in tags:
+ tag = self.tags.get(tag)
+ tag.increment_read()
diff --git a/py-fake-service/app/pixelated_user_agent.py b/py-fake-service/app/pixelated_user_agent.py
index 20ccadcc..48081bda 100644
--- a/py-fake-service/app/pixelated_user_agent.py
+++ b/py-fake-service/app/pixelated_user_agent.py
@@ -76,6 +76,7 @@ def mail_tags(mail_id):
@app.route('/mail/<mail_id>/read', methods=['POST'])
def mark_mail_as_read(mail_id):
+ mail_service.mark_as_read(mail_id)
return ""
@app.route('/contacts')