summaryrefslogtreecommitdiff
path: root/service/test/unit
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2014-10-13 19:29:36 +0200
committerDuda Dornelles <ddornell@thoughtworks.com>2014-10-14 17:48:27 +0200
commitcd4dffcfcb3f7473913e2b50571a182689efeedc (patch)
treedb8ff0748e5a63efcb3d8d82a7b8cc774376d86a /service/test/unit
parent451218929536b59d3e0a72a9c651a1911e1bd1cd (diff)
No more tag_index - now whoosh does everythin
Diffstat (limited to 'service/test/unit')
-rw-r--r--service/test/unit/adapter/pixelated_mail_test.py13
-rw-r--r--service/test/unit/adapter/pixelated_mailbox_test.py2
-rw-r--r--service/test/unit/adapter/tag_index_test.py88
-rw-r--r--service/test/unit/adapter/test_tag_service.py60
-rw-r--r--service/test/unit/user_agent_test.py28
5 files changed, 1 insertions, 190 deletions
diff --git a/service/test/unit/adapter/pixelated_mail_test.py b/service/test/unit/adapter/pixelated_mail_test.py
index 0ab09a0a..904f621d 100644
--- a/service/test/unit/adapter/pixelated_mail_test.py
+++ b/service/test/unit/adapter/pixelated_mail_test.py
@@ -18,8 +18,6 @@ import unittest
import os
import pixelated.support.date
from pixelated.adapter.pixelated_mail import PixelatedMail, InputMail
-from pixelated.adapter.tag_service import TagService
-from pixelated.adapter.tag_index import TagIndex
from pixelated.adapter.tag import Tag
from mockito import *
from test.support import test_helper
@@ -72,17 +70,6 @@ class TestPixelatedMail(unittest.TestCase):
self.assertEquals(mail.fdoc.content['flags'], [])
- def test_update_tags_notifies_tag_service(self):
- db_path = '/tmp/test_update_tags_notifies_tag_service'
- TagService.instance = TagService(TagIndex(db_path))
-
- mail = PixelatedMail.from_soledad(*test_helper.leap_mail(), soledad_querier=self.querier)
-
- mail.update_tags({'new_tag'})
- self.assertIn(Tag('new_tag'), mail.tag_service.all_tags())
-
- os.remove(db_path + '.db')
-
class InputMailTest(unittest.TestCase):
mail_dict = lambda x: {
diff --git a/service/test/unit/adapter/pixelated_mailbox_test.py b/service/test/unit/adapter/pixelated_mailbox_test.py
index d38cef5c..060bbc43 100644
--- a/service/test/unit/adapter/pixelated_mailbox_test.py
+++ b/service/test/unit/adapter/pixelated_mailbox_test.py
@@ -25,7 +25,7 @@ class PixelatedMailboxTest(unittest.TestCase):
def setUp(self):
self.tag_service = mock()
self.querier = mock()
- self.mailbox = PixelatedMailbox('INBOX', self.querier, tag_service=self.tag_service)
+ self.mailbox = PixelatedMailbox('INBOX', self.querier)
def test_remove_message_from_mailbox(self):
mail = PixelatedMail.from_soledad(*test_helper.leap_mail(), soledad_querier=self.querier)
diff --git a/service/test/unit/adapter/tag_index_test.py b/service/test/unit/adapter/tag_index_test.py
deleted file mode 100644
index 21564fc5..00000000
--- a/service/test/unit/adapter/tag_index_test.py
+++ /dev/null
@@ -1,88 +0,0 @@
-
-#
-# Copyright (c) 2014 ThoughtWorks, Inc.
-#
-# Pixelated is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Pixelated is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
-import unittest
-import os
-import uuid
-
-from pixelated.adapter.tag_index import TagIndex
-from pixelated.adapter.tag import Tag
-
-
-class TestTagIndex(unittest.TestCase):
-
- def setUp(self):
- self.db_path = '/tmp/test_tag_index_' + str(uuid.uuid4())
- self.tag_index = TagIndex(self.db_path)
-
- def tearDown(self):
- self.tag_index._close_db()
- os.remove(self.db_path + '.db')
-
- def test_get_and_set_works(self):
- tag = Tag('a_tag')
- self.tag_index.set(tag)
- self.assertEquals(tag, self.tag_index.get('a_tag'))
-
- def test_values_returns_all_values_in_the_index(self):
- tag_a = Tag('tag_a')
- self.tag_index.set(tag_a)
- tag_b = Tag('tag_b')
- self.tag_index.set(tag_b)
- tag_c = Tag('tag_c')
- self.tag_index.set(tag_c)
-
- self.assertEquals(set([tag_a, tag_b, tag_c]), self.tag_index.values())
-
- def test_changes_are_visible_between_instances_using_same_file(self):
- tag = Tag('some_tag')
- self.tag_index.set(tag)
-
- other_tag_index = TagIndex(self.db_path)
- self.assertIn(tag, other_tag_index.values())
-
- def test_add_does_not_replace_existent_tag_with_same_name(self):
- tag = Tag('tag', True)
- self.tag_index.set(tag)
-
- same_name_tag = Tag('tag', False)
- self.tag_index.add(same_name_tag)
-
- self.assertEquals(True, self.tag_index.get('tag').default)
-
- def test_empty_returns_true_if_there_are_no_values(self):
- self.assertTrue(self.tag_index.empty())
-
- def test_empty_returns_false_if_there_are_values(self):
- self.tag_index.set(Tag('tag'))
- self.assertFalse(self.tag_index.empty())
-
- def test_remove_deletes_the_tag_with_the_given_key_from_the_index(self):
- self.tag_index.set(Tag('tag'))
- self.tag_index.remove('tag')
- self.assertEquals(None, self.tag_index.get('tag'))
-
- def test_remove_does_not_raises_exception_if_key_is_not_present(self):
- self.tag_index.remove('not_there')
-
- def test_removals_are_visible_between_instances_using_same_file(self):
- tag = Tag('some_tag')
- self.tag_index.set(tag)
-
- other_tag_index = TagIndex(self.db_path)
- other_tag_index.remove('some_tag')
-
- self.assertIsNone(self.tag_index.get('some_tag'))
diff --git a/service/test/unit/adapter/test_tag_service.py b/service/test/unit/adapter/test_tag_service.py
deleted file mode 100644
index aeb1b503..00000000
--- a/service/test/unit/adapter/test_tag_service.py
+++ /dev/null
@@ -1,60 +0,0 @@
-#
-# Copyright (c) 2014 ThoughtWorks, Inc.
-#
-# Pixelated is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Pixelated is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
-
-import unittest
-import tempfile
-
-from pixelated.adapter.tag import Tag
-from pixelated.adapter.pixelated_mail import PixelatedMail
-from pixelated.adapter.tag_index import TagIndex
-from pixelated.adapter.tag_service import TagService
-from test.support import test_helper
-
-
-class TagServiceTest(unittest.TestCase):
- def setUp(self):
- self.index_file_handler, self.index_file_path = tempfile.mkstemp()
- self.tag_index = TagIndex(self.index_file_path)
- self.tag_service = TagService(tag_index=self.tag_index)
-
- def test_index_is_initialized_with_mail_tags_if_empty(self):
- mail_one = PixelatedMail.from_soledad(*test_helper.leap_mail(uid=0, extra_headers={'X-Tags': '["tag_1"]'}))
- mail_two = PixelatedMail.from_soledad(*test_helper.leap_mail(uid=1, extra_headers={'X-Tags': '["tag_2"]'}))
- mails = [mail_one, mail_two]
-
- self.tag_service.load_index(mails)
-
- self.assertEqual(self.tag_service.all_tags(), {Tag('sent'), Tag('inbox'), Tag('drafts'), Tag('trash'), Tag('tag_1'), Tag('tag_2')})
-
- def test_special_tags_always_exists(self):
- self.tag_service.load_index([])
-
- self.assertEqual(self.tag_service.all_tags(), {Tag('sent'), Tag('inbox'), Tag('drafts'), Tag('trash')})
-
- def test_notify_tags_updated_method_properly_changes_tags_state(self):
- mail_ident = 12
- tag = Tag('one_tag')
- tag.increment(mail_ident)
- self.tag_service.load_index([])
- self.tag_service.tag_index.set(tag)
-
- self.assertEquals(0, self.tag_service.tag_index.get('inbox').total)
- self.assertEquals(1, self.tag_service.tag_index.get('one_tag').total)
-
- self.tag_service.notify_tags_updated({'inbox'}, {'one_tag'}, mail_ident)
-
- self.assertEquals(1, self.tag_service.tag_index.get('inbox').total)
- self.assertIsNone(self.tag_service.tag_index.get('one_tag'))
diff --git a/service/test/unit/user_agent_test.py b/service/test/unit/user_agent_test.py
index afc42bdd..ea695b26 100644
--- a/service/test/unit/user_agent_test.py
+++ b/service/test/unit/user_agent_test.py
@@ -106,31 +106,3 @@ class UserAgentTest(unittest.TestCase):
verify(pixelated.user_agent.app.config).from_pyfile('/tmp/some/config/file')
finally:
pixelated.user_agent.app.config = orig_config
-
- def test_that_tags_returns_all_tags(self):
- when(self.tag_service).all_tags().thenReturn(TagService.SPECIAL_TAGS)
-
- response = self.app.get('/tags')
-
- self.assertEqual(200, response.status_code)
- expected = json.dumps([tag.as_dict() for tag in TagService.SPECIAL_TAGS])
- self.assertEqual(expected, response.data)
-
- def test_that_tags_are_filtered_by_query(self):
- 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)