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


Python helpers.NoNetworkLaunchpad类代码示例

本文整理汇总了Python中launchpadlib.testing.helpers.NoNetworkLaunchpad的典型用法代码示例。如果您正苦于以下问题:Python NoNetworkLaunchpad类的具体用法?Python NoNetworkLaunchpad怎么用?Python NoNetworkLaunchpad使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_get_token_and_login_is_deprecated

 def test_get_token_and_login_is_deprecated(self):
     # get_token_and_login() works but triggers a deprecation warning.
     with warnings.catch_warnings(record=True) as caught:
         warnings.simplefilter("always")
         NoNetworkLaunchpad.get_token_and_login('consumer')
         self.assertEquals(len(caught), 1)
         self.assertEquals(caught[0].category, DeprecationWarning)
开发者ID:bryan-herbert,项目名称:cpsc-113-finalexam,代码行数:7,代码来源:test_launchpad.py

示例2: test_authorization_engine_is_propagated

 def test_authorization_engine_is_propagated(self):
     # You can pass in a custom authorization engine, which will be
     # used to get a request token and exchange it for an access
     # token.
     engine = NoNetworkAuthorizationEngine(
         SERVICE_ROOT, 'application name')
     NoNetworkLaunchpad.login_with(authorization_engine=engine)
     self.assertEquals(engine.request_tokens_obtained, 1)
     self.assertEquals(engine.access_tokens_obtained, 1)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:9,代码来源:test_launchpad.py

示例3: test_dirs_created_are_secure

 def test_dirs_created_are_secure(self):
     launchpadlib_dir = os.path.join(self.temp_dir, 'launchpadlib')
     NoNetworkLaunchpad.login_with(
         'not important', service_root=SERVICE_ROOT,
         launchpadlib_dir=launchpadlib_dir)
     self.assertTrue(os.path.isdir(launchpadlib_dir))
     # Verify the mode is safe
     statinfo = os.stat(launchpadlib_dir)
     mode = stat.S_IMODE(statinfo.st_mode)
     self.assertEqual(mode, stat.S_IWRITE | stat.S_IREAD | stat.S_IEXEC)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:10,代码来源:test_launchpad.py

示例4: test_dirs_created_are_changed_to_secure

 def test_dirs_created_are_changed_to_secure(self):
     launchpadlib_dir = os.path.join(self.temp_dir, 'launchpadlib')
     # Verify a newly created-by-hand directory is insecure
     os.mkdir(launchpadlib_dir)
     os.chmod(launchpadlib_dir, 0755)
     self.assertTrue(os.path.isdir(launchpadlib_dir))
     statinfo = os.stat(launchpadlib_dir)
     mode = stat.S_IMODE(statinfo.st_mode)
     self.assertNotEqual(mode, stat.S_IWRITE | stat.S_IREAD | stat.S_IEXEC)
     NoNetworkLaunchpad.login_with(
         'not important', service_root=SERVICE_ROOT,
         launchpadlib_dir=launchpadlib_dir)
     # Verify the mode has been changed to 0700
     statinfo = os.stat(launchpadlib_dir)
     mode = stat.S_IMODE(statinfo.st_mode)
     self.assertEqual(mode, stat.S_IWRITE | stat.S_IREAD | stat.S_IEXEC)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:16,代码来源:test_launchpad.py

示例5: test_existing_credentials_arguments_passed_on

    def test_existing_credentials_arguments_passed_on(self):
        # When re-using existing credentials, the arguments login_with
        # is called with are passed on the the __init__() method.
        os.makedirs(
            os.path.join(self.temp_dir, 'api.example.com', 'credentials'))
        credentials_file_path = os.path.join(
            self.temp_dir, 'api.example.com', 'credentials', 'app name')
        credentials = Credentials(
            'app name', consumer_secret='consumer_secret:42',
            access_token=AccessToken('access_key:84', 'access_secret:168'))
        credentials.save_to_path(credentials_file_path)

        timeout = object()
        proxy_info = object()
        version = "foo"
        launchpad = NoNetworkLaunchpad.login_with(
            'app name', launchpadlib_dir=self.temp_dir,
            service_root=SERVICE_ROOT, timeout=timeout, proxy_info=proxy_info,
            version=version)
        expected_arguments = dict(
            service_root=SERVICE_ROOT,
            timeout=timeout,
            proxy_info=proxy_info,
            version=version,
            cache=os.path.join(self.temp_dir, 'api.example.com', 'cache'))
        for key, expected in expected_arguments.items():
            actual = launchpad.passed_in_args[key]
            self.assertEqual(actual, expected)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:28,代码来源:test_launchpad.py

示例6: test_version_is_propagated

    def test_version_is_propagated(self):
        # Make sure the login_with() method conveys the 'version'
        # argument all the way to the Launchpad object. The
        # credentials will be cached to disk.
        launchpadlib_dir = os.path.join(self.temp_dir, 'launchpadlib')
        launchpad = NoNetworkLaunchpad.login_with(
            'not important', service_root=SERVICE_ROOT,
            launchpadlib_dir=launchpadlib_dir, version="foo")
        self.assertEquals(launchpad.passed_in_args['version'], 'foo')

        # Now execute the same test a second time. This time, the
        # credentials are loaded from disk and a different code path
        # is executed. We want to make sure this code path propagates
        # the 'version' argument.
        launchpad = NoNetworkLaunchpad.login_with(
            'not important', service_root=SERVICE_ROOT,
            launchpadlib_dir=launchpadlib_dir, version="bar")
        self.assertEquals(launchpad.passed_in_args['version'], 'bar')
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:18,代码来源:test_launchpad.py

示例7: test_desktop_integration_doesnt_happen_without_consumer_name

 def test_desktop_integration_doesnt_happen_without_consumer_name(self):
     # The only way to do a non-desktop integration is to specify a
     # consumer_name. If you specify application_name instead, your
     # value for allow_access_levels is ignored, and a desktop
     # integration is performed.
     launchpad = NoNetworkLaunchpad.login_with(
         'application name', allow_access_levels=['FOO'])
     self.assertEquals(launchpad.authorization_engine.allow_access_levels,
                       ['DESKTOP_INTEGRATION'])
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:9,代码来源:test_launchpad.py

示例8: test_credentials_save_failed

    def test_credentials_save_failed(self):
        # If saving the credentials did not succeed and a callback was
        # provided, it is called.

        callback_called = []
        def callback():
            # Since we can't rebind "callback_called" here, we'll have to
            # settle for mutating it to signal success.
            callback_called.append(None)

        launchpadlib_dir = os.path.join(self.temp_dir, 'launchpadlib')
        service_root = "http://api.example.com/"
        with fake_keyring(BadSaveKeyring()):
            NoNetworkLaunchpad.login_with(
                'not important', service_root=service_root,
                launchpadlib_dir=launchpadlib_dir,
                credential_save_failed=callback)
            self.assertEquals(len(callback_called), 1)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:18,代码来源:test_launchpad.py

示例9: test_filename

    def test_filename(self):
        ignore, filename = tempfile.mkstemp()
        launchpad = NoNetworkLaunchpad.login_with(
            application_name='not important', credentials_file=filename)

        # The credentials are stored unencrypted in the file you
        # specify.
        credentials = Credentials.load_from_path(filename)
        self.assertEquals(credentials.consumer.key,
                          launchpad.credentials.consumer.key)
        os.remove(filename)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:11,代码来源:test_launchpad.py

示例10: test_short_service_name

    def test_short_service_name(self):
        # A short service name is converted to the full service root URL.
        launchpad = NoNetworkLaunchpad.login_with('app name', 'staging')
        self.assertEqual(
            launchpad.passed_in_args['service_root'],
            'https://api.staging.launchpad.net/')

        # A full URL as the service name is left alone.
        launchpad = NoNetworkLaunchpad.login_with(
            'app name', uris.service_roots['staging'])
        self.assertEqual(
            launchpad.passed_in_args['service_root'],
            uris.service_roots['staging'])

        # A short service name that does not match one of the
        # pre-defined service root names, and is not a valid URL,
        # raises an exception.
        launchpad = ('app name', 'https://')
        self.assertRaises(
            ValueError, NoNetworkLaunchpad.login_with, 'app name', 'foo')
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:20,代码来源:test_launchpad.py

示例11: test_non_desktop_integration

 def test_non_desktop_integration(self):
     # When doing a non-desktop integration, you must specify a
     # consumer_name. You can pass a list of allowable access
     # levels into login_with().
     launchpad = NoNetworkLaunchpad.login_with(
         consumer_name="consumer", allow_access_levels=['FOO'])
     self.assertEquals(launchpad.credentials.consumer.key, "consumer")
     self.assertEquals(launchpad.credentials.consumer.application_name,
                       None)
     self.assertEquals(launchpad.authorization_engine.allow_access_levels,
                       ['FOO'])
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:11,代码来源:test_launchpad.py

示例12: test_dirs_created

    def test_dirs_created(self):
        # The path we pass into login_with() is the directory where
        # cache for all service roots are stored.
        launchpadlib_dir = os.path.join(self.temp_dir, 'launchpadlib')
        NoNetworkLaunchpad.login_with(
            'not important', service_root=SERVICE_ROOT,
            launchpadlib_dir=launchpadlib_dir)
        # The 'launchpadlib' dir got created.
        self.assertTrue(os.path.isdir(launchpadlib_dir))
        # A directory for the passed in service root was created.
        service_path = os.path.join(launchpadlib_dir, 'api.example.com')
        self.assertTrue(os.path.isdir(service_path))
        # Inside the service root directory, there is a 'cache'
        # directory.
        self.assertTrue(
            os.path.isdir(os.path.join(service_path, 'cache')))

        # In older versions there was also a 'credentials' directory,
        # but no longer.
        credentials_path = os.path.join(service_path, 'credentials')
        self.assertFalse(os.path.isdir(credentials_path))
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:21,代码来源:test_launchpad.py

示例13: test_same_app_different_servers

    def test_same_app_different_servers(self):
        launchpadlib_dir = os.path.join(self.temp_dir, 'launchpadlib')
        keyring = InMemoryKeyring()
        # Be paranoid about the keyring starting out empty.
        assert not keyring.data, 'oops, a fresh keyring has data in it'
        with fake_keyring(keyring):
            # Create stored credentials for the same application but against
            # two different sites (service roots).
            NoNetworkLaunchpad.login_with(
                'application name', service_root='http://alpha.example.com/',
                launchpadlib_dir=launchpadlib_dir)
            NoNetworkLaunchpad.login_with(
                'application name', service_root='http://beta.example.com/',
                launchpadlib_dir=launchpadlib_dir)

        # There should only be two sets of stored credentials (this assertion
        # is of the test mechanism, not a test assertion).
        assert len(keyring.data.keys()) == 2

        application_key_1 = keyring.data.keys()[0][1]
        application_key_2 = keyring.data.keys()[1][1]
        self.assertNotEqual(application_key_1, application_key_2)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:22,代码来源:test_launchpad.py

示例14: test_anonymous_login

    def test_anonymous_login(self):
        """Test the anonymous login helper function."""
        launchpad = NoNetworkLaunchpad.login_anonymously(
            'anonymous access', launchpadlib_dir=self.temp_dir,
            service_root=SERVICE_ROOT)
        self.assertEqual(launchpad.credentials.access_token.key, '')
        self.assertEqual(launchpad.credentials.access_token.secret, '')

        # Test that anonymous credentials are not saved.
        credentials_path = os.path.join(
            self.temp_dir, 'api.example.com', 'credentials',
            'anonymous access')
        self.assertFalse(os.path.exists(credentials_path))
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:13,代码来源:test_launchpad.py

示例15: test_application_name_is_propagated

    def test_application_name_is_propagated(self):
        # Create a Launchpad instance for a given application name.
        # Credentials are stored, but they don't include the
        # application name, since multiple applications may share a
        # single system-wide credential.
        launchpadlib_dir = os.path.join(self.temp_dir, 'launchpadlib')
        launchpad = NoNetworkLaunchpad.login_with(
            'very important', service_root=SERVICE_ROOT,
            launchpadlib_dir=launchpadlib_dir)
        self.assertEquals(
            launchpad.credentials.consumer.application_name, 'very important')

        # Now execute the same test a second time. This time, the
        # credentials are loaded from disk and a different code path
        # is executed. We want to make sure this code path propagates
        # the application name, instead of picking an empty one from
        # disk.
        launchpad = NoNetworkLaunchpad.login_with(
            'very important', service_root=SERVICE_ROOT,
            launchpadlib_dir=launchpadlib_dir)
        self.assertEquals(
            launchpad.credentials.consumer.application_name, 'very important')
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:22,代码来源:test_launchpad.py


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