summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorBruno Wagner Goncalves <bwagner@thoughtworks.com>2014-08-12 17:03:19 -0300
committerBruno Wagner Goncalves <bwagner@thoughtworks.com>2014-08-12 17:03:19 -0300
commit27e07e05d97b577ef6b62b74ca7daebafd41db98 (patch)
tree9c8031d91977dd1ce2af72b4a146e5c0b29d6ae8 /service
parentcce7b837e4180167d426224ef625e12a8abc4994 (diff)
Basic tags implementation
Diffstat (limited to 'service')
-rw-r--r--service/app/adapter/mail_service.py3
-rw-r--r--service/app/pixelated_user_agent.py13
-rw-r--r--service/app/tags.py40
-rw-r--r--service/test/test_tags.py11
4 files changed, 52 insertions, 15 deletions
diff --git a/service/app/adapter/mail_service.py b/service/app/adapter/mail_service.py
index a08b73f9..25fb5188 100644
--- a/service/app/adapter/mail_service.py
+++ b/service/app/adapter/mail_service.py
@@ -24,6 +24,7 @@ console.setFormatter(formatter)
# add the handler to the root logger
logging.getLogger('').addHandler(console)
+
class MailService:
SPECIAL_BOXES = ['inbox', 'sent', 'drafts', 'trash']
@@ -114,4 +115,4 @@ class MailService:
if __name__ == '__main__':
print('Running Standalone')
- client = Client() \ No newline at end of file
+ client = Client()
diff --git a/service/app/pixelated_user_agent.py b/service/app/pixelated_user_agent.py
index 4286bb34..f5bc9a3a 100644
--- a/service/app/pixelated_user_agent.py
+++ b/service/app/pixelated_user_agent.py
@@ -6,6 +6,8 @@ from flask import Flask, request, Response
import app.search_query as search_query
from app.adapter.mail_service import MailService
from app.adapter.mail_converter import MailConverter
+from app.tags import Tag
+from app.tags import Tags
app = Flask(__name__, static_url_path='', static_folder='../../web-ui/app')
@@ -23,13 +25,13 @@ def respond_json(entity):
response = json.dumps(entity)
return Response(response=response, mimetype="application/json")
+
@app.route('/disabled_features')
def disabled_features():
return respond_json([
'saveDraft',
'createNewTag',
'replySection',
- 'tags',
'signatureStatus',
'encryptionStatus',
'contacts'
@@ -84,8 +86,8 @@ def delete_mails(mail_id):
@app.route('/tags')
def tags():
- #tags = map(lambda x: converter.from_tag(x), mail_service.all_tags())
- return respond_json(['inbox'])
+ tags = Tags()
+ return respond_json(tags.as_dict())
@app.route('/mail/<mail_id>')
@@ -128,7 +130,7 @@ def index():
def setup():
- start_reactor()
+ # start_reactor()
app.config.from_envvar('PIXELATED_UA_CFG')
account = app.config['ACCOUNT']
app.run(host=app.config['HOST'], debug=app.config['DEBUG'], port=app.config['PORT'])
@@ -138,11 +140,14 @@ from twisted.internet import reactor
import signal
import sys
+
+
def signal_handler(signal, frame):
stop_reactor_on_exit()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
+
def start_reactor():
def start_reactor_run():
reactor.run(False)
diff --git a/service/app/tags.py b/service/app/tags.py
index 39709a4c..78d594dd 100644
--- a/service/app/tags.py
+++ b/service/app/tags.py
@@ -1,7 +1,12 @@
+import json
+
+
class Tag:
- def __init__(self, name):
+ def __init__(self, name, default):
self.name = name
+ self.default = default
+ self.ident = name.__hash__()
def __eq__(self, other):
return self.name == other.name
@@ -9,24 +14,45 @@ class Tag:
def __hash__(self):
return self.name.__hash__()
+ def as_dict(self):
+ return {
+ 'name': self.name,
+ 'default': self.default,
+ 'ident': self.ident,
+ 'counts': {
+ 'total': 0,
+ 'read': 0,
+ 'starred': 0,
+ 'replied': 0
+ }
+ }
+
class Tags:
SPECIAL_TAGS = ['inbox', 'sent', 'drafts', 'trash']
def __init__(self):
- self.tags = set([Tag(name) for name in self.SPECIAL_TAGS])
+ self.tags = {}
+ self.create_default_tags()
+
+ def create_default_tags(self):
+ for name in self.SPECIAL_TAGS:
+ self.tags[name] = self.add(name)
def add(self, name):
- self.tags.add(Tag(name))
+ tag = Tag(name, name in self.SPECIAL_TAGS)
+ self.tags[name] = tag
+ return tag
def find(self, name):
- for tag in self.tags:
- if tag.name == name:
- return tag
+ return self.tags[name]
def __len__(self):
return len(self.tags)
def __iter__(self):
- return self.tags.__iter__() \ No newline at end of file
+ return self.tags.itervalues()
+
+ def as_dict(self):
+ return [tag.as_dict() for tag in self.tags.values()]
diff --git a/service/test/test_tags.py b/service/test/test_tags.py
index 5e0ea426..9c57ee07 100644
--- a/service/test/test_tags.py
+++ b/service/test/test_tags.py
@@ -5,9 +5,10 @@ from app.tags import Tags, Tag
class TagTestCase(unittest.TestCase):
def test_create_tag(self):
- tag = Tag('test')
+ tag = Tag('test', True)
self.assertEqual(tag.name, 'test')
+
class TagsTestCase(unittest.TestCase):
def test_add_tag_to_collection(self):
@@ -28,10 +29,14 @@ class TagsTestCase(unittest.TestCase):
tag_collection = Tags()
tag_collection.add('test')
tag_collection.add('test2')
- self.assertEqual(tag_collection.find('test'), Tag('test'))
+ self.assertEqual(tag_collection.find('test'), Tag('test', True))
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
+ self.assertIn(Tag(tag, True), tag_collection)
+
+ def test_special_tags_are_default(self):
+ tags = Tags()
+ self.assertTrue(tags.find('inbox').default)