def __init__(self, service_root, application_name=None, consumer_name=None, allow_access_levels=None): """Base class initialization. :param service_root: The root of the Launchpad instance being used. :param application_name: The name of the application that wants to use launchpadlib. This is used in conjunction with a desktop-wide integration. If you specify this argument, your values for consumer_name and allow_access_levels are ignored. :param consumer_name: The OAuth consumer name, for an application that wants its own point of integration into Launchpad. In almost all cases, you want to specify application_name instead and do a desktop-wide integration. The exception is when you're integrating a third-party website into Launchpad. :param allow_access_levels: A list of the Launchpad access levels to present to the user. ('READ_PUBLIC' and so on.) Your value for this argument will be ignored during a desktop-wide integration. :type allow_access_levels: A list of strings. """ self.service_root = uris.lookup_service_root(service_root) self.web_root = uris.web_root_for_service_root(service_root) if application_name is None and consumer_name is None: raise ValueError( "You must provide either application_name or consumer_name.") if application_name is not None and consumer_name is not None: raise ValueError( "You must provide only one of application_name and " "consumer_name. (You provided %r and %r.)" % (application_name, consumer_name)) if consumer_name is None: # System-wide integration. Create a system-wide consumer # and identify the application using a separate # application name. allow_access_levels = ["DESKTOP_INTEGRATION"] consumer = SystemWideConsumer(application_name) else: # Application-specific integration. Use the provided # consumer name to create a consumer automatically. consumer = Consumer(consumer_name) application_name = consumer_name self.consumer = consumer self.application_name = application_name self.allow_access_levels = allow_access_levels or []
def test_default_application_name(self): # Application name defaults to None consumer = Consumer("key", "secret") self.assertEqual(consumer.application_name, None)
def test_data_fields(self): consumer = Consumer("key", "secret", "application") self.assertEqual(consumer.key, "key") self.assertEqual(consumer.secret, "secret") self.assertEqual(consumer.application_name, "application")