Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions datareservoirio/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,29 @@ def set_dev(self):
_constants.APPLICATIONINSIGHTS_DEV_CONNECTIONSTRING
)

def set_api_base_url(self, base_url):
"""
Point the client at a custom DataReservoir.io API base URL.

Intended for development/testing against a mock server. The
environment is marked as DEV, so telemetry (if explicitly enabled)
uses the DEV config and does not leak to the production resource.

Parameters
----------
base_url : str
Full API base URL including the ``/api/`` suffix, e.g.
``"http://localhost:5824/api/"``. A trailing slash is added if
missing.
"""
if not base_url.endswith("/"):
base_url = base_url + "/"
self._set_environment(_constants.ENV_DEV)
self._set_base_url(base_url)
self._set_application_insight_connectionstring(
_constants.APPLICATIONINSIGHTS_DEV_CONNECTIONSTRING
)

def _set_environment(self, environment):
self._logger.info(f"Setting environment to: {environment}")
self.current_environment = environment
Expand Down
13 changes: 13 additions & 0 deletions tests/test_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ def test_set_dev(self, environment):
== _constants.APPLICATIONINSIGHTS_DEV_CONNECTIONSTRING
)

def test_set_api_base_url(self, environment):
environment.set_api_base_url("http://drio-mock.gov:1337/api/")
assert environment.current_environment == "DEV"
assert environment.api_base_url == "http://drio-mock.gov:1337/api/"
assert (
environment._application_insight_connectionstring
== _constants.APPLICATIONINSIGHTS_DEV_CONNECTIONSTRING
)

def test_set_api_base_url_adds_trailing_slash(self, environment):
environment.set_api_base_url("http://localhost:42/api")
assert environment.api_base_url == "http://localhost:42/api/"

def test__set_environment(self, environment):
environment._set_environment("QA")
assert environment.current_environment == "QA"
Expand Down
Loading