def test_app_services(self, init_app): service = utils.get_app_service(init_app, 'test.service', AppService) assert isinstance(service, AppService) service2 = utils.get_app_service(init_app, 'test.service', AppService) assert service is service2 firebase_admin.delete_app(init_app) with pytest.raises(ValueError): utils.get_app_service(init_app, 'test.service', AppService)
def _get_token_generator(app): """Returns a _TokenGenerator instance for an App. If the App already has a _TokenGenerator associated with it, simply returns it. Otherwise creates a new _TokenGenerator, and adds it to the App before returning it. Args: app: A Firebase App instance (or None to use the default App). Returns: _TokenGenerator: A _TokenGenerator for the specified App instance. Raises: ValueError: If the app argument is invalid. """ return utils.get_app_service(app, _AUTH_ATTRIBUTE, _TokenGenerator)
def reference(path='/', app=None): """Returns a database Reference representing the node at the specified path. If no path is specified, this function returns a Reference that represents the database root. Args: path: Path to a node in the Firebase realtime database (optional). app: An App instance (optional). Returns: Reference: A newly initialized Reference. Raises: ValueError: If the specified path or app is invalid. """ client = utils.get_app_service(app, _DB_ATTRIBUTE, _Client.from_app) return Reference(client=client, path=path)
def bucket(name=None, app=None): """Returns a handle to a Google Cloud Storage bucket. If the name argument is not provided, uses the 'storageBucket' option specified when initializing the App. If that is also not available raises an error. This function does not make any RPC calls. Args: name: Name of a cloud storage bucket (optional). app: An App instance (optional). Returns: google.cloud.storage.Bucket: A handle to the specified bucket. Raises: ValueError: If a bucket name is not specified either via options or method arguments, or if the specified bucket name is not a valid string. """ client = utils.get_app_service(app, _STORAGE_ATTRIBUTE, _StorageClient.from_app) return client.bucket(name)