Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
write 'sync status' doc and send welcome mail
--HG-- extra : rebase_source : 7e792689ca89fb10106680d89c99c50f9e160c19
- Loading branch information
Showing
10 changed files
with
115 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"schemas" : { | ||
"rd.ext.workqueue" : { | ||
"source_schemas" : ["rd.core.sync-status"], | ||
"code" : "RDFILE: *.py", | ||
"content_type" : "application/x-python", | ||
"info": "Sends a 'welcome' email after the first sync completes" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
def handler(doc): | ||
if doc['num_syncs'] != 1: | ||
return | ||
|
||
key = ['rd.account', 'proto', 'smtp'] | ||
result = open_view(key=key, reduce=False, include_docs=True) | ||
rows = result['rows'] | ||
if not rows: | ||
logger.warn("can't find an smtp account from which to send welcome email") | ||
return | ||
acct = rows[0]['doc'] | ||
|
||
# write a simple outgoing schema | ||
addy = acct['username'] | ||
body = 'no really - welcome! Raindrop just synchronized %d of your messages' % doc['new_items'] | ||
item = {'body' : body, | ||
'from' : ['email', addy], | ||
'from_display': 'raindrop', | ||
'to' : [ | ||
['email', addy], | ||
], | ||
'to_display' : ['you'], | ||
'subject': "Welcome to raindrop", | ||
# The 'state' bit... | ||
'sent_state': None, | ||
'outgoing_state': 'outgoing', | ||
} | ||
emit_schema('rd.msg.outgoing.simple', item) | ||
logger.info("queueing welcome mail to '%s'", addy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from twisted.internet import defer | ||
|
||
from raindrop.tests import TestCaseWithTestDB, FakeOptions | ||
from raindrop.model import get_doc_model | ||
from raindrop.proto import test as test_proto | ||
|
||
import logging | ||
logger = logging.getLogger(__name__) | ||
|
||
class TestSyncing(TestCaseWithTestDB): | ||
def make_config(self): | ||
config = TestCaseWithTestDB.make_config(self) | ||
# now add our smtp account | ||
acct = config.accounts['test_smtp'] = {} | ||
acct['proto'] = 'smtp' | ||
acct['username'] = 'test_raindrop@test.mozillamessaging.com' | ||
acct['id'] = 'smtp_test' | ||
acct['ssl'] = False | ||
return config | ||
|
||
@defer.inlineCallbacks | ||
def test_sync_state_doc(self, expected_num_syncs=1): | ||
_ = yield self.deferMakeAnotherTestMessage(None) | ||
_ = yield self.ensure_pipeline_complete() | ||
# open the document with the sync state. | ||
wanted = ["raindrop", "sync-status"], 'rd.core.sync-status' | ||
si = (yield self.doc_model.open_schemas([wanted]))[0] | ||
self.failUnless(si) | ||
self.failUnlessEqual(si.get('new_items'), 1) | ||
self.failUnlessEqual(si.get('num_syncs'), expected_num_syncs) | ||
|
||
@defer.inlineCallbacks | ||
def test_sync_state_doc_twice(self): | ||
# make sure it works twice with the same conductor instance/db | ||
_ = yield self.test_sync_state_doc() | ||
_ = yield self.test_sync_state_doc(2) |