summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2014-08-11 17:24:36 -0300
committerVictor Shyba <victor.shyba@gmail.com>2014-08-11 17:24:36 -0300
commit582ef39f46f88e43704df871470dfe7218cb3aa8 (patch)
tree57ac8921db1e8b3a378363a75f07130dbc3e71b1 /service
parent690975d4bcc80a14cf85649cb8db163424b93cf2 (diff)
first implementation of tags
Diffstat (limited to 'service')
-rw-r--r--service/app/tags.py32
-rw-r--r--service/test/test_tags.py37
2 files changed, 69 insertions, 0 deletions
diff --git a/service/app/tags.py b/service/app/tags.py
new file mode 100644
index 00000000..39709a4c
--- /dev/null
+++ b/service/app/tags.py
@@ -0,0 +1,32 @@
+class Tag:
+
+ def __init__(self, name):
+ self.name = name
+
+ def __eq__(self, other):
+ return self.name == other.name
+
+ def __hash__(self):
+ return self.name.__hash__()
+
+
+class Tags:
+
+ SPECIAL_TAGS = ['inbox', 'sent', 'drafts', 'trash']
+
+ def __init__(self):
+ self.tags = set([Tag(name) for name in self.SPECIAL_TAGS])
+
+ def add(self, name):
+ self.tags.add(Tag(name))
+
+ def find(self, name):
+ for tag in self.tags:
+ if tag.name == name:
+ return tag
+
+ def __len__(self):
+ return len(self.tags)
+
+ def __iter__(self):
+ return self.tags.__iter__() \ No newline at end of file
diff --git a/service/test/test_tags.py b/service/test/test_tags.py
new file mode 100644
index 00000000..5e0ea426
--- /dev/null
+++ b/service/test/test_tags.py
@@ -0,0 +1,37 @@
+import unittest
+from app.tags import Tags, Tag
+
+
+class TagTestCase(unittest.TestCase):
+
+ def test_create_tag(self):
+ tag = Tag('test')
+ self.assertEqual(tag.name, 'test')
+
+class TagsTestCase(unittest.TestCase):
+
+ def test_add_tag_to_collection(self):
+ tag_collection = Tags()
+ tag_collection.add('test')
+ self.assertEqual(len(tag_collection), len(Tags())+1)
+ tag_collection.add('test2')
+ self.assertEqual(len(tag_collection), len(Tags())+2)
+
+ def test_no_tag_duplication(self):
+ tag_collection = Tags()
+ tag_collection.add('test')
+ self.assertEqual(len(tag_collection), len(Tags())+1)
+ tag_collection.add('test')
+ self.assertEqual(len(tag_collection), len(Tags())+1)
+
+ def test_find_tag_on_collection(self):
+ tag_collection = Tags()
+ tag_collection.add('test')
+ tag_collection.add('test2')
+ self.assertEqual(tag_collection.find('test'), Tag('test'))
+
+ def test_special_tags_always_exist(self):
+ special_tags = ['inbox', 'sent', 'drafts', 'trash']
+ tag_collection = Tags()
+ for tag in special_tags:
+ self.assertIn(Tag(tag), tag_collection) \ No newline at end of file