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_ml_service(app):
    """ Returns an _MLService instance for an App.

    Args:
      app: A Firebase App instance (or None to use the default App).

    Returns:
      _MLService: An _MLService for the specified App instance.

    Raises:
      ValueError: If the app argument is invalid.
    """
    return _utils.get_app_service(app, _ML_ATTRIBUTE, _MLService)
Beispiel #3
0
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)
Beispiel #4
0
def _get_client(app):
    """Returns a client instance for an App.

    If the App already has a client associated with it, simply returns
    it. Otherwise creates a new client, and adds it to the App before
    returning it.

    Args:
        app: A Firebase App instance (or ``None`` to use the default App).

    Returns:
        Client: A client for the specified App instance.

    Raises:
        ValueError: If the app argument is invalid.
    """
    return _utils.get_app_service(app, _AUTH_ATTRIBUTE, Client)
Beispiel #5
0
def _get_auth_service(app):
    """Returns an _AuthService instance for an App.

    If the App already has an _AuthService associated with it, simply returns
    it. Otherwise creates a new _AuthService, and adds it to the App before
    returning it.

    Args:
      app: A Firebase App instance (or None to use the default App).

    Returns:
      _AuthService: An _AuthService for the specified App instance.

    Raises:
      ValueError: If the app argument is invalid.
    """
    return _utils.get_app_service(app, _AUTH_ATTRIBUTE, _AuthService)
def client(app=None):
    """Returns a client that can be used to interact with Google Cloud Firestore.

    Args:
      app: An App instance (optional).

    Returns:
      google.cloud.firestore.Firestore: A `Firestore Client`_.

    Raises:
      ValueError: If a project ID is not specified either via options, credentials or
          environment variables, or if the specified project ID is not a valid string.

    .. _Firestore Client: https://googlecloudplatform.github.io/google-cloud-python/latest\
          /firestore/client.html
    """
    fs_client = _utils.get_app_service(app, _FIRESTORE_ATTRIBUTE, _FirestoreClient.from_app)
    return fs_client.get()
Beispiel #7
0
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)
Beispiel #8
0
def reference(path='/', app=None, url=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. By default, the returned References provide access to the Firebase Database specified at
    app initialization. To connect to a different database instance in the same Firebase project,
    specify the ``url`` parameter.

    Args:
      path: Path to a node in the Firebase realtime database (optional).
      app: An App instance (optional).
      url: Base URL of the Firebase Database instance (optional). When specified, takes
          precedence over the the ``databaseURL`` option set at app initialization.

    Returns:
      Reference: A newly initialized Reference.

    Raises:
      ValueError: If the specified path or app is invalid.
    """
    service = _utils.get_app_service(app, _DB_ATTRIBUTE, _DatabaseService)
    client = service.get_client(url)
    return Reference(client=client, path=path)
Beispiel #9
0
def _get_iid_service(app):
    return _utils.get_app_service(app, _IID_ATTRIBUTE, _InstanceIdService)
Beispiel #10
0
def _get_messaging_service(app):
    return _utils.get_app_service(app, _MESSAGING_ATTRIBUTE, _MessagingService)
Beispiel #11
0
def _get_project_management_service(app):
    return _utils.get_app_service(app, _PROJECT_MANAGEMENT_ATTRIBUTE, _ProjectManagementService)
Beispiel #12
0
def _get_tenant_mgt_service(app):
    return _utils.get_app_service(app, _TENANT_MGT_ATTRIBUTE,
                                  _TenantManagementService)
 def test_app_services_invalid_app(self, init_app):
     app = firebase_admin.App(init_app.name, init_app.credential, {})
     with pytest.raises(ValueError):
         _utils.get_app_service(app, 'test.service', AppService)
 def test_app_services_invalid_arg(self, arg):
     with pytest.raises(ValueError):
         _utils.get_app_service(arg, 'test.service', AppService)
Beispiel #15
0
    def reference(self, path='/', app=None, url=None):

        service = _utils.get_app_service(app, _DB_ATTRIBUTE, _DatabaseService)
        client = service.get_client(url)
        return Reference(client=client, path=path)
def _get_remote_config_management_service(app):
    return _utils.get_app_service(app, _REMOTE_CONFIG_MANAGEMENT_ATTRIBUTE, _RemoteConfigManagementService)