From ff01686c1b38d26b0ef54833cf3463ab0bf73bf8 Mon Sep 17 00:00:00 2001 From: Patrick Maia and Victor Shyba Date: Sun, 7 Sep 2014 16:55:57 +0000 Subject: #51 - some tests for TagIndex and the addition of method TagIndex.add --- service/test/adapter/tag_index_test.py | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 service/test/adapter/tag_index_test.py (limited to 'service/test') diff --git a/service/test/adapter/tag_index_test.py b/service/test/adapter/tag_index_test.py new file mode 100644 index 00000000..05f7ce55 --- /dev/null +++ b/service/test/adapter/tag_index_test.py @@ -0,0 +1,63 @@ + +# +# 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 . +import unittest +import os + +from pixelated.adapter.tag_index import TagIndex +from pixelated.adapter.tag import Tag + + +class TestTagIndex(unittest.TestCase): + + def setUp(self): + self.db_path = '/tmp/database_test_tag_index' + 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) -- cgit v1.2.3