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
2 changes: 1 addition & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: pipenv run pytest -v --cov=./switcher_client --cov-report xml --cov-config=.coveragerc

- name: SonarCloud Scan
uses: sonarsource/sonarqube-scan-action@v7.1.0
uses: sonarsource/sonarqube-scan-action@v8.0.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: env.SONAR_TOKEN != ''
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: pipenv run pytest -v --cov=./switcher_client --cov-report xml

- name: SonarCloud Scan
uses: sonarsource/sonarqube-scan-action@v7.1.0
uses: sonarsource/sonarqube-scan-action@v8.0.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: env.SONAR_TOKEN != ''
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,23 @@ switcher.remote().is_on('FEATURE01')

### Loading Snapshots

Load configuration snapshots from the API for local/offline usage:
Load snapshots from the API or local files:

```python
# Download and save snapshot from API
# Load snapshot from local file
Client.load_snapshot()
```

```python
# Load snapshot from API with fetch_remote option
Client.load_snapshot(LoadSnapshotOptions(fetch_remote=True))
```

```python
# Load snapshot with watch option to update the client in real-time when file changes
Client.load_snapshot(LoadSnapshotOptions(watch_snapshot=True))
```

### Version Management

Check your current snapshot version:
Expand Down
3 changes: 3 additions & 0 deletions switcher_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ def load_snapshot(options: Optional[LoadSnapshotOptions] = None) -> int:
if Client._is_check_snapshot_available(snapshot_options.fetch_remote):
Client.check_snapshot()

if snapshot_options.watch_snapshot:
Client.watch_snapshot()

return Client.snapshot_version()

@staticmethod
Expand Down
26 changes: 26 additions & 0 deletions tests/test_client_watch_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from switcher_client.client import Client, ContextOptions
from switcher_client.lib.snapshot_watcher import SnapshotWatcher, WatchSnapshotCallback
from switcher_client.lib.globals.global_snapshot import LoadSnapshotOptions

context_options_local = ContextOptions(local=True, snapshot_location='tests/snapshots/temp')
async_error = None
Expand Down Expand Up @@ -56,6 +57,31 @@ def test_watch_snapshot(self):
else:
print("Warning: Snapshot watcher did not detect the change within the time limit")

def test_watch_snapshot_from_load_snapshot(self):
""" Should watch the snapshot file when load_snapshot is called with watch_snapshot option """

fixture_env = 'default_load_1'
fixture_env_file_modified = 'tests/snapshots/default_load_2.json'
fixture_location = 'tests/snapshots/temp'

# given
modify_fixture_snapshot(fixture_location, fixture_env, f'tests/snapshots/{fixture_env}.json')
given_context(options=context_options_local, environment=fixture_env)

# test
Client.load_snapshot(LoadSnapshotOptions(watch_snapshot=True))
switcher = Client.get_switcher('FF2FOR2030')

assert switcher.is_on()
modify_fixture_snapshot(fixture_location, fixture_env, fixture_env_file_modified)

# then
verified = verify_util(30, lambda: switcher.is_on() == False)
if verified:
assert switcher.is_on() == False
else:
print("Warning: Snapshot watcher did not detect the change within the time limit")

def test_watch_snapshot_err_no_snapshot_location(self):
""" Should reject with error when snapshot location is not defined in the context options """

Expand Down
Loading