Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing an app should not require GCP credentials #609

Open
thclark opened this issue Oct 9, 2023 · 1 comment
Open

Testing an app should not require GCP credentials #609

thclark opened this issue Oct 9, 2023 · 1 comment
Labels
test Implement or update unit tests user experience (UX) Key UX issues

Comments

@thclark
Copy link
Contributor

thclark commented Oct 9, 2023

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 = <tests.test_app.TestApp testMethod=test_evaluate>

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 thclark added test Implement or update unit tests user experience (UX) Key UX issues labels Oct 9, 2023
@thclark
Copy link
Contributor Author

thclark commented Oct 9, 2023

Closely related to #600

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Implement or update unit tests user experience (UX) Key UX issues
Projects
Status: Priority 2 (Medium)
Development

No branches or pull requests

1 participant