diff options
author | Patrick Maia <patrickjourdanmaia@gmail.com> | 2015-02-10 19:56:57 +0000 |
---|---|---|
committer | Patrick Maia <patrickjourdanmaia@gmail.com> | 2015-02-10 19:57:28 +0000 |
commit | dcec274dd5d727f113bbc64a95e9fc0773829ce3 (patch) | |
tree | 26f1df7e101c100f68bb8b51c23b14145ebac3ad | |
parent | f27a5ce3a56cb3e70adcaf21ad97d79e8c26330b (diff) |
Issue #276 - uses the old casing when an existing tag with different casing is posted
-rw-r--r-- | service/pixelated/adapter/services/mail_service.py | 10 | ||||
-rw-r--r-- | service/test/integration/test_tags.py | 17 |
2 files changed, 27 insertions, 0 deletions
diff --git a/service/pixelated/adapter/services/mail_service.py b/service/pixelated/adapter/services/mail_service.py index 40a7c6ff..5ef0a188 100644 --- a/service/pixelated/adapter/services/mail_service.py +++ b/service/pixelated/adapter/services/mail_service.py @@ -39,6 +39,7 @@ class MailService: reserved_words = self.tag_service.extract_reserved(new_tags) if len(reserved_words): raise ValueError('None of the following words can be used as tags: ' + ' '.join(reserved_words)) + new_tags = self._favor_existing_tags_casing(new_tags) mail = self.mail(mail_id) mail.update_tags(set(new_tags)) self.search_engine.index_mail(mail) @@ -48,6 +49,15 @@ class MailService: def _filter_white_space_tags(self, tags): return filter(bool, map(lambda e: e.strip(), tags)) + def _favor_existing_tags_casing(self, new_tags): + current_tags = map(lambda tag: tag['name'], self.search_engine.tags(query='', skip_default_tags=True)) + current_tags_lower = map(lambda tag: tag.lower(), current_tags) + + def _use_current_casing(new_tag_lower): + return current_tags[current_tags_lower.index(new_tag_lower)] + + return map(lambda new_tag: _use_current_casing(new_tag.lower()) if new_tag.lower() in current_tags_lower else new_tag, new_tags) + def mail(self, mail_id): return self.querier.mail(mail_id) diff --git a/service/test/integration/test_tags.py b/service/test/integration/test_tags.py index 41aeeeeb..ad723067 100644 --- a/service/test/integration/test_tags.py +++ b/service/test/integration/test_tags.py @@ -36,6 +36,23 @@ class TagsTest(SoledadTestBase): mails = self.get_mails_by_tag('IMPORTANT') self.assertEquals('Mail with tags', mails[0].subject) + def test_use_old_casing_when_same_tag_with_different_casing_is_posted(self): + mail = MailBuilder().with_subject('Mail with tags').build_input_mail() + self.client.add_mail_to_inbox(mail) + self.post_tags(mail.ident, self._tags_json(['ImPoRtAnT'])) + mails = self.get_mails_by_tag('ImPoRtAnT') + self.assertEquals({'ImPoRtAnT'}, set(mails[0].tags)) + + another_mail = MailBuilder().with_subject('Mail with tags').build_input_mail() + self.client.add_mail_to_inbox(another_mail) + self.post_tags(another_mail.ident, self._tags_json(['IMPORTANT'])) + mails = self.get_mails_by_tag('IMPORTANT') + self.assertEquals(0, len(mails)) + mails = self.get_mails_by_tag('ImPoRtAnT') + self.assertEquals(2, len(mails)) + self.assertEquals({'ImPoRtAnT'}, set(mails[0].tags)) + self.assertEquals({'ImPoRtAnT'}, set(mails[1].tags)) + def test_tags_are_case_sensitive(self): mail = MailBuilder().with_subject('Mail with tags').build_input_mail() self.client.add_mail_to_inbox(mail) |