-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This reverts commit 7ed21c8. Co-authored-by: Steve Bunting <[email protected]>
- Loading branch information
1 parent
7ed21c8
commit 46c7414
Showing
20 changed files
with
433 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,79 @@ | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
|
||
from supergood import Client | ||
from tests.helper import get_config, get_remote_config | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
@pytest.fixture(scope="session") | ||
def broken_redaction(session_mocker): | ||
session_mocker.patch( | ||
"supergood.client.redact_values", side_effect=Exception | ||
).start() | ||
yield session_mocker | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def monkeysession(): | ||
with pytest.MonkeyPatch.context() as mp: | ||
yield mp | ||
|
||
|
||
@pytest.fixture | ||
def supergood_client(request, mocker): | ||
with pytest.MonkeyPatch.context() as mp: | ||
config = get_config() | ||
remote_config = get_remote_config() | ||
|
||
if getattr(request, "param", None): | ||
if request.param.get("config", None): | ||
config = request.param["config"] | ||
if request.param.get("remote_config", None): | ||
remote_config = request.param["remote_config"] | ||
|
||
Client.initialize( | ||
client_id="client_id", | ||
client_secret_id="client_secret_id", | ||
base_url="https://api.supergood.ai", | ||
telemetry_url="https://telemetry.supergood.ai", | ||
config=config, | ||
) | ||
# first 3 are just to make sure we don't post anything externally | ||
mocker.patch("supergood.api.Api.post_events", return_value=None).start() | ||
mocker.patch("supergood.api.Api.post_errors", return_value=None).start() | ||
mocker.patch("supergood.api.Api.post_telemetry", return_value=None).start() | ||
# next we make sure we don't call get externally, and stub in our remote config | ||
mocker.patch("supergood.api.Api.get_config", return_value=remote_config).start() | ||
# Turns off the worker, pytest mocks don't always play well with threads | ||
mocker.patch("supergood.worker.Worker.start", return_value=None).start() | ||
mocker.patch("supergood.worker.Repeater.start", return_value=None).start() | ||
mocker.patch("supergood.worker.Worker.append", return_value=True).start() | ||
mp.setenv("SG_OVERRIDE_AUTO_FLUSH", "false") | ||
mp.setenv("SG_OVERRIDE_AUTO_CONFIG", "false") | ||
Client._get_config() | ||
yield Client | ||
Client.kill() | ||
@pytest.fixture(scope="session") | ||
def broken_client(broken_redaction, monkeysession): | ||
config = get_config() | ||
remote_config = get_remote_config() | ||
broken_redaction.patch("supergood.api.Api.post_events", return_value=None).start() | ||
broken_redaction.patch("supergood.api.Api.post_errors", return_value=None).start() | ||
broken_redaction.patch( | ||
"supergood.api.Api.get_config", return_value=remote_config | ||
).start() | ||
Client.initialize( | ||
client_id="client_id", | ||
client_secret_id="client_secret_id", | ||
base_url="https://api.supergood.ai", | ||
telemetry_url="https://telemetry.supergood.ai", | ||
config=config, | ||
) | ||
monkeysession.setenv("SG_OVERRIDE_AUTO_FLUSH", "false") | ||
monkeysession.setenv("SG_OVERRIDE_AUTO_CONFIG", "false") | ||
Client._get_config() | ||
yield Client | ||
Client.kill() # on exit | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def supergood_client(request, session_mocker, monkeysession): | ||
# Allows for a param dictionary to control behavior | ||
# currently looks for "config" "remote_config" and "auto" | ||
config = get_config() | ||
auto = False | ||
remote_config = get_remote_config() | ||
if getattr(request, "param", None): | ||
if request.param.get("config", None): | ||
config = request.param["config"] | ||
if request.param.get("remote_config", None): | ||
remote_config = request.param["remote_config"] | ||
if request.param.get("auto", None): | ||
auto = request.param["auto"] | ||
|
||
session_mocker.patch("supergood.api.Api.post_events", return_value=None).start() | ||
session_mocker.patch("supergood.api.Api.post_errors", return_value=None).start() | ||
session_mocker.patch( | ||
"supergood.api.Api.get_config", return_value=remote_config | ||
).start() | ||
session_mocker.patch("supergood.api.Api.post_telemetry", return_value=None).start() | ||
|
||
if not auto: | ||
monkeysession.setenv("SG_OVERRIDE_AUTO_FLUSH", "false") | ||
monkeysession.setenv("SG_OVERRIDE_AUTO_CONFIG", "false") | ||
|
||
Client.initialize( | ||
client_id="client_id", | ||
client_secret_id="client_secret_id", | ||
base_url="https://api.supergood.ai", | ||
telemetry_url="https://telemetry.supergood.ai", | ||
config=config, | ||
) | ||
Client._get_config() | ||
yield Client | ||
Client.kill() # on exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.