def before_all(context): ensure_server() logging.disable('INFO') PixelatedSite.disable_csp_requests() client = AppTestClient() start_app_test_client(client, UserAgentMode(is_single_user=True)) client.listenTCP(port=8889) FeaturesResource.DISABLED_FEATURES.append('autoRefresh') context.client = client multi_user_client = AppTestClient() start_app_test_client(multi_user_client, UserAgentMode(is_single_user=False)) multi_user_client.listenTCP(port=MULTI_USER_PORT) context.multi_user_client = multi_user_client
def start_client(self, mode=UserAgentMode(is_single_user=True)): self._initialize() self._test_account = AppTestAccount('test', self._tmp_dir.name) yield self._test_account.start() self.cleanup = lambda: self._test_account.cleanup() self.soledad = self._test_account.soledad self.service_factory = ServicesFactory(UserAgentMode(is_single_user=False)) root_resource = RootResource(self.service_factory) leap_provider = mock() self.resource = set_up_protected_resources(root_resource, leap_provider, self.service_factory)
def start_pixelated_user_agent(userid, soledad, keymanager, account): try: leap_session = LeapSessionAdapter(userid, soledad, keymanager, account) except Exception as exc: log.error("Got error! %r" % exc) config = Config() leap_home = os.path.join(get_path_prefix(), 'leap') config.leap_home = leap_home leap_session.config = config services_factory = SingleUserServicesFactory( UserAgentMode(is_single_user=True)) if getattr(sys, 'frozen', False): # we are running in a |PyInstaller| bundle static_folder = os.path.join(sys._MEIPASS, 'leap', 'pixelated_www') else: static_folder = os.path.abspath(leap.pixelated_www.__path__[0]) set_static_folder(static_folder) resource = RootResource(services_factory, static_folder=static_folder) config.host = 'localhost' config.port = 9090 config.sslkey = None config.sslcert = None config.manhole = False d = leap_session.account.callWhenReady( lambda _: _start_in_single_user_mode(leap_session, config, resource, services_factory)) return d
def start_client(self, mode=UserAgentMode(is_single_user=True)): self._initialize() self._mode = mode self._test_account = AppTestAccount(self.ACCOUNT, self._tmp_dir.name) yield self._test_account.start() self.cleanup = lambda: self._tmp_dir.dissolve() # copy fields for single user tests self.soledad = self._test_account.soledad self.search_engine = self._test_account.search_engine self.keymanager = self._test_account.keymanager self.mail_sender = self._test_account.mail_sender self.mail_store = self._test_account.mail_store self.attachment_store = self._test_account.attachment_store self.draft_service = self._test_account.draft_service self.leap_session = self._test_account.leap_session self.feedback_service = self._test_account.feedback_service self.mail_service = self._test_account.mail_service self.account = self._test_account.account if mode.is_single_user: self.service_factory = SingleUserServicesFactory(mode) services = self._test_account.services self.service_factory.add_session('someuserid', services) self.resource = RootResource(self.service_factory) self.resource.initialize() else: self.service_factory = StubServicesFactory(self.accounts, mode) provider = mock() provider.config = LeapConfig(self._tmp_dir.name) self.resource = set_up_protected_resources(RootResource(self.service_factory), provider, self.service_factory, checker=StubSRPChecker(provider))
def setUp(self): self.mail_service = mock() self.services_factory = mock() self.services_factory.mode = UserAgentMode(is_single_user=True) self.services = mock() self.services.mail_service = self.mail_service self.services.draft_service = mock() self.services_factory._services_by_user = {'someuserid': self.mail_service} when(self.services_factory).services(ANY()).thenReturn(self.services)
def setUp(self): self.keymanager = mock() self.services_factory = mock() self.services_factory.mode = UserAgentMode(is_single_user=True) self.services = mock() self.services.keymanager = self.keymanager self.services_factory._services_by_user = { 'someuserid': self.keymanager } when(self.services_factory).services(ANY()).thenReturn(self.services) self.web = DummySite(KeysResource(self.services_factory))
def setUp(self): self.mail_service = mock() self.services_factory = mock() self.services_factory.mode = UserAgentMode(is_single_user=True) self.services = mock() self.services.mail_service = self.mail_service self.services_factory._services_by_user = { 'someuserid': self.mail_service } when(self.services_factory).services(ANY()).thenReturn(self.services) self.mails_resource = AttachmentsResource(self.services_factory) self.mails_resource.isLeaf = True self.web = DummySite(self.mails_resource)
def setUp(self): self.services = mock() self.mail_service = mock() self.mail_service.account_email = MAIL_ADDRESS self.keymanager = mock() self.services_factory = mock() self.services_factory.mode = UserAgentMode(is_single_user=True) self.services.mail_service = self.mail_service self.services.keymanager = self.keymanager self.services_factory._services_by_user = { 'someuserid': self.keymanager } self.resource = UserSettingsResource(self.services_factory) when(self.services_factory).services(any()).thenReturn(self.services) self.web = DummySite(self.resource)
def setUp(self): self.mail_service = mock() self.services_factory = mock() self.services_factory.mode = UserAgentMode(is_single_user=True) self.services = mock() self.services.mail_service = self.mail_service self.services_factory._services_by_user = {'someuserid': self.mail_service} when(self.services_factory).services(ANY()).thenReturn(self.services) self.mail_service.account_email = self.MAIL_ADDRESS root_resource = RootResource(self.services_factory) root_resource._html_template = "<html><head><title>$account_email</title></head></html>" root_resource._mode = root_resource self.web = DummySite(root_resource) self.root_resource = root_resource
def _start_user_agent(port, is_single_user): client = AppTestClient() start_app_test_client(client, UserAgentMode(is_single_user=is_single_user)) client.listenTCP(port=port) return client