Skip to content

Commit a7e6d64

Browse files
authored
Merge pull request #32 from talon-one/add-test-workflow
add test workflow
2 parents 710fca9 + 5d3199c commit a7e6d64

File tree

4 files changed

+193
-2
lines changed

4 files changed

+193
-2
lines changed

.github/workflows/test.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: run tests
2+
3+
on: [push]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
permissions:
9+
contents: 'read'
10+
id-token: 'write'
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Authenticate to Google Cloud
15+
id: auth
16+
uses: google-github-actions/auth@v1
17+
with:
18+
token_format: access_token
19+
workload_identity_provider: projects/949875736540/locations/global/workloadIdentityPools/external-pool/providers/github-provider
20+
service_account: artifact-pusher@talon-artifacts.iam.gserviceaccount.com
21+
- name: Login to GAR
22+
uses: docker/login-action@v3
23+
with:
24+
registry: europe-west3-docker.pkg.dev
25+
username: oauth2accesstoken
26+
password: ${{ steps.auth.outputs.access_token }}
27+
- uses: hoverkraft-tech/compose-action@v2.0.2
28+
- name: Set up Python
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: '3.x'
32+
- name: Install dependencies
33+
run: |
34+
python -m pip install --upgrade pip
35+
pip install -r requirements.txt
36+
sudo apt-get install jq curl
37+
- name: Run example
38+
run: |
39+
ACCOUNT_RESPONSE=$(curl -s --location "http://localhost:9000/v1/accounts" \
40+
--header "Content-Type: application/json" \
41+
--data-raw '{
42+
"companyName": "demo",
43+
"email": "integrationtest@talon.one",
44+
"password": "Password1234!"
45+
}');
46+
export TALON_USER_ID=$(echo $ACCOUNT_RESPONSE | jq ".userId");
47+
export TALON_USER_TOKEN=$(echo $ACCOUNT_RESPONSE | jq ".token" | tr -d '"');
48+
USER_RESPONSE=$(curl -s --location "http://localhost:9000/v1/users/$TALON_USER_ID" \
49+
--header "Authorization: Bearer $TALON_USER_TOKEN");
50+
export TALON_ACCOUNT_ID=$(echo $USER_RESPONSE | jq ".accountId");
51+
echo "User with ID $TALON_USER_ID and Token $TALON_USER_TOKEN was created for application $TALON_ACCOUNT_ID";
52+
53+
APPLICATION_RESPONSE=$(curl -s --location "http://localhost:9000/v1/applications" \
54+
--header "Content-Type: application/json" \
55+
--header "Authorization: Bearer $TALON_USER_TOKEN" \
56+
--data-raw '{
57+
"name": "demo",
58+
"currency": "EUR",
59+
"timezone": "Europe/Berlin",
60+
"enableFlattenedCartItems": false
61+
}');
62+
export TALON_APPLICATION_ID=$(echo $USER_RESPONSE | jq ".id");
63+
echo "Application with ID $TALON_APPLICATION_ID was created"
64+
65+
API_KEY_RESPONSE=$(curl -s -v --location "http://localhost:9000/v1/applications/$TALON_APPLICATION_ID/apikeys" \
66+
--header "Content-Type: application/json" \
67+
--header "Authorization: Bearer $TALON_USER_TOKEN" \
68+
--data-raw '{
69+
"title": "Application HIT KEY",
70+
"expires": "2099-01-01T0:00:00Z"
71+
}');
72+
echo "Api-Key-Response: $API_KEY_RESPONSE";
73+
export TALON_API_KEY=$(echo $API_KEY_RESPONSE | jq ".key" | tr -d '"');
74+
echo "Api-Key $TALON_API_KEY created"
75+
python example.py;

docker-compose.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
services:
2+
api-service:
3+
image: europe-west3-docker.pkg.dev/talon-artifacts/talon-images/talon-service:master
4+
depends_on:
5+
- database-service
6+
ports:
7+
- "9000:9000"
8+
environment:
9+
- TALON_DB_NAME=talon
10+
- TALON_DB_USER=talon
11+
- TALON_DB_PASSWORD=talon.one.9000
12+
- TALON_DB_HOST=database-service
13+
- TALON_DB_PORT=5432
14+
- TALON_ENABLE_WEBHOOK_WORKER_POOL=false
15+
- TZ=UTC
16+
- RELEASE_STAGE=ci
17+
- TALON_CH_ENABLED=false
18+
- TALON_DISABLE_PROFILER=true
19+
- USE_REPLICA_DB=false
20+
command:
21+
- /talon/talon
22+
healthcheck:
23+
test: ["CMD", "curl", "-f", "http://localhost:9000/v1/status/health"]
24+
interval: 10s
25+
timeout: 5s
26+
retries: 10
27+
restart: "on-failure:10"
28+
29+
database-service:
30+
image: docker.io/bitnami/postgresql:15
31+
volumes:
32+
- 'postgresql_master_data:/bitnami/postgresql'
33+
ports:
34+
- "5433:5432"
35+
environment:
36+
- POSTGRESQL_DATABASE=talon
37+
- POSTGRESQL_USERNAME=talon
38+
- POSTGRESQL_PASSWORD=talon.one.9000
39+
healthcheck:
40+
test: ["CMD-SHELL", "pg_isready -U talon -d talon"]
41+
interval: 10s
42+
timeout: 5s
43+
retries: 5
44+
restart: "on-failure:10"
45+
46+
volumes:
47+
postgresql_master_data:

example.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import talon_one
2+
from talon_one.rest import ApiException
3+
from pprint import pprint
4+
import json
5+
import os
6+
7+
# Create configuration with your host destination and authorization using api_key_v1
8+
configuration = talon_one.Configuration(
9+
host = "http://localhost:9000",
10+
api_key_prefix = {
11+
"Authorization": "ApiKey-v1"
12+
},
13+
api_key = {
14+
"Authorization": os.environ["TALON_API_KEY"]
15+
}
16+
)
17+
18+
# Integration API example to send a session update
19+
integration_api = talon_one.IntegrationApi(talon_one.ApiClient(configuration))
20+
21+
# Preparing a NewCustomerSessionV2 object
22+
customer_session = talon_one.NewCustomerSessionV2(
23+
"PROFILE_ID"
24+
)
25+
customer_session.cart_items = [
26+
talon_one.CartItem(name="Red Spring Blouse",
27+
sku="rdbs-1111",
28+
quantity=1,
29+
price=49,
30+
category="Shirts"),
31+
talon_one.CartItem(name="Denim Trousers",
32+
sku="dtr-2222",
33+
quantity=1,
34+
price=74,
35+
category="Trousers"),
36+
]
37+
customer_session.coupon_codes = [
38+
"Cool_Stuff"
39+
]
40+
41+
# Instantiating a new IntegrationRequest object
42+
integration_request = talon_one.IntegrationRequest(
43+
customer_session,
44+
# Optional list of requested information to be present on the response.
45+
# See models/integration_request.py for full list
46+
# ["customerSession", "loyalty"]
47+
)
48+
49+
# Create/update a customer session using `update_customer_session_v2` function
50+
api_response = integration_api.update_customer_session_v2("my_unique_session_v2_id", integration_request)
51+
encoded_data = json.dumps(api_response.to_dict(), default=str)
52+
pprint(encoded_data)
53+
54+
# Parsing the returned effects list, please consult https://developers.talon.one/Integration-API/handling-effects-v2 for the full list of effects and their corresponding properties
55+
for effect in api_response.effects:
56+
if effect.effect_type == "setDiscount":
57+
# Initiating right props instance according to the effect type
58+
setDiscountProps = integration_api.api_client.deserialize_model(effect.props, talon_one.SetDiscountEffectProps)
59+
60+
# Access the specific effect's properties
61+
print("Set a discount '{name}' of {value}".format(
62+
name = setDiscountProps.name,
63+
value = setDiscountProps.value
64+
))
65+
elif effect.effect_type == "rejectCoupon":
66+
rejectCouponEffectProps = integration_api.api_client.deserialize_model(effect.props, talon_one.RejectCouponEffectProps)
67+
68+
# Work with AcceptCouponEffectProps' properties
69+
# ...

test-requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
pytest~=4.6.7 # needed for python 2.7+3.4
1+
pytest~=8.3.3 # needed for python 2.7+3.4
22
pytest-cov>=2.8.1
3-
pytest-randomly==1.2.3 # needed for python 2.7+3.4
3+
pytest-randomly==3.16.0 # needed for python 2.7+3.4

0 commit comments

Comments
 (0)