diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2014-10-09 10:49:40 +0200 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2014-10-09 10:49:40 +0200 |
commit | ba8024b667a4ca16305e3b8c6fe566ba328a488d (patch) | |
tree | 508cf331572ddfd75d3e4c40808a031e492c99e4 /service | |
parent | c77b5aeb93fb61c2ec67d89f7a1266418fff5a9a (diff) |
Skip default tags for tag suggestions.
- Fixup for issue #52
Diffstat (limited to 'service')
-rw-r--r-- | service/integration/drafts_test.py | 2 | ||||
-rw-r--r-- | service/pixelated/adapter/tag_service.py | 3 | ||||
-rw-r--r-- | service/pixelated/user_agent.py | 9 | ||||
-rw-r--r-- | service/test/user_agent_test.py | 26 |
4 files changed, 29 insertions, 11 deletions
diff --git a/service/integration/drafts_test.py b/service/integration/drafts_test.py index 749b1ad3..64581768 100644 --- a/service/integration/drafts_test.py +++ b/service/integration/drafts_test.py @@ -60,5 +60,3 @@ class DraftsTest(unittest.TestCase, SoledadTestBase): self.assertEquals(1, len(drafts)) self.assertEquals('First draft edited', drafts[0].subject) - - diff --git a/service/pixelated/adapter/tag_service.py b/service/pixelated/adapter/tag_service.py index 874a9a58..f128f1bb 100644 --- a/service/pixelated/adapter/tag_service.py +++ b/service/pixelated/adapter/tag_service.py @@ -59,3 +59,6 @@ class TagService: def all_tags(self): return self.tag_index.values().union(self.SPECIAL_TAGS) + + def all_custom_tags(self): + return self.tag_index.values().difference(self.SPECIAL_TAGS) diff --git a/service/pixelated/user_agent.py b/service/pixelated/user_agent.py index 12b9a97a..03372f23 100644 --- a/service/pixelated/user_agent.py +++ b/service/pixelated/user_agent.py @@ -124,12 +124,17 @@ def delete_mails(): @app.route('/tags') def tags(): + tag_service = mail_service.tag_service + query = request.args.get('q') + skipDefaultTags = request.args.get('skipDefaultTags') + + all_tags = tag_service.all_custom_tags() if skipDefaultTags else tag_service.all_tags() if query: - tags = [tag for tag in mail_service.all_tags() if bool(re.match(query, tag.name, re.IGNORECASE))] + tags = [tag for tag in all_tags if bool(re.match(query, tag.name, re.IGNORECASE))] else: - tags = mail_service.all_tags() + tags = all_tags return respond_json([tag.as_dict() for tag in tags]) diff --git a/service/test/user_agent_test.py b/service/test/user_agent_test.py index d21f1733..be4d9354 100644 --- a/service/test/user_agent_test.py +++ b/service/test/user_agent_test.py @@ -35,6 +35,8 @@ class UserAgentTest(unittest.TestCase): def setUp(self): self.app = pixelated.user_agent.app.test_client() self.mail_service = mock() + self.tag_service = mock() + self.mail_service.tag_service = self.tag_service pixelated.user_agent.DISABLED_FEATURES = [] pixelated.user_agent.mail_service = self.mail_service @@ -61,11 +63,11 @@ class UserAgentTest(unittest.TestCase): def test_sending_mail_return_sent_mail_data_when_send_succeeds(self): self.input_mail = self.draft() self.input_mail.as_dict = lambda: {'header': {'from': 'a@a.a', 'to': 'b@b.b'}, - 'ident': 1, - 'tags': [], - 'status': [], - 'security_casing': {}, - 'body': 'email body'} + 'ident': 1, + 'tags': [], + 'status': [], + 'security_casing': {}, + 'body': 'email body'} result = self.app.post('/mails', data='{"ident":1}', content_type="application/json") @@ -128,7 +130,7 @@ class UserAgentTest(unittest.TestCase): pixelated.user_agent.app.config = orig_config def test_that_tags_returns_all_tags(self): - when(self.mail_service).all_tags().thenReturn(TagService.SPECIAL_TAGS) + when(self.tag_service).all_tags().thenReturn(TagService.SPECIAL_TAGS) response = self.app.get('/tags') @@ -137,10 +139,20 @@ class UserAgentTest(unittest.TestCase): self.assertEqual(expected, response.data) def test_that_tags_are_filtered_by_query(self): - when(self.mail_service).all_tags().thenReturn(TagService.SPECIAL_TAGS) + when(self.tag_service).all_tags().thenReturn(TagService.SPECIAL_TAGS) response = self.app.get('/tags?q=dr') self.assertEqual(200, response.status_code) expected = json.dumps([Tag('drafts', True).as_dict()]) self.assertEqual(expected, response.data) + + def test_that_default_tags_are_ignorable(self): + when(self.tag_service).all_tags().thenReturn(TagService.SPECIAL_TAGS) + when(self.tag_service).all_custom_tags().thenReturn([Tag('test')]) + + response = self.app.get('/tags?skipDefaultTags=true') + + self.assertEqual(200, response.status_code) + expected = json.dumps([Tag('test').as_dict()]) + self.assertEqual(expected, response.data) |