Skip to content

Commit

Permalink
add test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Neokil committed Nov 25, 2024
1 parent 710fca9 commit 99d7a40
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 2 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: run tests

on: [push]

jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'

steps:
- uses: actions/checkout@v4
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v1
with:
token_format: access_token
workload_identity_provider: projects/949875736540/locations/global/workloadIdentityPools/external-pool/providers/github-provider
service_account: [email protected]
- name: Login to GAR
uses: docker/login-action@v3
with:
registry: europe-west3-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
- uses: hoverkraft-tech/[email protected]
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
sudo apt-get install jq curl
- name: Run example
run: |
ACCOUNT_RESPONSE=$(curl -v --location "http://localhost:9000/v1/accounts" \
--header "Content-Type: application/json" \
--data-raw '{
"companyName": "demo",
"email": "[email protected]",
"password": "Password1234!"
}');
export TALON_USER_ID=$(echo $ACCOUNT_RESPONSE | jq ".userId");
export TALON_USER_TOKEN=$(echo $ACCOUNT_RESPONSE | jq ".token");
USER_RESPONSE=$(curl -v --location "http://localhost:9000/v1/users/$TALON_USER_ID" \
--header "Authorization: $TALON_USER_TOKEN");
export TALON_ACCOUNT_ID=$(echo $USER_RESPONSE | jq ".accountId");
echo "User with ID $TALON_USER_ID and Token $TALON_USER_TOKEN was created for application $TALON_ACCOUNT_ID";
export TALON_API_KEY=$(curl -v --location "http://localhost:9000/v1/applications/$TALON_ACCOUNT_ID/apikeys" \
--header "Content-Type: application/json" \
--header "Authorization: $TALON_USER_TOKEN" \
--data-raw '{
"title": "Application HIT KEY",
"expires": "2099-01-01T0:00:00Z,
}' | jq ".apiKey");
echo "Api-Key $TALON_API_KEY created"
python example.py;
47 changes: 47 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
services:
api-service:
image: europe-west3-docker.pkg.dev/talon-artifacts/talon-images/talon-service:master
depends_on:
- database-service
ports:
- "9000:9000"
environment:
- TALON_DB_NAME=talon
- TALON_DB_USER=talon
- TALON_DB_PASSWORD=talon.one.9000
- TALON_DB_HOST=database-service
- TALON_DB_PORT=5432
- TALON_ENABLE_WEBHOOK_WORKER_POOL=false
- TZ=UTC
- RELEASE_STAGE=ci
- TALON_CH_ENABLED=false
- TALON_DISABLE_PROFILER=true
- USE_REPLICA_DB=false
command:
- /talon/talon
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/v1/status/health"]
interval: 10s
timeout: 5s
retries: 10
restart: "on-failure:10"

database-service:
image: docker.io/bitnami/postgresql:15
volumes:
- 'postgresql_master_data:/bitnami/postgresql'
ports:
- "5433:5432"
environment:
- POSTGRESQL_DATABASE=talon
- POSTGRESQL_USERNAME=talon
- POSTGRESQL_PASSWORD=talon.one.9000
healthcheck:
test: ["CMD-SHELL", "pg_isready -U talon -d talon"]
interval: 10s
timeout: 5s
retries: 5
restart: "on-failure:10"

volumes:
postgresql_master_data:
69 changes: 69 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import talon_one
from talon_one.rest import ApiException
from pprint import pprint
import json
import os

# Create configuration with your host destination and authorization using api_key_v1
configuration = talon_one.Configuration(
host = "http://localhost:9000",
api_key_prefix = {
"Authorization": "ApiKey-v1"
},
api_key = {
"Authorization": os.environ["TALON_API_KEY"]
}
)

# Integration API example to send a session update
integration_api = talon_one.IntegrationApi(talon_one.ApiClient(configuration))

# Preparing a NewCustomerSessionV2 object
customer_session = talon_one.NewCustomerSessionV2(
"PROFILE_ID"
)
customer_session.cart_items = [
talon_one.CartItem(name="Red Spring Blouse",
sku="rdbs-1111",
quantity=1,
price=49,
category="Shirts"),
talon_one.CartItem(name="Denim Trousers",
sku="dtr-2222",
quantity=1,
price=74,
category="Trousers"),
]
customer_session.coupon_codes = [
"Cool_Stuff"
]

# Instantiating a new IntegrationRequest object
integration_request = talon_one.IntegrationRequest(
customer_session,
# Optional list of requested information to be present on the response.
# See models/integration_request.py for full list
# ["customerSession", "loyalty"]
)

# Create/update a customer session using `update_customer_session_v2` function
api_response = integration_api.update_customer_session_v2("my_unique_session_v2_id", integration_request)
encoded_data = json.dumps(api_response.to_dict(), default=str)
pprint(encoded_data)

# 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
for effect in api_response.effects:
if effect.effect_type == "setDiscount":
# Initiating right props instance according to the effect type
setDiscountProps = integration_api.api_client.deserialize_model(effect.props, talon_one.SetDiscountEffectProps)

# Access the specific effect's properties
print("Set a discount '{name}' of {value}".format(
name = setDiscountProps.name,
value = setDiscountProps.value
))
elif effect.effect_type == "rejectCoupon":
rejectCouponEffectProps = integration_api.api_client.deserialize_model(effect.props, talon_one.RejectCouponEffectProps)

# Work with AcceptCouponEffectProps' properties
# ...
4 changes: 2 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pytest~=4.6.7 # needed for python 2.7+3.4
pytest~=8.3.3 # needed for python 2.7+3.4
pytest-cov>=2.8.1
pytest-randomly==1.2.3 # needed for python 2.7+3.4
pytest-randomly==3.16.0 # needed for python 2.7+3.4

0 comments on commit 99d7a40

Please sign in to comment.