Skip to content
This repository was archived by the owner on Jan 21, 2025. It is now read-only.

contract test - griffin #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services:
broker-pact:
image: pactfoundation/pact-broker
ports:
- "9292:9292"
environment:
PACT_BROKER_DATABASE_USERNAME: pactbrokeruser
PACT_BROKER_DATABASE_PASSWORD: pactbrokerpass
PACT_BROKER_DATABASE_NAME: pactbroker
PACT_BROKER_DATABASE_HOST: db
PACT_BROKER_DATABASE_PORT: 5432
depends_on:
- db

db:
image: postgres:12
environment:
POSTGRES_USER: pactbrokeruser
POSTGRES_PASSWORD: pactbrokerpass
POSTGRES_DB: pactbroker
ports:
- "5432:5432"
4 changes: 4 additions & 0 deletions publish_pact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from pact import Broker

broker = Broker(broker_base_url='http://localhost:9292')
broker.publish('SearchReportConsumer', version='1.0.0', pact_dir='./pacts')
107 changes: 26 additions & 81 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,91 +1,36 @@
aiohttp==3.9.3
aiosignal==1.3.1
annotated-types==0.7.0
anyio==4.4.0
attrs==23.2.0
boto3==1.24.54
botocore==1.27.96
cachetools==5.3.2
certifi==2024.2.2
cffi==1.16.0
boto3==1.35.8
botocore==1.35.8
certifi==2024.7.4
cffi==1.17.0
charset-normalizer==3.3.2
click==8.1.7
Deprecated==1.2.14
dnspython==2.6.1
email_validator==2.2.0
et-xmlfile==1.1.0
execnet==2.0.2
fastapi==0.111.0
fastapi-cli==0.0.4
frozenlist==1.4.1
google-auth==2.28.0
google-auth-oauthlib==1.2.0
gspread==5.4.0
common-fate-schema==0.7.0
exceptiongroup==1.2.2
fastapi==0.112.2
flux==1.3.5
h11==0.14.0
httpcore==1.0.5
httptools==0.6.1
httpx==0.27.0
idna==3.6
iniconfig==2.0.0
Jinja2==3.1.4
idna==3.8
jmespath==1.0.1
jsonpickle==2.0.0
mail-parser==3.15.0
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mdurl==0.1.2
Logbook==1.7.0.post0
multidict==6.0.5
numpy==1.26.4
oauthlib==3.2.2
opencv-python==4.7.0.68
openpyxl==3.0.9
orjson==3.10.6
packaging==23.2
pact-python==2.2.0
percy-selenium==1.0.4
pluggy==1.4.0
psutil==5.9.8
pyasn1==0.5.1
pyasn1-modules==0.3.0
pycparser==2.21
pydantic==2.8.2
pydantic_core==2.20.1
PyGithub==1.55
Pygments==2.18.0
PyJWT==2.8.0
PyMySQL==0.9.3
PyNaCl==1.5.0
PyPika==0.48.8
pytest==7.2.1
pytest-instafail==0.4.2
pytest-rerunfailures==10.2
pytest-xdist==3.2.0
python-dateutil==2.8.2
python-dotenv==1.0.1
python-multipart==0.0.9
pytz==2021.3
PyYAML==6.0.1
requests==2.31.0
requests-oauthlib==1.3.1
rich==13.7.1
rsa==4.9
s3transfer==0.6.2
selenium==3.141.0
setuptools==69.1.0
shellingham==1.5.4
simplejson==3.19.2
pact==1.12.0
pact-python==2.2.1
provider==0.11.0
psutil==6.0.0
pycparser==2.22
pydantic==1.10.18
python-dateutil==2.9.0.post0
requests==2.32.3
s3transfer==0.10.2
six==1.16.0
slackclient==2.9.3
sniffio==1.3.1
starlette==0.37.2
typer==0.12.3
starlette==0.38.2
toml==0.10.2
typing_extensions==4.12.2
ujson==5.10.0
urllib3==1.26.7
uvicorn==0.30.1
uvloop==0.19.0
watchfiles==0.22.0
webdriver-manager==4.0.1
websockets==12.0
wrapt==1.16.0
urllib3==1.26.19
uvicorn==0.30.6
waiting==1.5.0
yarl==1.9.4

PyYAML~=6.0.2
31 changes: 31 additions & 0 deletions tests/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# config.yml

# Provider configuration
provider:
name: "SearchReportProvider" # Provider'ın adı
base_url: "http://localhost:8080" # Provider'ın yerel ortamda çalıştığı URL

# Pact Broker configuration (optional, if using a broker)
pact_broker:
url: "http://localhost:9292/" # Pact Broker URL'i
username: "your-username" # Pact Broker'a erişim için kullanıcı adı
password: "your-password" # Pact Broker'a erişim için parola
consumer_version_tag: "dev" # Tüketiciye ait sürüm etiketleri (örn. dev, prod)
provider_version_tag: "master" # Sağlayıcıya ait sürüm etiketleri (örn. master, staging)
enable_ssl_verification: true # SSL doğrulamasını etkinleştir (gerektiğinde false yapılabilir)

# Pact files path (for local testing without broker)
pact_files:
path: "./pacts" # Pact dosyalarının yerel olarak bulunduğu klasör

# Verification configuration
verification:
publish_results: true # Pact Broker'a test sonuçlarını otomatik olarak yayınla
provider_version: "1.0.0" # Provider'ın versiyonu (test sonuçlarını yayınlamak için kullanılır)
retry_attempts: 3 # Pact doğrulaması başarısız olursa kaç kez yeniden denensin
timeout: 5000 # Sağlayıcı API'ye yapılan istekler için zaman aşımı (ms cinsinden)

# Test environment variables (optional)
environment:
ENV: "local" # Testin çalıştığı ortam (örn. local, dev, prod)
API_KEY: "your-api-key" # Sağlayıcı API için kullanılacak olan API anahtarı (gerekliyse)
186 changes: 186 additions & 0 deletions tests/consumer_internal_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import atexit
import unittest
from pact import Consumer, Provider
import requests

# Pact configurations
pact = Consumer('InternalQueryConsumer').has_pact_with(Provider('InternalQueryProvider'), pact_dir='./pacts')
pact.start_service() # Pact services starting
atexit.register(pact.stop_service)


class InternalQueryContract(unittest.TestCase):
def test_internal_query(self):
expected_response = {
"data": [
{
"image_url": "https://img.lowestfare.com.hk/Content/img/logo.png",
"name": "邁爾斯堡薩尼貝爾蓋特威溫德姆拉昆塔套房酒店 迈尔斯堡萨尼贝尔盖特威温德姆拉昆塔套房酒店 La Quinta Inn & Suites by Wyndham Ft. Myers-Sanibel Gateway",
"item_id": "1024295",
"product_last_modified_by": "CatalogAPI",
"url": "https://aws-www-test-3.hutchgo.com.hk/zh-hk/",
"in_stock": 1,
"price": {
"HKD": 0
},
"product_modified_at": "2024-08-08 02:53:59",
"locale": "zh_HK:hotel",
"id": "1024295:zh_HK:hotel",
"category": [],
"discount": {
"HKD": 0
},
"original_price": {
"HKD": 0
}
},
{
"image_url": "https://img.lowestfare.com.hk/Content/img/logo.png",
"name": "龐當PLT套房酒店 庞当PLT套房酒店 Pendang Suite Hotel PLT",
"item_id": "1559382",
"product_last_modified_by": "CatalogAPI",
"url": "https://aws-www-test-3.hutchgo.com.hk/zh-hk/",
"in_stock": 1,
"price": {
"HKD": 0
},
"product_modified_at": "2024-08-08 02:53:59",
"locale": "zh_HK:hotel",
"id": "1559382:zh_HK:hotel",
"category": [],
"discount": {
"HKD": 0
},
"original_price": {
"HKD": 0
}
},
{
"image_url": "https://img.lowestfare.com.hk/Content/img/logo.png",
"name": "龍目島蘭科馬塔蘭菲芙酒店 (favehotel Langko Mataram - Lombok) 龙目岛兰科马塔兰菲芙酒店 (favehotel Langko Mataram - Lombok) favehotel Langko Mataram - Lombok",
"item_id": "1340653",
"product_last_modified_by": "CatalogAPI",
"url": "https://aws-www-test-3.hutchgo.com.hk/zh-hk/",
"in_stock": 1,
"price": {
"HKD": 0
},
"product_modified_at": "2024-08-08 02:53:59",
"locale": "zh_HK:hotel",
"id": "1340653:zh_HK:hotel",
"category": [],
"discount": {
"HKD": 0
},
"original_price": {
"HKD": 0
}
},
{
"image_url": "https://img.lowestfare.com.hk/Content/img/logo.png",
"name": "黑風洞酒店 黑风洞酒店 Batu Caves Hotel",
"item_id": "1533940",
"product_last_modified_by": "CatalogAPI",
"url": "https://aws-www-test-3.hutchgo.com.hk/zh-hk/",
"in_stock": 1,
"price": {
"HKD": 0
},
"product_modified_at": "2024-08-08 02:53:59",
"locale": "zh_HK:hotel",
"id": "1533940:zh_HK:hotel",
"category": [],
"discount": {
"HKD": 0
},
"original_price": {
"HKD": 0
}
},
{
"image_url": "https://img.lowestfare.com.hk/Content/img/logo.png",
"name": "龍仁中心CO'OP酒店 (Yongin Central CO'OP Hotel) 龙仁中心CO'OP酒店 (Yongin Central CO'OP Hotel) Yongin Central CO'OP Hotel",
"item_id": "1289139",
"product_last_modified_by": "CatalogAPI",
"url": "https://aws-www-test-3.hutchgo.com.hk/zh-hk/",
"in_stock": 1,
"price": {
"HKD": 0
},
"product_modified_at": "2024-08-08 02:53:59",
"locale": "zh_HK:hotel",
"id": "1289139:zh_HK:hotel",
"category": [],
"discount": {
"HKD": 0
},
"original_price": {
"HKD": 0
}
}
],
"scroll_id": "DXF1ZXJ5QW5kRmV0Y2gBAAAAAd34d_sWejAzaTNwTlhUYVdzMjBHLThhTmNjZw==",
"size": 5,
"success": True,
"total": 10
}

request_body = {
"size": 5,
"_source": {
"exclude": ["modified_by", "modified_at", "recommendations", "suggest"]
},
"query": {
"bool": {
"must": [
{
"match": {
"locale": "zh_HK:hotel"
}
}
],
"must_not": [
{
"bool": {
"must": [
{
"exists": {
"field": "is_status_passive"
}
},
{
"term": {
"is_status_passive": 1
}
}
]
}
}
]
}
}
}

# Define the Pact interaction
(pact
.given('Internal query endpoint with given partner data')
.upon_receiving('a request to insert an event')
.with_request('POST', '/v2/internal-query', body=request_body, headers={'Content-Type': 'application/json'})
.will_respond_with(200, body=expected_response, headers={'Content-Type': 'application/json'}))

# With the Pact service running, send the request and check the response
with pact:
result = requests.post(pact.uri + '/v2/internal-query',
params=
{
'partner': 'hutchgouat'
}, json=request_body,
headers={'Content-Type': 'application/json'})
self.assertEqual(result.status_code, 200)
actual_response = result.json()

self.assertEqual(actual_response, expected_response)


if __name__ == '__main__':
unittest.main()
Loading
Loading