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

Make octue services easy to test and patch #658

Open
nvn-nil opened this issue May 20, 2024 · 0 comments
Open

Make octue services easy to test and patch #658

nvn-nil opened this issue May 20, 2024 · 0 comments

Comments

@nvn-nil
Copy link

nvn-nil commented May 20, 2024

Feature request

Use Case

Create Google Cloud clients only as required to make it easy to test applications using octue. I recommend reviewing other uses of Google clients too.

Or maybe provide an escape hatch by providing an offline/local mode for tests.

Thanks in advance!

Current state

The clients for different google services are created in the init function. This makes patching very difficult for tests.

I'm monkey-patching this particular one in my tests. This was easier than patching many other functions that use the client when I'm only doing local unit tests.

# Monkey patch the unnecessary credential check in init
def diagnostics_init(self, cloud_path):
    self.cloud_path = cloud_path
    self.analysis_id = None
    self.configuration_values = None
    self.configuration_manifest = None
    self.input_values = None
    self.input_manifest = None
    self.questions = []


@cached_property
def diagnostic_storage_client_property(self):
    return GoogleCloudStorageClient()


Diagnostics.__init__ = diagnostics_init
Diagnostics._storage_client = diagnostic_storage_client_property

This is obviously not ideal for a variety of reasons but was easier in my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant