Skip to content

Commit 6b53163

Browse files
authored
fix: workflow and pytest for remote execution (#22)
1 parent dba2437 commit 6b53163

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

.github/workflows/flow-cycle-payment-scenarios.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Reset all scenarios
1414
run: |
1515
echo "Resetting all payment scenarios..."
16-
curl -X POST "${{ secrets.SCENARIO_SERVICE_URL }}/scenario-runner/api/payment-scenarios/reset"
16+
curl -X POST "${{ vars.SCENARIO_SERVICE_URL }}/api/payment-scenarios/reset"
1717
sleep 2
1818
1919
- name: Select random scenario
@@ -28,21 +28,21 @@ jobs:
2828
if: steps.random.outputs.scenario == '1'
2929
run: |
3030
echo "Enabling Gateway Timeout scenario (15% probability, 15s delay)"
31-
curl -X POST "${{ secrets.SCENARIO_SERVICE_URL }}/scenario-runner/api/payment-scenarios/gateway-timeout?enabled=true&probability=15.0&delay=15"
31+
curl -X POST "${{ vars.SCENARIO_SERVICE_URL }}/api/payment-scenarios/gateway-timeout?enabled=true&probability=15.0&delay=15"
3232
3333
- name: Enable Card Decline (Scenario 2)
3434
if: steps.random.outputs.scenario == '2'
3535
run: |
3636
echo "Enabling Card Decline scenario (20% probability)"
37-
curl -X POST "${{ secrets.SCENARIO_SERVICE_URL }}/scenario-runner/api/payment-scenarios/card-decline?enabled=true&probability=20.0"
37+
curl -X POST "${{ vars.SCENARIO_SERVICE_URL }}/api/payment-scenarios/card-decline?enabled=true&probability=20.0"
3838
3939
- name: Enable Stolen Card (Scenario 3)
4040
if: steps.random.outputs.scenario == '3'
4141
run: |
4242
echo "Enabling Stolen Card scenario (10% probability)"
43-
curl -X POST "${{ secrets.SCENARIO_SERVICE_URL }}/scenario-runner/api/payment-scenarios/stolen-card?enabled=true&probability=10.0"
43+
curl -X POST "${{ vars.SCENARIO_SERVICE_URL }}/api/payment-scenarios/stolen-card?enabled=true&probability=10.0"
4444
4545
- name: Verify scenario configuration
4646
run: |
4747
echo "Current scenario configuration:"
48-
curl "${{ secrets.SCENARIO_SERVICE_URL }}/scenario-runner/api/payment-scenarios"
48+
curl "${{ vars.SCENARIO_SERVICE_URL }}/api/payment-scenarios"

tests/README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,26 @@ This directory contains automated tests for the Relibank payment failure scenari
2020

2121
## Running the Tests
2222

23-
### Run All Tests
23+
### Run All Tests Locally
2424
```bash
2525
pytest tests/test_payment_scenarios.py -v -s
2626
```
2727

28+
### Run Tests Against Remote Environment
29+
To test against a remote deployment, set the environment variables:
30+
31+
```bash
32+
# Example: Testing against a remote server
33+
export SCENARIO_SERVICE_URL="https://your-server.example.com/scenario-runner"
34+
export BASE_URL="https://your-server.example.com"
35+
pytest tests/test_payment_scenarios.py -v -s
36+
```
37+
38+
Or as a one-liner:
39+
```bash
40+
SCENARIO_SERVICE_URL="https://your-server.example.com/scenario-runner" BASE_URL="https://your-server.example.com" pytest tests/test_payment_scenarios.py -v -s
41+
```
42+
2843
### Run Individual Tests
2944
```bash
3045
# Test gateway timeout scenario
@@ -213,13 +228,14 @@ These tests can be added to GitHub Actions or other CI pipelines:
213228

214229
```yaml
215230
- name: Run payment scenario tests
231+
env:
232+
SCENARIO_SERVICE_URL: ${{ vars.SCENARIO_SERVICE_URL }}
233+
BASE_URL: ${{ vars.BASE_URL }}
216234
run: |
217235
pip install pytest requests
218236
pytest tests/test_payment_scenarios.py -v
219237
```
220238
221-
For CI environments, update service URLs in the test file or use environment variables:
222-
```python
223-
SCENARIO_SERVICE_URL = os.getenv("SCENARIO_SERVICE_URL", "http://localhost:8000")
224-
BILL_PAY_SERVICE_URL = os.getenv("BILL_PAY_SERVICE_URL", "http://localhost:5000")
225-
```
239+
The tests automatically use environment variables for configuration:
240+
- `SCENARIO_SERVICE_URL`: URL to the scenario runner service (default: `http://localhost:8000/scenario-runner`)
241+
- `BASE_URL`: Base URL to the bill pay service (default: `http://localhost:5000`)

tests/test_payment_scenarios.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
import pytest
22
import requests
33
import time
4+
import os
45
from typing import Dict, List
56

6-
# Configuration
7-
SCENARIO_SERVICE_URL = "http://localhost:8000"
8-
BILL_PAY_SERVICE_URL = "http://localhost:5000"
7+
# Configuration - use environment variables with local defaults
8+
SCENARIO_SERVICE_URL = os.getenv("SCENARIO_SERVICE_URL", "http://localhost:8000/scenario-runner")
9+
BILL_PAY_SERVICE_URL = os.getenv("BASE_URL", "http://localhost:5000")
910
NUM_PAYMENT_ATTEMPTS = 50 # Send enough to trigger scenarios
1011

1112
@pytest.fixture
1213
def reset_scenarios():
1314
"""Reset all scenarios before and after tests"""
14-
response = requests.post(f"{SCENARIO_SERVICE_URL}/scenario-runner/api/payment-scenarios/reset")
15+
response = requests.post(f"{SCENARIO_SERVICE_URL}/api/payment-scenarios/reset")
1516
assert response.status_code == 200
1617
yield
1718
# Cleanup after test
18-
requests.post(f"{SCENARIO_SERVICE_URL}/scenario-runner/api/payment-scenarios/reset")
19+
requests.post(f"{SCENARIO_SERVICE_URL}/api/payment-scenarios/reset")
1920

2021

2122
def enable_scenario(scenario_name: str, probability: float = None, delay: float = None) -> Dict:
2223
"""Enable a payment scenario"""
2324
endpoints = {
24-
"gateway_timeout": f"{SCENARIO_SERVICE_URL}/scenario-runner/api/payment-scenarios/gateway-timeout",
25-
"card_decline": f"{SCENARIO_SERVICE_URL}/scenario-runner/api/payment-scenarios/card-decline",
26-
"stolen_card": f"{SCENARIO_SERVICE_URL}/scenario-runner/api/payment-scenarios/stolen-card"
25+
"gateway_timeout": f"{SCENARIO_SERVICE_URL}/api/payment-scenarios/gateway-timeout",
26+
"card_decline": f"{SCENARIO_SERVICE_URL}/api/payment-scenarios/card-decline",
27+
"stolen_card": f"{SCENARIO_SERVICE_URL}/api/payment-scenarios/stolen-card"
2728
}
2829

2930
params = {"enabled": True}
@@ -196,7 +197,7 @@ def test_scenario_reset(reset_scenarios):
196197
enable_scenario("stolen_card", probability=100.0)
197198

198199
# Reset all scenarios
199-
response = requests.post(f"{SCENARIO_SERVICE_URL}/scenario-runner/api/payment-scenarios/reset")
200+
response = requests.post(f"{SCENARIO_SERVICE_URL}/api/payment-scenarios/reset")
200201
assert response.status_code == 200
201202
print("Reset all scenarios")
202203

0 commit comments

Comments
 (0)