Skip to content

Make octue services easy to test and patch #658

Closed
@nvn-nil

Description

@nvn-nil

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions