octue / octue-sdk-python

The python SDK for @Octue services and digital twins.
https://octue.com
Other
10 stars 4 forks source link

Testing an app should not require GCP credentials #609

Open thclark opened 1 year ago

thclark commented 1 year ago

Feature request

Use Case

It should be as easy as possible to develop a service. Ideally, we want to be able to provide a testing framework for applications so that anyone can write an test an applicaiton without spinning up any infrastructure on GCP.

Testing a service should not require valid GCP credentials; because we should be able to mock every interaction with GCP in the test harness.

Current state

Click to see the error you get if you try to test an app without a valid set of credentials ``` ________________________________________________________ TestApp.test_evaluate _________________________________________________________ self = def test_evaluate(self): """Test that the app can run an evaluation and return it.""" > runner = Runner(app_src=App, twine=TWINE) tests/test_app.py:152: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/local/lib/python3.11/site-packages/octue/runner.py:71: in __init__ self.crash_diagnostics = CrashDiagnostics(cloud_path=crash_diagnostics_cloud_path) /usr/local/lib/python3.11/site-packages/octue/crash_diagnostics.py:32: in __init__ self._storage_client = GoogleCloudStorageClient() /usr/local/lib/python3.11/site-packages/octue/cloud/storage/client.py:41: in __init__ self.credentials, self.project_name = auth.default() /usr/local/lib/python3.11/site-packages/google/auth/_default.py:657: in default credentials, project_id = checker() /usr/local/lib/python3.11/site-packages/google/auth/_default.py:650: in lambda: _get_explicit_environ_credentials(quota_project_id=quota_project_id), /usr/local/lib/python3.11/site-packages/google/auth/_default.py:270: in _get_explicit_environ_credentials credentials, project_id = load_credentials_from_file( _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ filename = '/path/to/a/nonexisting/credentials/file.json', scopes = None, default_scopes = None quota_project_id = None, request = None def load_credentials_from_file( filename, scopes=None, default_scopes=None, quota_project_id=None, request=None ): """Loads Google credentials from a file. The credentials file must be a service account key, stored authorized user credentials, external account credentials, or impersonated service account credentials. Args: filename (str): The full path to the credentials file. scopes (Optional[Sequence[str]]): The list of scopes for the credentials. If specified, the credentials will automatically be scoped if necessary default_scopes (Optional[Sequence[str]]): Default scopes passed by a Google client library. Use 'scopes' for user-defined scopes. quota_project_id (Optional[str]): The project ID used for quota and billing. request (Optional[google.auth.transport.Request]): An object used to make HTTP requests. This is used to determine the associated project ID for a workload identity pool resource (external account credentials). If not specified, then it will use a google.auth.transport.requests.Request client to make requests. Returns: Tuple[google.auth.credentials.Credentials, Optional[str]]: Loaded credentials and the project ID. Authorized user credentials do not have the project ID information. External account credentials project IDs may not always be determined. Raises: google.auth.exceptions.DefaultCredentialsError: if the file is in the wrong format or is missing. """ if not os.path.exists(filename): > raise exceptions.DefaultCredentialsError( "File {} was not found.".format(filename) ) E google.auth.exceptions.DefaultCredentialsError: File /path/to/a/nonexisting/credentials/file.json was not found. /usr/local/lib/python3.11/site-packages/google/auth/_default.py:114: DefaultCredentialsError ```
thclark commented 1 year ago

Closely related to #600