本文整理汇总了Python中pixelated.adapter.search.SearchEngine.index_mails方法的典型用法代码示例。如果您正苦于以下问题:Python SearchEngine.index_mails方法的具体用法?Python SearchEngine.index_mails怎么用?Python SearchEngine.index_mails使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pixelated.adapter.search.SearchEngine
的用法示例。
在下文中一共展示了SearchEngine.index_mails方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mails [as 别名]
class SoledadTestBase:
def __init__(self):
pass
def teardown_soledad(self):
pass
def setup_soledad(self):
self.soledad = initialize_soledad(tempdir=soledad_test_folder)
self.mail_address = "[email protected]"
# setup app
PixelatedMail.from_email_address = self.mail_address
SearchEngine.INDEX_FOLDER = soledad_test_folder + '/search_index'
self.app = pixelated.runserver.app
self.soledad_querier = SoledadQuerier(self.soledad)
self.account = SoledadBackedAccount('test', self.soledad, MagicMock())
self.mailboxes = Mailboxes(self.account, self.soledad_querier)
self.mail_sender = mock()
self.tag_service = TagService()
self.draft_service = DraftService(self.mailboxes)
self.mail_service = MailService(self.mailboxes, self.mail_sender, self.tag_service,
self.soledad_querier)
self.search_engine = SearchEngine(self.soledad_querier)
self.search_engine.index_mails(self.mail_service.all_mails())
features_controller = FeaturesController()
features_controller.DISABLED_FEATURES.append('autoReload')
home_controller = HomeController()
mails_controller = MailsController(mail_service=self.mail_service,
draft_service=self.draft_service,
search_engine=self.search_engine)
tags_controller = TagsController(search_engine=self.search_engine)
sync_info_controller = SyncInfoController()
attachments_controller = AttachmentsController(self.soledad_querier)
app_factory._setup_routes(self.app, home_controller, mails_controller, tags_controller,
features_controller, sync_info_controller, attachments_controller)
self.resource = KleinResource(self.app)
def get_mails_by_tag(self, tag, page=1, window=100):
request = requestMock(path="/mails")
request.args = {
'q': ['tag:%s' % tag],
'w': [str(window)],
'p': [str(page)]
}
_render(self.resource, request)
response = json.loads(request.getWrittenData())
return [ResponseMail(m) for m in response['mails']]
def post_mail(self, data):
request = requestMock(path='/mails', method="POST", body=data, headers={'Content-Type': ['application/json']})
_render(self.resource, request)
response = json.loads(request.getWrittenData())
return ResponseMail(response)
def get_attachment(self, ident, encoding):
request = requestMock(path='/attachment/' + ident)
request.args = {
'encoding': [encoding]
}
_render(self.resource, request)
return request.getWrittenData()
def put_mail(self, data):
request = requestMock('/mails', method="PUT", body=data, headers={'Content-Type': ['application/json']})
_render(self.resource, request)
response = json.loads(request.getWrittenData())
return response['ident']
def post_tags(self, mail_ident, tags_json):
request = requestMock('/mail/' + mail_ident + '/tags', method="POST", body=tags_json,
headers={'Content-Type': ['application/json']})
_render(self.resource, request)
return json.loads(request.getWrittenData())
def get_tags(self, **kwargs):
request = requestMock('/tags')
request.args = kwargs
_render(self.resource, request)
return json.loads(request.getWrittenData())
def delete_mail(self, mail_ident):
request = requestMock(path='/mail/' + mail_ident, method="DELETE")
_render(self.resource, request)
return request
def mark_as_read(self, mail_ident):
request = requestMock('/mail/' + mail_ident + '/read', method="POST", headers={'Content-Type': ['application/json']})
_render(self.resource, request)
return request
def mark_as_unread(self, mail_ident):
request = requestMock('/mail/' + mail_ident + '/unread', method="POST", headers={'Content-Type': ['application/json']})
_render(self.resource, request)
#.........这里部分代码省略.........
示例2: teardown_soledad
# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mails [as 别名]
class SoledadTestBase:
def teardown_soledad(self):
self.soledad.close()
shutil.rmtree(soledad_test_folder)
def setup_soledad(self):
unstub() # making sure all mocks from other tests are reset
# making sure soledad test folder is not there
if (os.path.isdir(soledad_test_folder)):
shutil.rmtree(soledad_test_folder)
self.soledad = initialize_soledad(tempdir=soledad_test_folder)
self.mail_address = "[email protected]"
# resetting soledad querier
SoledadQuerier.reset()
SoledadQuerier.get_instance(soledad=self.soledad)
# setup app
PixelatedMail.from_email_address = self.mail_address
self.app = pixelated.user_agent.app.test_client()
self.account = FakeAccount()
self.pixelated_mailboxes = PixelatedMailBoxes(self.account)
self.mail_sender = mock()
self.tag_index = TagIndex(os.path.join(soledad_test_folder, 'tag_index'))
self.tag_service = TagService(self.tag_index)
self.draft_service = DraftService(self.pixelated_mailboxes)
self.mail_service = MailService(self.pixelated_mailboxes, self.mail_sender, self.tag_service)
SearchEngine.INDEX_FOLDER = soledad_test_folder + '/search_index'
self.search_engine = SearchEngine()
self.search_engine.index_mails(self.mail_service.all_mails())
pixelated.user_agent.mail_service = self.mail_service
pixelated.user_agent.draft_service = self.draft_service
pixelated.user_agent.tag_service = self.tag_service
pixelated.user_agent.search_engine = self.search_engine
def get_mails_by_tag(self, tag):
response = json.loads(self.app.get("/mails?q=tag:" + tag).data)
return [ResponseMail(m) for m in response['mails']]
def post_mail(self, data):
response = json.loads(self.app.post('/mails', data=data, content_type="application/json").data)
return ResponseMail(response)
def put_mail(self, data):
response = json.loads(self.app.put('/mails', data=data, content_type="application/json").data)
return response['ident']
def post_tags(self, mail_ident, tags_json):
return json.loads(
self.app.post('/mail/' + mail_ident + '/tags', data=tags_json, content_type="application/json").data)
def delete_mail(self, mail_ident):
self.app.delete('/mail/' + mail_ident)
def mark_as_read(self, mail_ident):
self.app.post('/mail/' + mail_ident + '/read', content_type="application/json")
def add_mail_to_inbox(self, input_mail):
mail = self.pixelated_mailboxes.inbox().add(input_mail)
self.search_engine.index_mail(mail)
示例3: AppTestAccount
# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mails [as 别名]
class AppTestAccount(object):
INDEX_KEY = (
"\xde3?\x87\xff\xd9\xd3\x14\xf0\xa7>\x1f%C{\x16.\\\xae\x8c\x13\xa7\xfb\x04\xd4]+\x8d_\xed\xd1\x8d\x0bI"
"\x8a\x0e\xa4tm\xab\xbf\xb4\xa5\x99\x00d\xd5w\x9f\x18\xbc\x1d\xd4_W\xd2\xb6\xe8H\x83\x1b\xd8\x9d\xad"
)
def __init__(self, user_id, leap_home):
self._user_id = user_id
self._leap_home = leap_home
self._uuid = str(uuid.uuid4())
self._mail_address = "%[email protected]" % user_id
self._soledad = None
self._services = None
@defer.inlineCallbacks
def start(self):
soledad_test_folder = os.path.join(self._leap_home, self._uuid)
self.soledad = yield initialize_soledad(tempdir=soledad_test_folder, uuid=self._uuid)
self.search_engine = SearchEngine(self.INDEX_KEY, user_home=soledad_test_folder)
self.keymanager = mock()
self.mail_sender = self._create_mail_sender()
self.mail_store = SearchableMailStore(LeapMailStore(self.soledad), self.search_engine)
self.attachment_store = LeapAttachmentStore(self.soledad)
yield self._initialize_account()
self.draft_service = DraftService(self.mail_store)
self.leap_session = mock()
self.feedback_service = FeedbackService(self.leap_session)
self.mail_service = self._create_mail_service(
self.mail_sender, self.mail_store, self.search_engine, self.attachment_store
)
mails = yield self.mail_service.all_mails()
if len(mails) > 0:
raise Exception("What? Where did these come from?")
self.search_engine.index_mails(mails)
@property
def services(self):
if self._services is None:
services = mock(Services)
services.keymanager = self.keymanager
services.mail_service = self.mail_service
services.draft_service = self.draft_service
services.search_engine = self.search_engine
services.feedback_service = self.feedback_service
services._leap_session = self.leap_session
self._services = services
self.leap_session.close = lambda: "mocked"
return self._services
def cleanup(self):
soledad_test_folder = os.path.join(self._leap_home, self._uuid)
shutil.rmtree(soledad_test_folder)
def _initialize_account(self):
self.account = Account(self.soledad, self._user_id)
return self.account.deferred_initialization
def _create_mail_service(self, mail_sender, mail_store, search_engine, attachment_store):
return MailService(mail_sender, mail_store, search_engine, self._mail_address, attachment_store)
def _create_mail_sender(self):
mail_sender = Mock()
mail_sender.sendmail.side_effect = lambda mail: succeed(mail)
return mail_sender
示例4: AppTestClient
# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mails [as 别名]
class AppTestClient(object):
INDEX_KEY = (
"\xde3?\x87\xff\xd9\xd3\x14\xf0\xa7>\x1f%C{\x16.\\\xae\x8c\x13\xa7\xfb\x04\xd4]+\x8d_\xed\xd1\x8d\x0bI"
"\x8a\x0e\xa4tm\xab\xbf\xb4\xa5\x99\x00d\xd5w\x9f\x18\xbc\x1d\xd4_W\xd2\xb6\xe8H\x83\x1b\xd8\x9d\xad"
)
ACCOUNT = "test"
MAIL_ADDRESS = "[email protected]"
# def __init__(self):
# self.start_client()
@defer.inlineCallbacks
def start_client(self):
soledad_test_folder = self._generate_soledad_test_folder_name()
SearchEngine.DEFAULT_INDEX_HOME = soledad_test_folder
self.cleanup = lambda: shutil.rmtree(soledad_test_folder)
self.soledad = yield initialize_soledad(tempdir=soledad_test_folder)
self.keymanager = mock()
self.search_engine = SearchEngine(self.INDEX_KEY, agent_home=soledad_test_folder)
self.mail_sender = self._create_mail_sender()
self.mail_store = SearchableMailStore(LeapMailStore(self.soledad), self.search_engine)
account_ready_cb = defer.Deferred()
self.account = IMAPAccount(self.ACCOUNT, self.soledad, account_ready_cb)
yield account_ready_cb
self.draft_service = DraftService(self.mail_store)
self.leap_session = mock()
self.feedback_service = FeedbackService(self.leap_session)
self.mail_service = self._create_mail_service(self.mail_sender, self.mail_store, self.search_engine)
mails = yield self.mail_service.all_mails()
self.search_engine.index_mails(mails)
self.resource = RootResource()
self.resource.initialize(
self.keymanager, self.search_engine, self.mail_service, self.draft_service, self.feedback_service
)
def _render(self, request, as_json=True):
def get_str(_str):
return json.loads(_str) if as_json else _str
def get_request_written_data(_=None):
written_data = request.getWrittenData()
if written_data:
return get_str(written_data)
resource = getChildForRequest(self.resource, request)
result = resource.render(request)
if isinstance(result, basestring):
return get_str(result), request
# result is NOT_DONE_YET
d = succeed(request) if request.finished else request.notifyFinish()
d.addCallback(get_request_written_data)
return d, request
def listenTCP(self, port=4567, host="127.0.0.1"):
reactor.listenTCP(port, PixelatedSite(self.resource), interface=host)
def run_on_a_thread(self, logfile="/tmp/app_test_client.log", port=4567, host="127.0.0.1"):
def _start():
self.listenTCP(port, host)
reactor.run()
process = multiprocessing.Process(target=_start)
process.start()
time.sleep(1)
return lambda: process.terminate()
def get(self, path, get_args="", as_json=True):
request = request_mock(path)
request.args = get_args
return self._render(request, as_json)
def post(self, path, body=""):
request = request_mock(path=path, method="POST", body=body, headers={"Content-Type": ["application/json"]})
return self._render(request)
def put(self, path, body):
request = request_mock(path=path, method="PUT", body=body, headers={"Content-Type": ["application/json"]})
return self._render(request)
def delete(self, path, body=""):
request = request_mock(path=path, body=body, headers={"Content-Type": ["application/json"]}, method="DELETE")
return self._render(request)
@defer.inlineCallbacks
def add_mail_to_inbox(self, input_mail):
mail = yield self.mail_store.add_mail("INBOX", input_mail.raw)
defer.returnValue(mail)
@defer.inlineCallbacks
def add_multiple_to_mailbox(
#.........这里部分代码省略.........
示例5: __init__
# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mails [as 别名]
class AppTestClient:
INDEX_KEY = '\xde3?\x87\xff\xd9\xd3\x14\xf0\xa7>\x1f%C{\x16.\\\xae\x8c\x13\xa7\xfb\x04\xd4]+\x8d_\xed\xd1\x8d\x0bI' \
'\x8a\x0e\xa4tm\xab\xbf\xb4\xa5\x99\x00d\xd5w\x9f\x18\xbc\x1d\xd4_W\xd2\xb6\xe8H\x83\x1b\xd8\x9d\xad'
def __init__(self, soledad_test_folder='/tmp/soledad-test/test'):
self.soledad = initialize_soledad(tempdir=soledad_test_folder)
self.mail_address = "[email protected]"
# setup app
PixelatedMail.from_email_address = self.mail_address
SearchEngine.DEFAULT_INDEX_HOME = soledad_test_folder
self.app = App()
self.soledad_querier = SoledadQuerier(self.soledad)
self.soledad_querier.get_index_masterkey = lambda: self.INDEX_KEY
self.account = SoledadBackedAccount('test', self.soledad, MagicMock())
self.mailboxes = Mailboxes(self.account, self.soledad_querier)
self.mail_sender = Mock()
self.tag_service = TagService()
self.draft_service = DraftService(self.mailboxes)
self.mail_service = MailService(self.mailboxes, self.mail_sender, self.tag_service,
self.soledad_querier)
self.search_engine = SearchEngine(self.soledad_querier)
self.search_engine.index_mails(self.mail_service.all_mails())
self.app.resource = RootResource()
self.app.resource.initialize(self.soledad_querier, self.search_engine, self.mail_service, self.draft_service)
def _render(self, request, as_json=True):
def get_str(_str):
return json.loads(_str) if as_json else _str
def get_request_written_data(_=None):
written_data = request.getWrittenData()
if written_data:
return get_str(written_data)
resource = getChildForRequest(self.app.resource, request)
result = resource.render(request)
if isinstance(result, basestring):
return get_str(result), request
# result is NOT_DONE_YET
d = succeed(request) if request.finished else request.notifyFinish()
d.addCallback(get_request_written_data)
return d, request
def run_on_a_thread(self, logfile='/tmp/app_test_client.log', port=4567, host='0.0.0.0'):
def _start():
reactor.listenTCP(port, Site(self.app.resource), interface=host)
reactor.run()
process = multiprocessing.Process(target=_start)
process.start()
time.sleep(1)
return lambda: process.terminate()
def get(self, path, get_args='', as_json=True):
request = request_mock(path)
request.args = get_args
return self._render(request, as_json)
def post(self, path, body=''):
request = request_mock(path=path, method="POST", body=body, headers={'Content-Type': ['application/json']})
return self._render(request)
def put(self, path, body):
request = request_mock(path=path, method="PUT", body=body, headers={'Content-Type': ['application/json']})
return self._render(request)
def delete(self, path, body=""):
request = request_mock(path=path, body=body, headers={'Content-Type': ['application/json']}, method="DELETE")
return self._render(request)
def add_document_to_soledad(self, _dict):
self.soledad_querier.soledad.create_doc(_dict)
def add_mail_to_inbox(self, input_mail):
mail = self.mailboxes.inbox().add(input_mail)
mail.update_tags(input_mail.tags)
self.search_engine.index_mail(mail)
def add_multiple_to_mailbox(self, num, mailbox='', flags=[], tags=[], to='[email protected]', cc='[email protected]', bcc='[email protected]'):
mails = []
for _ in range(num):
input_mail = MailBuilder().with_status(flags).with_tags(tags).with_to(to).with_cc(cc).with_bcc(bcc).build_input_mail()
mail = self.mailboxes._create_or_get(mailbox).add(input_mail)
mails.append(mail)
mail.update_tags(input_mail.tags)
self.search_engine.index_mail(mail)
return mails
示例6: AppTestClient
# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mails [as 别名]
class AppTestClient(object):
INDEX_KEY = '\xde3?\x87\xff\xd9\xd3\x14\xf0\xa7>\x1f%C{\x16.\\\xae\x8c\x13\xa7\xfb\x04\xd4]+\x8d_\xed\xd1\x8d\x0bI' \
'\x8a\x0e\xa4tm\xab\xbf\xb4\xa5\x99\x00d\xd5w\x9f\x18\xbc\x1d\xd4_W\xd2\xb6\xe8H\x83\x1b\xd8\x9d\xad'
ACCOUNT = 'test'
MAIL_ADDRESS = '[email protected]'
def __init__(self):
self.start_client()
def start_client(self):
soledad_test_folder = self._generate_soledad_test_folder_name()
SearchEngine.DEFAULT_INDEX_HOME = soledad_test_folder
self.cleanup = lambda: shutil.rmtree(soledad_test_folder)
PixelatedMail.from_email_address = self.MAIL_ADDRESS
self.soledad = initialize_soledad(tempdir=soledad_test_folder)
self.soledad_querier = self._create_soledad_querier(self.soledad, self.INDEX_KEY)
self.keymanager = mock()
self.search_engine = SearchEngine(self.INDEX_KEY, agent_home=soledad_test_folder)
self.mail_sender = self._create_mail_sender()
self.account = SoledadBackedAccount(self.ACCOUNT, self.soledad, MagicMock())
self.mailboxes = Mailboxes(self.account, self.soledad_querier, self.search_engine)
self.draft_service = DraftService(self.mailboxes)
self.mail_service = self._create_mail_service(self.mailboxes, self.mail_sender, self.soledad_querier, self.search_engine)
self.search_engine.index_mails(self.mail_service.all_mails())
self.resource = RootResource()
self.resource.initialize(self.keymanager, self.search_engine, self.mail_service, self.draft_service)
def _render(self, request, as_json=True):
def get_str(_str):
return json.loads(_str) if as_json else _str
def get_request_written_data(_=None):
written_data = request.getWrittenData()
if written_data:
return get_str(written_data)
resource = getChildForRequest(self.resource, request)
result = resource.render(request)
if isinstance(result, basestring):
return get_str(result), request
# result is NOT_DONE_YET
d = succeed(request) if request.finished else request.notifyFinish()
d.addCallback(get_request_written_data)
return d, request
def run_on_a_thread(self, logfile='/tmp/app_test_client.log', port=4567, host='0.0.0.0'):
def _start():
reactor.listenTCP(port, Site(self.resource), interface=host)
reactor.run()
process = multiprocessing.Process(target=_start)
process.start()
time.sleep(1)
return lambda: process.terminate()
def get(self, path, get_args='', as_json=True):
request = request_mock(path)
request.args = get_args
return self._render(request, as_json)
def post(self, path, body=''):
request = request_mock(path=path, method="POST", body=body, headers={'Content-Type': ['application/json']})
return self._render(request)
def put(self, path, body):
request = request_mock(path=path, method="PUT", body=body, headers={'Content-Type': ['application/json']})
return self._render(request)
def delete(self, path, body=""):
request = request_mock(path=path, body=body, headers={'Content-Type': ['application/json']}, method="DELETE")
return self._render(request)
def add_document_to_soledad(self, _dict):
self.soledad_querier.soledad.create_doc(_dict)
def add_mail_to_inbox(self, input_mail):
mail = self.mailboxes.inbox.add(input_mail)
if input_mail.tags:
mail.update_tags(input_mail.tags)
self.search_engine.index_mail(mail)
def add_multiple_to_mailbox(self, num, mailbox='', flags=[], tags=[], to='[email protected]', cc='[email protected]', bcc='[email protected]'):
mails = []
for _ in range(num):
input_mail = MailBuilder().with_status(flags).with_tags(tags).with_to(to).with_cc(cc).with_bcc(bcc).build_input_mail()
mail = self.mailboxes._create_or_get(mailbox).add(input_mail)
mails.append(mail)
mail.update_tags(input_mail.tags) if tags else None
self.search_engine.index_mails(mails) if tags else None
return mails
def _create_soledad_querier(self, soledad, index_key):
#.........这里部分代码省略.........
示例7: __init__
# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mails [as 别名]
class AppTestClient:
def __init__(self, soledad_test_folder='soledad-test'):
self.soledad = initialize_soledad(tempdir=soledad_test_folder)
self.mail_address = "[email protected]"
# setup app
PixelatedMail.from_email_address = self.mail_address
SearchEngine.INDEX_FOLDER = soledad_test_folder + '/search_index'
self.app = pixelated.runserver.app
self.soledad_querier = SoledadQuerier(self.soledad)
self.soledad_querier.get_index_masterkey = lambda: '_yg2oG_5ELM8_-sQYcsxI37WesI0dOtZQXpwAqjvhR4='
self.account = SoledadBackedAccount('test', self.soledad, MagicMock())
self.mailboxes = Mailboxes(self.account, self.soledad_querier)
self.mail_sender = Mock()
self.tag_service = TagService()
self.draft_service = DraftService(self.mailboxes)
self.mail_service = MailService(self.mailboxes, self.mail_sender, self.tag_service,
self.soledad_querier)
self.search_engine = SearchEngine(self.soledad_querier)
self.search_engine.index_mails(self.mail_service.all_mails())
features_controller = FeaturesController()
features_controller.DISABLED_FEATURES.append('autoReload')
home_controller = HomeController()
mails_controller = MailsController(mail_service=self.mail_service,
draft_service=self.draft_service,
search_engine=self.search_engine)
tags_controller = TagsController(search_engine=self.search_engine)
contacts_controller = ContactsController(search_engine=self.search_engine)
sync_info_controller = SyncInfoController()
attachments_controller = AttachmentsController(self.soledad_querier)
setup_routes(self.app, home_controller, mails_controller, tags_controller,
features_controller, sync_info_controller, attachments_controller, contacts_controller)
def _render(self, request, as_json=True):
def get_request_written_data(_=None):
written_data = request.getWrittenData()
if written_data:
return json.loads(written_data) if as_json else written_data
d = _render(self.app.resource(), request)
if request.finished:
return get_request_written_data(), request
else:
d.addCallback(get_request_written_data)
return d, request
def run_on_a_thread(self, logfile='/tmp/app_test_client.log', port=4567, host='localhost'):
worker = lambda: self.app.run(host=host, port=port, logFile=open(logfile, 'w'))
process = multiprocessing.Process(target=worker)
process.start()
time.sleep(1) # just let it start
return lambda: process.terminate()
def get(self, path, get_args, as_json=True):
request = requestMock(path)
request.args = get_args
return self._render(request, as_json)
def post(self, path, body=''):
request = requestMock(path=path, method="POST", body=body, headers={'Content-Type': ['application/json']})
return self._render(request)
def put(self, path, body):
request = requestMock(path=path, method="PUT", body=body, headers={'Content-Type': ['application/json']})
return self._render(request)
def delete(self, path):
request = requestMock(path=path, method="DELETE")
return self._render(request)
def add_document_to_soledad(self, _dict):
self.soledad_querier.soledad.create_doc(_dict)
def add_mail_to_inbox(self, input_mail):
mail = self.mailboxes.inbox().add(input_mail)
mail.update_tags(input_mail.tags)
self.search_engine.index_mail(mail)
def add_multiple_to_mailbox(self, num, mailbox='', flags=[], tags=[]):
mails = []
for _ in range(num):
input_mail = MailBuilder().with_status(flags).with_tags(tags).build_input_mail()
mail = self.mailboxes._create_or_get(mailbox).add(input_mail)
mails.append(mail)
mail.update_tags(input_mail.tags)
self.search_engine.index_mail(mail)
return mails
示例8: __init__
# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mails [as 别名]
class SoledadTestBase:
def __init__(self):
pass
def teardown_soledad(self):
pass
def _reset_routes(self, app):
static_files_route = app.view_functions['static']
app.view_functions = {'static': static_files_route}
def setup_soledad(self):
self.soledad = initialize_soledad(tempdir=soledad_test_folder)
self.mail_address = "[email protected]"
# setup app
PixelatedMail.from_email_address = self.mail_address
SearchEngine.INDEX_FOLDER = soledad_test_folder + '/search_index'
self.client = pixelated.runserver.app.test_client()
self._reset_routes(self.client.application)
self.soledad_querier = SoledadQuerier(self.soledad)
self.account = FakeAccount()
self.mailboxes = Mailboxes(self.account, self.soledad_querier)
self.mail_sender = mock()
self.tag_service = TagService()
self.draft_service = DraftService(self.mailboxes)
self.mail_service = MailService(self.mailboxes, self.mail_sender, self.tag_service,
self.soledad_querier)
self.search_engine = SearchEngine()
self.search_engine.index_mails(self.mail_service.all_mails())
features_controller = FeaturesController()
features_controller.DISABLED_FEATURES.append('autoReload')
home_controller = HomeController()
mails_controller = MailsController(mail_service=self.mail_service,
draft_service=self.draft_service,
search_engine=self.search_engine)
tags_controller = TagsController(search_engine=self.search_engine)
sync_info_controller = SyncInfoController()
app_factory._setup_routes(self.client.application, home_controller, mails_controller, tags_controller,
features_controller, sync_info_controller)
def get_mails_by_tag(self, tag, page=1, window=100):
response = json.loads(self.client.get("/mails?q=tag:%s&w=%s&p=%s" % (tag, window, page)).data)
return [ResponseMail(m) for m in response['mails']]
def post_mail(self, data):
response = json.loads(self.client.post('/mails', data=data, content_type="application/json").data)
return ResponseMail(response)
def put_mail(self, data):
response = json.loads(self.client.put('/mails', data=data, content_type="application/json").data)
return response['ident']
def post_tags(self, mail_ident, tags_json):
return json.loads(
self.client.post('/mail/' + mail_ident + '/tags', data=tags_json, content_type="application/json").data)
def get_tags(self, query_string=""):
return json.loads(
self.client.get('/tags' + query_string, content_type="application/json").data)
def delete_mail(self, mail_ident):
self.client.delete('/mail/' + mail_ident)
def mark_as_read(self, mail_ident):
self.client.post('/mail/' + mail_ident + '/read', content_type="application/json")
def mark_as_unread(self, mail_ident):
self.client.post('/mail/' + mail_ident + '/unread', content_type="application/json")
def mark_many_as_unread(self, idents):
self.client.post('/mails/unread', data={'idents': json.dumps(idents)})
def mark_many_as_read(self, idents):
return self.client.post('/mails/read', data={'idents': json.dumps(idents)})
def add_mail_to_inbox(self, input_mail):
mail = self.mailboxes.inbox().add(input_mail)
mail.update_tags(input_mail.tags)
self.search_engine.index_mail(mail)
def add_multiple_to_mailbox(self, num, mailbox='', flags=[], tags=[]):
mails = []
for _ in range(num):
input_mail = MailBuilder().with_status(flags).with_tags(tags).build_input_mail()
mail = self.mailboxes._create_or_get(mailbox).add(input_mail)
mails.append(mail)
mail.update_tags(input_mail.tags)
self.search_engine.index_mail(mail)
return mails