当前位置: 首页>>代码示例>>Python>>正文


Python SearchEngine.index_mail方法代码示例

本文整理汇总了Python中pixelated.adapter.search.SearchEngine.index_mail方法的典型用法代码示例。如果您正苦于以下问题:Python SearchEngine.index_mail方法的具体用法?Python SearchEngine.index_mail怎么用?Python SearchEngine.index_mail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pixelated.adapter.search.SearchEngine的用法示例。


在下文中一共展示了SearchEngine.index_mail方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_contents_encoding_accents

# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mail [as 别名]
    def test_contents_encoding_accents(self):
        # given
        se = SearchEngine(INDEX_KEY, self.user_home)

        headers = {
            "From": "[email protected]",
            "To": "=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=",
            "Cc": "=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=",
            "Subject": "Some test mail",
            "Date": str(datetime.now()),
        }

        body = "When doing the search, it's not possible to find words with graphical accents, e.g.: 'coração', 'é',  'Fièvre', La Pluie d'été, 'não'."

        # when
        se.index_mail(
            LeapMail("mailid", "INBOX", headers=headers, body=body)
        )  # test_helper.pixelated_mail(extra_headers=headers, chash='mailid'))

        result = se.search(u"'coração', 'é',")
        self.assertEqual((["mailid"], 1), result)

        result = se.search(u"Fièvre")
        self.assertEqual((["mailid"], 1), result)

        result = se.search(u"été")
        self.assertEqual((["mailid"], 1), result)
开发者ID:akjones,项目名称:pixelated-user-agent,代码行数:29,代码来源:test_search.py

示例2: test_headers_encoding

# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mail [as 别名]
    def test_headers_encoding(self):
        # given
        se = SearchEngine(INDEX_KEY, self.user_home)

        headers = {
            'From': '[email protected]',
            'To': '=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=',
            'Cc': '=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=',
            'Subject': 'Some test mail',
        }

        # when
        se.index_mail(LeapMail('mailid', 'INBOX', headers=headers))   # test_helper.pixelated_mail(extra_headers=headers, chash='mailid'))

        result = se.search('folker')

        self.assertEqual((['mailid'], 1), result)
开发者ID:carriercomm,项目名称:pixelated-user-agent,代码行数:19,代码来源:test_search.py

示例3: test_encoding

# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mail [as 别名]
    def test_encoding(self):
        # given
        se = SearchEngine(INDEX_KEY, self.agent_home)

        headers = {
            "From": "[email protected]",
            "To": "=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=",
            "Cc": "=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=",
            "Subject": "Some test mail",
        }

        # when
        se.index_mail(test_helper.pixelated_mail(extra_headers=headers, chash="mailid"))

        result = se.search("folker")

        self.assertEqual((["mailid"], 1), result)
开发者ID:EderRoger,项目名称:pixelated-user-agent,代码行数:19,代码来源:test_search.py

示例4: test_encoding

# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mail [as 别名]
    def test_encoding(self):
        # given
        soledad_querier = mock()
        when(soledad_querier).get_index_masterkey().thenReturn(INDEX_KEY)

        se = SearchEngine(soledad_querier, self.agent_home)

        headers = {
            'From': '[email protected]',
            'To': '=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=',
            'Cc': '=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=',
            'Subject': 'Some test mail',
        }

        # when
        se.index_mail(test_helper.pixelated_mail(extra_headers=headers, chash='mailid'))

        result = se.search('folker')

        self.assertEqual((['mailid'], 1), result)
开发者ID:amukiza,项目名称:pixelated-user-agent,代码行数:22,代码来源:test_search.py

示例5: test_index_mail_secured_by_lock

# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mail [as 别名]
    def test_index_mail_secured_by_lock(self):
        # given
        soledad_querier = mock()
        lock_stub = LockStub()
        when(soledad_querier).get_index_masterkey().thenReturn(INDEX_KEY)

        self.assertEqual(INDEX_KEY, soledad_querier.get_index_masterkey())
        se = SearchEngine(soledad_querier, self.agent_home)
        se._write_lock = lock_stub

        headers = {
            'From': '[email protected]',
            'To': '[email protected]',
            'Subject': 'Some test mail',
        }

        # when
        se.index_mail(test_helper.pixelated_mail(extra_headers=headers))

        # then
        self.assertTrue(lock_stub.called)
开发者ID:amukiza,项目名称:pixelated-user-agent,代码行数:23,代码来源:test_search.py

示例6: test_contents_encoding_special_characters

# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mail [as 别名]
    def test_contents_encoding_special_characters(self):
        # given
        se = SearchEngine(INDEX_KEY, self.agent_home)

        headers = {
            'From': '[email protected]',
            'To': '=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=',
            'Cc': '=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=',
            'Subject': 'Some test mail',
        }

        body = "When doing the search, 您好  أهلا"

        # when
        se.index_mail(LeapMail('mailid', 'INBOX', headers=headers, body=body))   # test_helper.pixelated_mail(extra_headers=headers, chash='mailid'))

        result = se.search(u"您好")
        self.assertEqual((['mailid'], 1), result)

        result = se.search(u"أهلا")
        self.assertEqual((['mailid'], 1), result)
开发者ID:tcz001,项目名称:pixelated-user-agent,代码行数:23,代码来源:test_search.py

示例7: test_contents_encoding_accents

# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mail [as 别名]
    def test_contents_encoding_accents(self):
        # given
        se = SearchEngine(INDEX_KEY, self.agent_home)

        headers = {
            'From': '[email protected]',
            'To': '=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=',
            'Cc': '=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=',
            'Subject': 'Some test mail',
        }

        body = "When doing the search, it's not possible to find words with graphical accents, e.g.: 'coração', 'é',  'Fièvre', La Pluie d'été, 'não'."

        # when
        se.index_mail(LeapMail('mailid', 'INBOX', headers=headers, body=body))   # test_helper.pixelated_mail(extra_headers=headers, chash='mailid'))

        result = se.search(u"'coração', 'é',")
        self.assertEqual((['mailid'], 1), result)

        result = se.search(u"Fièvre")
        self.assertEqual((['mailid'], 1), result)

        result = se.search(u"été")
        self.assertEqual((['mailid'], 1), result)
开发者ID:tcz001,项目名称:pixelated-user-agent,代码行数:26,代码来源:test_search.py

示例8: test_contents_encoding_special_characters

# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mail [as 别名]
    def test_contents_encoding_special_characters(self):
        # given
        se = SearchEngine(INDEX_KEY, self.user_home)

        headers = {
            "From": "[email protected]",
            "To": "=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=",
            "Cc": "=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=",
            "Subject": "Some test mail",
            "Date": str(datetime.now()),
        }

        body = "When doing the search, 您好  أهلا"

        # when
        se.index_mail(
            LeapMail("mailid", "INBOX", headers=headers, body=body)
        )  # test_helper.pixelated_mail(extra_headers=headers, chash='mailid'))

        result = se.search(u"您好")
        self.assertEqual((["mailid"], 1), result)

        result = se.search(u"أهلا")
        self.assertEqual((["mailid"], 1), result)
开发者ID:akjones,项目名称:pixelated-user-agent,代码行数:26,代码来源:test_search.py

示例9: __init__

# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mail [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)
#.........这里部分代码省略.........
开发者ID:rouanw,项目名称:pixelated-user-agent,代码行数:103,代码来源:integration_helper.py

示例10: teardown_soledad

# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mail [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)
开发者ID:vintrepid,项目名称:pixelated-user-agent,代码行数:67,代码来源:integration_helper.py

示例11: __init__

# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mail [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
开发者ID:pedrovereza,项目名称:pixelated-user-agent,代码行数:98,代码来源:app_test_client.py

示例12: AppTestClient

# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mail [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):
#.........这里部分代码省略.........
开发者ID:EderRoger,项目名称:pixelated-user-agent,代码行数:103,代码来源:app_test_client.py

示例13: __init__

# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mail [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
开发者ID:RogerS49,项目名称:pixelated-user-agent,代码行数:96,代码来源:app_test_client.py

示例14: __init__

# 需要导入模块: from pixelated.adapter.search import SearchEngine [as 别名]
# 或者: from pixelated.adapter.search.SearchEngine import index_mail [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
开发者ID:Nangal,项目名称:pixelated-user-agent,代码行数:97,代码来源:integration_helper.py


注:本文中的pixelated.adapter.search.SearchEngine.index_mail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。