Skip to content

Commit

Permalink
Finalizing Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sadaqatullah committed Nov 11, 2022
1 parent d430f2a commit 3108be3
Show file tree
Hide file tree
Showing 5 changed files with 338 additions and 19 deletions.
27 changes: 26 additions & 1 deletion data/saas/config/recharge_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ saas_config:
- name: email
identity: email
data_path: customers
update:
method: PUT
path: /customers/<customer_id>
body: |
{
<masked_object_fields>
}
param_values:
- name: customer_id
references:
- dataset: <instance_fides_key>
field: customers.customer_id
direction: from

- name: addresses
requests:
Expand All @@ -52,4 +65,16 @@ saas_config:
field: customers.id
direction: from
data_path: addresses

update:
method: PUT
path: /addresses/<address_id>
body: |
{
<masked_object_fields>
}
param_values:
- name: address_id
references:
- dataset: <instance_fides_key>
field: addresses.address_id
direction: from
2 changes: 1 addition & 1 deletion data/saas/dataset/recharge_dataset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ dataset:
fidesops_meta:
data_type: string
- name: id
data_categories: [ user.unique_id ]
data_categories: [ system.operations ]
fidesops_meta:
data_type: string
- name: last_name
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ extension-pkg-whitelist = ["pydantic", "zlib"]
env = [
"TESTING=True"
]
log_cli=false
log_cli=true
filterwarnings = "ignore::DeprecationWarning:aiofiles.*:"
testpaths="tests"
log_level = "INFO"
Expand Down
183 changes: 176 additions & 7 deletions tests/ops/fixtures/saas/recharge_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from typing import Any, Dict, Generator

import uuid
import pydash
import pytest
import requests
from faker import Faker
from fideslib.db import session
from requests import Response
from sqlalchemy.orm import Session

from fides.api.ops.models.connectionconfig import (
Expand All @@ -15,9 +18,9 @@
load_config_with_replacement,
load_dataset_with_replacement,
)
from tests.ops.test_helpers.saas_test_utils import poll_for_existence
from tests.ops.test_helpers.vault_client import get_secrets


secrets = get_secrets("recharge")


Expand All @@ -32,10 +35,15 @@ def recharge_secrets(saas_config):
@pytest.fixture(scope="function")
def recharge_identity_email(saas_config):
return (
pydash.get(saas_config, "recharge.identity_email") or secrets["identity_email"]
pydash.get(saas_config, "recharge.identity_email") or secrets["identity_email"]
)


@pytest.fixture(scope='function')
def recharge_erasure_identity_email():
return f"{uuid.uuid4().hex}@email.com"


@pytest.fixture
def recharge_config() -> Dict[str, Any]:
return load_config_with_replacement(
Expand All @@ -56,7 +64,7 @@ def recharge_dataset() -> Dict[str, Any]:

@pytest.fixture(scope="function")
def recharge_connection_config(
db: session, recharge_config, recharge_secrets
db: session, recharge_config, recharge_secrets
) -> Generator:
fides_key = recharge_config["fides_key"]
connection_config = ConnectionConfig.create(
Expand All @@ -76,9 +84,9 @@ def recharge_connection_config(

@pytest.fixture
def recharge_dataset_config(
db: Session,
recharge_connection_config: ConnectionConfig,
recharge_dataset: Dict[str, Any],
db: Session,
recharge_connection_config: ConnectionConfig,
recharge_dataset: Dict[str, Any],
) -> Generator:
fides_key = recharge_dataset["fides_key"]
recharge_connection_config.name = fides_key
Expand All @@ -94,3 +102,164 @@ def recharge_dataset_config(
)
yield dataset
dataset.delete(db=db)


class RechargeTestClient:
"""Helper to call various Recharge data management requests"""

def __init__(self, recharge_connection_config: ConnectionConfig):

self.recharge_secrets = recharge_connection_config.secrets
self.headers = {
"X-Recharge-Access-Token": self.recharge_secrets["api_key"],
"Content-Type": "application/json"
}
self.base_url = f"https://{self.recharge_secrets['domain']}"
self.faker = Faker()
self.first_name = self.faker.first_name()
self.last_name = self.faker.last_name()
self.street_address = self.faker.street_address()

# 1: Creates, checks for existance and deletes customer
def create_customer(self, email) -> Response:
customer_body = {
"first_name": self.first_name,
"last_name": self.last_name,
"email": email,
"billing_address1": self.street_address,
"billing_city": "New York City",
"billing_province": "New York",
"billing_country": "United States",
"billing_first_name": self.first_name,
"billing_last_name": self.last_name,
"billing_zip": "10001",
}

customer_response: Response = requests.post(
url=f"{self.base_url}/customers",
json=customer_body,
headers=self.headers,
)
assert customer_response.ok

return customer_response

def customer_exists(self, email):
customer_response: Response = requests.get(
url=f"{self.base_url}/customers",
params={"email": email},
headers=self.headers,
)
assert customer_response.ok
return customer_response.json()

def delete_customer(self, customer_id):
delete_customer_response = requests.delete(
url=f"{self.base_url}/customers/{customer_id}",
headers=self.headers,
data={}
)
assert delete_customer_response.ok

# 2: Creates, checks for existance and deletes address
def create_address(self, customer_id) -> Response:
address_body = {
"customer_id": customer_id,
"address1": self.street_address,
"address2": self.street_address,
"city": "Los Angeles",
"company": "Recharge",
"country_code": "US",
"country": "United States",
"first_name": self.first_name,
"last_name": self.last_name,
"order_attributes": [
{
"name": "custom name",
"value": "custom value"
}
],
"phone": "5551234567",
"province": "California",
"zip": "90001"
}
address_response = requests.post(
url=f"{self.base_url}/addresses",
headers=self.headers,
json=address_body,
)
assert address_response.ok
return address_response

def address_exists(self, customer_id):
address_response: Response = requests.get(
url=f"{self.base_url}/addresses",
params={"customer_id": customer_id},
headers=self.headers,
)
assert address_response.ok
return address_response.json()

def delete_address(self, address_id):
delete_address_response = requests.delete(
url=f"{self.base_url}/addresses/{address_id}",
headers=self.headers,
data={}
)
assert delete_address_response.ok

# 3: Creates, checks for existance and deletes order
def create_order(self, ): pass
def order_exists(self, ): pass
def delete_order(self, ): pass

# 4: Creates, checks for existance and deletes payment_method
def create_payment_method(self): pass
def payment_method_exists(self): pass
def delete_payment_method(self): pass

# 5: Creates, checks for existance and deletes subscription
def create_subscription(self): pass
def subscription_exist(self): pass
def delete_subscription(self): pass


@pytest.fixture(scope="function")
def recharge_test_client(
recharge_connection_config: RechargeTestClient
) -> Generator:
test_client = RechargeTestClient(recharge_connection_config=recharge_connection_config)
yield test_client


@pytest.fixture(scope="function")
def recharge_erasure_data(
recharge_test_client: RechargeTestClient, recharge_erasure_identity_email: str
) -> Generator:
customer_response = recharge_test_client.create_customer(recharge_erasure_identity_email)
error_message = (
f"customer with email {recharge_erasure_identity_email} could not be created in Recharge"
)
poll_for_existence(
recharge_test_client.customer_exists,
(recharge_erasure_identity_email,),
error_message=error_message,
)
customer_id = customer_response.json()["customer"]["id"]

address_response = recharge_test_client.create_address(customer_id)
error_message = (
f"address for customer '{recharge_erasure_identity_email}' could not be created in Recharge"
)
poll_for_existence(
recharge_test_client.address_exists,
args=(customer_id,),
error_message=error_message,
)
address_id = address_response.json()["address"]["id"]

yield customer_response, address_response


recharge_test_client.delete_address(address_id)
recharge_test_client.delete_customer(customer_id)
Loading

0 comments on commit 3108be3

Please sign in to comment.