summaryrefslogtreecommitdiff
path: root/py-fake-service/app/adapter/tagsset.py
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2014-08-12 20:29:33 -0300
committerDuda Dornelles <ddornell@thoughtworks.com>2014-08-12 20:31:37 -0300
commit9779abfb1b1d0513e5efbc2737395bba0e8b6235 (patch)
treee6b093174b098a66cf89f1f88cab876a8221071c /py-fake-service/app/adapter/tagsset.py
parentb5686e01012b5fd1b544ca16efd3cb73f8620a1c (diff)
creating new tag if tag doesnt exist in py-fake-service
Diffstat (limited to 'py-fake-service/app/adapter/tagsset.py')
-rw-r--r--py-fake-service/app/adapter/tagsset.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/py-fake-service/app/adapter/tagsset.py b/py-fake-service/app/adapter/tagsset.py
index abe7ef7e..803c921c 100644
--- a/py-fake-service/app/adapter/tagsset.py
+++ b/py-fake-service/app/adapter/tagsset.py
@@ -8,9 +8,8 @@ class TagsSet:
def add(self, mbox_mail):
tags = mbox_mail.get('X-TW-Pixelated-Tags').split(', ')
for tag in tags:
- tag = self.tags.setdefault(tag, Tag(tag, self.ident))
+ tag = self._create_new_tag(tag)
tag.increment_count()
- self.ident += 1
def all_tags(self):
return self.tags.values()
@@ -20,9 +19,19 @@ class TagsSet:
tag = self.tags.get(tag)
tag.increment_read()
- def increment_tag_total_count(self, tag):
- self.tags.get(tag).increment_count()
+ def increment_tag_total_count(self, tagname):
+ tag = self.tags.get(tagname)
+ if tag:
+ tag.increment_count()
+ else:
+ self._create_new_tag(tagname)
def decrement_tag_total_count(self, tag):
self.tags.get(tag).decrement_count()
+ def _create_new_tag(self, tag):
+ tag = self.tags.setdefault(tag, Tag(tag, self.ident))
+ self.ident += 1
+ return tag
+
+