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
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ pylint = "==4.0.5"
pytest = "==9.0.2"
pytest-cov = "==7.1.0"
pytest-httpx = "==0.36.0"
python-dotenv = "==1.2.2"
typing-extensions = "4.15.0"
switcher-client = {file = ".", editable = true}
11 changes: 10 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions tests/playground/index.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import threading
import time
import os

from .util import monitor_run
from dotenv import load_dotenv

from util import monitor_run
from switcher_client.lib.globals.global_context import DEFAULT_ENVIRONMENT
from switcher_client.lib.globals.global_snapshot import LoadSnapshotOptions
from switcher_client import Client, ContextOptions, WatchSnapshotCallback

load_dotenv()
API_KEY = os.getenv('SWITCHER_API_KEY')
SWITCHER_KEY = 'CLIENT_PYTHON_FEATURE'
LOOP = True

def setup_context(options: ContextOptions = ContextOptions(), environment = DEFAULT_ENVIRONMENT):
Client.build_context(
domain='Switcher API',
url='https://api.switcherapi.com',
api_key='[API_KEY]',
api_key=API_KEY,
component='switcher-client-python',
environment=environment,
options=options
Expand Down Expand Up @@ -112,7 +117,7 @@ def uc_watch_snapshot():

try:
# Replace with use case
uc_watch_snapshot()
uc_simple_api_call()
while LOOP:
time.sleep(1)
except KeyboardInterrupt:
Expand Down
71 changes: 71 additions & 0 deletions tests/test_switcher_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import os

from dotenv import load_dotenv

from switcher_client.client import Client
from switcher_client.lib.globals.global_context import ContextOptions
from switcher_client.lib.globals.global_snapshot import LoadSnapshotOptions

load_dotenv()
API_KEY = os.getenv('SWITCHER_API_KEY')
WARN_SKIP = 'API key not found. Please set the SWITCHER_API_KEY environment variable.'

def test_is_on():
""" Should call the remote API with success """

if not API_KEY:
print(WARN_SKIP)
return

# given
given_context()
switcher = Client.get_switcher('CLIENT_PYTHON_FEATURE')

# test
response_detail = switcher.is_on_with_details()
assert response_detail is not None

def test_load_snapshot():
""" Should load the snapshot from the remote API with success """

if not API_KEY:
print(WARN_SKIP)
return

# given
given_context(options=ContextOptions(local=True))

# test
snapshot = Client.load_snapshot(options=LoadSnapshotOptions(fetch_remote=True))
switcher = Client.get_switcher('CLIENT_PYTHON_FEATURE')
response_detail = switcher.is_on_with_details()

assert snapshot is not None
assert response_detail is not None

def test_check_switcher_availability():
""" Should check the switcher availability with success """

if not API_KEY:
print(WARN_SKIP)
return

# given
given_context()

# test
try:
Client.check_switchers(['CLIENT_PYTHON_FEATURE'])
except Exception as e:
assert False, f'check_switchers should not raise an exception, but got: {e}'

# Helpers

def given_context(options=ContextOptions()):
Client.build_context(
url='https://api.switcherapi.com',
api_key=API_KEY,
domain='Switcher API',
component='switcher-client-python',
options=options
)
Loading