diff options
author | Bruno Wagner Goncalves <bwagner@thoughtworks.com> | 2014-08-14 14:02:49 -0300 |
---|---|---|
committer | Bruno Wagner Goncalves <bwagner@thoughtworks.com> | 2014-08-14 14:02:49 -0300 |
commit | ff6aafebcc40d3b734da794e732a0b1cd3526964 (patch) | |
tree | abb750b4da9c340fdf2868203f5f9d46ca5c7d08 | |
parent | b5e0973245c2af1c5c9d67f5f15eeb00a93cfc93 (diff) |
Update mail tags are now on the right place
-rw-r--r-- | service/app/adapter/mail_service.py | 12 | ||||
-rw-r--r-- | service/app/pixelated_user_agent.py | 12 | ||||
-rw-r--r-- | service/test/adapter/mail_service_test.py | 10 |
3 files changed, 15 insertions, 19 deletions
diff --git a/service/app/adapter/mail_service.py b/service/app/adapter/mail_service.py index 94612d82..73baef56 100644 --- a/service/app/adapter/mail_service.py +++ b/service/app/adapter/mail_service.py @@ -54,17 +54,9 @@ class MailService: def mails(self, query): return self.mailbox.messages or [] - def update_mail(self, dict_mail): - # Iterating over messages because messages.getUID() is not trustworthy - mail = None - for message in self.mailbox.messages: - if message.getUID() == dict_mail['ident']: - mail = PixelatedMail(message) - - new_tags = mail.update_tags(dict_mail['tags']) - + def update_tags(self, mail, new_tags): + new_tags = mail.update_tags(new_tags) self._update_tag_list(new_tags) - return mail def _update_tag_list(self, tags): diff --git a/service/app/pixelated_user_agent.py b/service/app/pixelated_user_agent.py index 2d0dc4b8..7f13809a 100644 --- a/service/app/pixelated_user_agent.py +++ b/service/app/pixelated_user_agent.py @@ -88,21 +88,23 @@ def delete_mails(mail_id): @app.route('/tags') def tags(): - tags = Tags() + tags = mail_service.all_tags() return respond_json(tags.as_dict()) @app.route('/mail/<mail_id>') def mail(mail_id): mail = mail_service.mail(mail_id) - mail = PixelatedMail(mail) return respond_json(mail.as_dict()) -@app.route('/mail/<mail_id>/tags') +@app.route('/mail/<mail_id>/tags', methods=['POST']) def mail_tags(mail_id): - mail = converter.from_mail(mail_service.mail(mail_id)) - return respond_json(mail['tags']) + new_tags = request.get_json()['newtags'] + mail = mail_service.mail(mail_id) + mail_service.update_tags(mail, new_tags) + tag_names = [tag.name for tag in mail.tags] + return respond_json(tag_names) @app.route('/mail/<mail_id>/read', methods=['POST']) diff --git a/service/test/adapter/mail_service_test.py b/service/test/adapter/mail_service_test.py index 4751413d..8187e586 100644 --- a/service/test/adapter/mail_service_test.py +++ b/service/test/adapter/mail_service_test.py @@ -32,8 +32,10 @@ class TestMailService(unittest.TestCase): mailservice = MailService() - raw_mail = self._raw_mail() - raw_mail['tags'].append('my_new_tag') - mails = mailservice.update_mail(raw_mail) + new_tags = ['test'] + mails = mailservice.update_tags(mailservice.mail(6), new_tags) - self.assertIn(Tag('my_new_tag'), mailservice.all_tags()) + for tag in mailservice.all_tags(): + print tag.name + + self.assertIn(Tag('test'), mailservice.all_tags()) |