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 5, 2024
1 parent 710fca9 commit 17d893d
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 2 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: run tests

on: [push]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Login to GCR
uses: docker/login-action@v3
with:
registry: eu.gcr.io
username: _json_key
password: ${{ secrets.GCR_JSON_KEY }}
- uses: hoverkraft-tech/compose-action@v2.0.2
- uses: actions/checkout@v4
- 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
- name: Run example
run: |
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: eu.gcr.io/talon-farm2/talon-one/talon-service/master:latest
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:
68 changes: 68 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import talon_one
from talon_one.rest import ApiException
from pprint import pprint
import json

# 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": "e18149e88f42247f0123456789abcdef9302722577ad60cebc86c4333b6fb70"
}
)

# 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 17d893d

Please sign in to comment.