Skip to content

Commit

Permalink
Contract project added
Browse files Browse the repository at this point in the history
  • Loading branch information
eren.anar committed Jul 10, 2024
1 parent eb6aa46 commit 728f97b
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 0 deletions.
4 changes: 4 additions & 0 deletions global_values.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
EMAIL = "erenContract@test.com"
BASE_URL = "https://atrium.useinsider.com"
PARTNER = "inshoppingcart"
INSIDERID = "706cadeb-14ca-45ec-aa7c-bbc5ca4d1408"
91 changes: 91 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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
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
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
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
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
six==1.16.0
slackclient==2.9.3
sniffio==1.3.1
starlette==0.37.2
typer==0.12.3
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
yarl==1.9.4
63 changes: 63 additions & 0 deletions tests/shopifyContactProfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import atexit
import unittest
from pact import Consumer, Provider
import requests
from global_values import EMAIL, PARTNER, INSIDERID

# Pact konfigürasyonu
pact = Consumer('ContactProfileConsumer').has_pact_with(Provider('ContactProfileProvider'), pact_dir='./pacts')
pact.start_service() # Pact servisini başlatıyoruz
atexit.register(pact.stop_service) # Servisin durdurulmasını sağlıyoruz

class ContactProfileContract(unittest.TestCase):
def test_contact_profile(self):
# Beklenen yanıt verisi
expected_response = {
"attributes": {
"actv": True,
"crea": "2024-07-09T17:14:44Z",
"em": "erencontract@test.com",
"eo": True,
"gdpr": True,
"global_unsubscribe": 0,
"idat": "2024-07-09T17:14:49Z",
"iid": INSIDERID,
"upta": "2024-07-09T23:11:51Z"
}
}

# Gönderilecek istek verisi
request_body = {
"partner": PARTNER,
"sources": ["last"],
"identifiers": {
"em": EMAIL
},
"attributes": ["*"],
"events": {
"start_date": 1,
"end_date": 1797643132,
"wanted": [
{
"event_name": "confirmation_page_view",
"params": ["url", "crea"]
}
]
}
}

# Pact etkileşimini tanımlıyoruz
(pact
.given('User profile exists')
.upon_receiving('a request to create or get profile')
.with_request('post', '/api/contact/v1/profile', body=request_body)
.will_respond_with(200, body=expected_response))

# Pact servisi çalışırken isteği gönderiyoruz ve yanıtı kontrol ediyoruz
with pact:
result = requests.post(pact.uri + '/api/contact/v1/profile', json=request_body)
self.assertEqual(result.json(), expected_response)


if __name__ == '__main__':
unittest.main()
51 changes: 51 additions & 0 deletions tests/shopifyCreateUser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import atexit
import unittest
from pact import Consumer, Provider
import requests
from global_values import EMAIL, PARTNER


# Pact konfigürasyonu
pact = Consumer('UserCreateConsumer').has_pact_with(Provider('UserCreateProvider'), pact_dir='./pacts')
pact.start_service() # Pact servisini başlatıyoruz
atexit.register(pact.stop_service) # Servisin durdurulmasını sağlıyoruz

class UserCreateContract(unittest.TestCase):
def test_user_create(self):

# Gönderilecek istek verisi
request_body = {
"partner": PARTNER,
"source": "email",
"lane": 0,
"users": [
{
"identifiers": {
"em": EMAIL
},
"attributes": {
"eo": True,
"gdpr": True,
"global_unsubscribe": 0
}
}
]
}

expected_response = {}

# Pact etkileşimini tanımlıyoruz
(pact
.given('User with email exists')
.upon_receiving('a request to update attributes')
.with_request('post', '/api/attribute/v1/update', body=request_body)
.will_respond_with(200, body=expected_response))

# Pact servisi çalışırken isteği gönderiyoruz ve yanıtı kontrol ediyoruz
with pact:
result = requests.post(pact.uri + '/api/attribute/v1/update', json=request_body)
self.assertEqual(result.status_code, 200)
self.assertEqual(result.json(), expected_response)

if __name__ == '__main__':
unittest.main()
45 changes: 45 additions & 0 deletions tests/shopifyIdentity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import atexit
import unittest
from pact import Consumer, Provider
import requests
from global_values import EMAIL, PARTNER, INSIDERID

# Pact konfigürasyonu
pact = Consumer('IdentityConsumer').has_pact_with(Provider('IdentityProvider'), pact_dir='./pacts')
pact.start_service() # Pact servisini başlatıyoruz
atexit.register(pact.stop_service) # Servisin durdurulmasını sağlıyoruz

class IdentityGetContract(unittest.TestCase):
def test_get_identity(self):
# Beklenen yanıt verisi
expected_response = INSIDERID

# Gönderilecek istek verisi
request_body = {
"partner": PARTNER,
"read_only": True,
"identifiers": {
"em": EMAIL
}
}

# Pact etkileşimini tanımlıyoruz
(pact
.given('User with email exists')
.upon_receiving('a request to get identity')
.with_request('post', '/api/identity/v1/get', body=request_body)
.will_respond_with(200, body=expected_response))

# Pact servisi çalışırken isteği gönderiyoruz ve yanıtı kontrol ediyoruz
with pact:
result = requests.post(pact.uri + '/api/identity/v1/get', json=request_body)
self.assertEqual(result.status_code, 200)
try:
response_json = result.json()
except ValueError:
response_json = result.text

self.assertEqual(response_json, expected_response)

if __name__ == '__main__':
unittest.main()
46 changes: 46 additions & 0 deletions tests/shopifyTriggerEvent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import atexit
import unittest
from pact import Consumer, Provider
import requests
from global_values import EMAIL, PARTNER

# Pact konfigürasyonu
pact = Consumer('EventConsumer').has_pact_with(Provider('EventProvider'), pact_dir='./pacts')
pact.start_service() # Pact servisini başlatıyoruz
atexit.register(pact.stop_service) # Servisin durdurulmasını sağlıyoruz

class EventTriggerContract(unittest.TestCase):
def test_trigger_event(self):
# Beklenen yanıt verisi
expected_response = {"eren": True}

# Gönderilecek istek verisi
request_body = {
"partner": PARTNER,
"source": "email",
"identifiers": {
"em": EMAIL
},
"events": [
{
"event_name": "email_open",
"timestamp": 1719827005
}
]
}

# Pact etkileşimini tanımlıyoruz
(pact
.given('User with email exists')
.upon_receiving('a request to insert an event')
.with_request('post', '/api/event/v1/insert', body=request_body)
.will_respond_with(200, body=expected_response))

# Pact servisi çalışırken isteği gönderiyoruz ve yanıtı kontrol ediyoruz
with pact:
result = requests.post(pact.uri + '/api/event/v1/insert', json=request_body)
self.assertEqual(result.status_code, 200)
self.assertEqual(result.json(), expected_response)

if __name__ == '__main__':
unittest.main()
25 changes: 25 additions & 0 deletions verify_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import unittest
from pact import Verifier
from global_values import BASE_URL


class ProviderVerification(unittest.TestCase):
def test_verify_create_profile_provider(self):
verifierCreateProfile = Verifier(provider='UserCreateConsumer', provider_base_url=BASE_URL)
verifierCreateProfile.verify_pacts('./tests/pacts/usercreateconsumer-usercreateprovider.json')

def test_verify_contact_profile_provider(self):
verifierContactProfile = Verifier(provider='ContactProfileConsumer', provider_base_url=BASE_URL)
verifierContactProfile.verify_pacts('./tests/pacts/contactprofileconsumer-contactprofileprovider.json')

def test_verify_event_provider(self):
verifierEvent = Verifier(provider='EventConsumer', provider_base_url=BASE_URL)
verifierEvent.verify_pacts('./tests/pacts/eventconsumer-eventprovider.json')

def test_verify_identity_provider(self):
verifierEvent = Verifier(provider='IdentityConsumer', provider_base_url=BASE_URL)
verifierEvent.verify_pacts('./tests/pacts/identityconsumer-identityprovider.json')


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

0 comments on commit 728f97b

Please sign in to comment.