import requests import cProfile import pstats import pprint from test_files_system_fields import * def profile(code, name='profile_run', sort='cumulative'): """Common-use for cProfile""" cProfile.run(code, name) stats = pstats.Stats(name) stats.sort_stats(sort) stats.print_stats(num) return stats #data1 = {"customerId": "bf3efb2b31de8152853ca27e58f0048f7c63c9cf97a2511e0f9c6b0e", "fileId": "e6b0e56f0dcc30d307da28f8d7042037bd05427379482faa8b726af2bec9be7b/MOCK_DATA.csv", "fieldMap":[{ "systemFieldName": "userEmail", "incomingFieldName": "id" },{ "systemFieldName": "userFirstName", "incomingFieldName": "first_name" },{ "systemFieldName": "userLastName", "incomingFieldName": "last_name" },{ "systemFieldName": "userEmail", "incomingFieldName": "email" },{ "systemFieldName": "userGender", "incomingFieldName": "gender" }], "collectionName": "MOCK_DATA.csv"} #data2 = {'customerId': 'c7b4555c468ffee2efc9483182179802806c02543c14b6381ea9e39a0', 'fileId': '2c1a9dd1e9f518e1d4fee2f2a14917722b80da4b029e084fa64ceaeab322beb3/testcase.csv', 'fieldMap': '[{"systemFieldName":"userEmail","incomingFieldName":"email"},{"systemFieldName":"userFirstName","incomingFieldName":"firstname"},{"systemFieldName":"userLastName","incomingFieldName":"lastname"},{"systemFieldName":"userPhone","incomingFieldName":"phone"},{"systemFieldName":"userGender","incomingFieldName":"gender"},{"systemFieldName":"userDob","incomingFieldName":"dob"}]', 'collectionName': 'testcase.csv'} #data2 = {'customerId': 'kaspar', 'fileId': 'kaspar/ULO_CyberSpirits.csv', 'fieldMap': '[{"systemFieldName":"userEmail","incomingFieldName":"Buyer Email"}]', 'collectionName': 'ULO_CyberSpirits.csv'} def run_test_new_enrichment(): import time bulk_set = [ {'collection_id': 62, # 43 'schema': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', #'ca7a460d855e229dd0384001e1c9f5d6fb59381f967ba1b7ec36a7591' #'c8af107ff20523f23efeae937a12eaeed23eda36b9168c828cedf35f9' 'user_id': 'e69fbcc1-c57c-4de2-ab79-91dc5791b094' }, ] for data in bulk_set: urlbase = 'http://localhost:12345' url = f"{urlbase}/test_enrichment" r = requests.post(url, json=data) time.sleep(5) print(repr(r.content)) def delete_collection(): data = {'collectionId': 23, 'clientId': 'ca7a460d855e229dd0384001e1c9f5d6fb59381f967ba1b7ec36a7591', } urlbase = 'http://localhost:12345' url = f"{urlbase}/delete_collection" r = requests.post(url, json=data) print(repr(r.content)) def run_bulk_test(): for file in kaspar: urlbase = 'http://localhost:12345' url = f"{urlbase}/initiate_manual_file_upload" r = requests.post(url, json=file) print(repr(r.content)) def run_analytics_test(): data = {'clientId': 'ca7a460d855e229dd0384001e1c9f5d6fb59381f967ba1b7ec36a7591', 'collectionId': 18 } urlbase = 'http://localhost:12345' url = f"{urlbase}/get_analytics" r = requests.post(url, json=data) print(repr(r.content)) return r.content def run_grouped_analytics(): data = {'clientId': 'ca7a460d855e229dd0384001e1c9f5d6fb59381f967ba1b7ec36a7591', # 'c92dcf85f845a29a44eba65edf5d75d03e13db7dc00ff549aaccc97b6' 'collectionId': 166 } urlbase = 'http://localhost:12345' url = f"{urlbase}/get_grouped_analytics" r = requests.post(url, json=data) print(repr(r.content)) return r.content def run_single_test(): janet_joplin = { "customerId": "af65a0ef98e7420800afdea2beb81059bde2bc59d797cc0851412ac41", # "customerId": "aleks_test", "fileName": "Janis_AllTimeCustomers_7-16-2020.xlsx", "filePath": "Janis Joplin/prepared_data", "bucket": "incoming-fan-data", "fieldMap": "[{'value': 'merchPurchaseDate', 'index': 0}, {'value': 'userFullName', 'index': 4}, {'value': 'userEmail', 'index': 6}, {'value': 'userAddress', 'index': 15}, {'value': 'userAddress2', 'index': 16}, {'value': 'userCity', 'index': 17}, {'value': 'userState', 'index': 18}, {'value': 'userZip', 'index': 19}, {'value': 'userCountry', 'index': 20}, {'value': 'userPhone', 'index': 21}, {'value': 'merchType', 'index': 23}, {'value': 'merchSku', 'index': 28}, {'value': 'merchName', 'index': 29}, {'value': 'merchItemPrice', 'index': 32}, {'value': 'merchPurchaceQuantity', 'index': 33}, {'value': 'merchPurchaceMonetary', 'index': 34}]" } def run_single_test(): matoma = { 'customerId': 'ca7a460d855e229dd0384001e1c9f5d6fb59381f967ba1b7ec36a7591', 'fileName': 'MATOMA Subscribed to Emails.csv', 'filePath': 'MATOMA', 'fieldMap': '[{"value":"userEmail","index":"1"}]', 'bucket': 'incoming-fan-data', } pixies = { 'customerId': 'ca7a460d855e229dd0384001e1c9f5d6fb59381f967ba1b7ec36a7591', 'fileName': 'subscribed_members_export_ab47582e54.csv', 'filePath': 'PIXIES/prepared_data', 'fieldMap': '[{"value":"userEmail","index":"0"}]', 'bucket': 'incoming-fan-data', } urlbase='http://localhost:12345' url = f"{urlbase}/initiate_manual_file_upload" r = requests.post(url, json=matoma) print(repr(r.content)) def test_enrichment_processing(prefix, collection_id): data = {'customerId': 'c947f75b43c862f14cebf9cbcfd060aa2253fd0383f55e7e793574a65', 'fieldMap': '[{"systemFieldName":"userEmail","incomingFieldName":"email"}]', 'collectionId': collection_id, 'bucket': 'devel---filestore', 'prefix': prefix} urlbase = 'http://localhost:12345' url = f"{urlbase}/process_pipl_json_files" r = requests.post(url, json=data) print(repr(r.content)) def make_api_call(collection_id, endpoint): data = {'customerId': 'c7b538defdde08de612a48a0b9a7a1725ace9bfa49d74a7909d81e856', 'collectionId': collection_id } urlbase = 'http://localhost:12345' url = f"{urlbase}/{endpoint}" r = requests.post(url, json=data) print(repr(r.content)) def generate_flattened_tables(): data = {'customerId': 'af65a0ef98e7420800afdea2beb81059bde2bc59d797cc0851412ac41'} urlbase = 'http://localhost:12345' url = f"{urlbase}/generate_flattened_tables" r = requests.post(url, json=data) print(repr(r.content)) def test_initiate_file_upload(): data = {'clientId': 'aleks_test', 'fileName': 'the_best_file.csv', 'bucket': 'incoming-fan-data'} urlbase = 'http://localhost:12345' url = f"{urlbase}/initiate_file_upload" r = requests.post(url, json=data) print(repr(r.content)) def test_generate_audience(): data = {'collectionId': 25, 'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'audienceName': 'COLLECTION 25 LATEST AUDIENCE TEST ALEKS', 'audienceDescription': 'FEB 2021 - Aleks test-122', 'user_id': 'e69fbcc1-c57c-4de2-ab79-91dc5791b094'} urlbase = 'http://localhost:12345' url = f"{urlbase}/generate_fb_audience" r = requests.post(url, json=data) print(repr(r.content)) def test_delete_audience(): data = {'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'alliance_schema': 'c9b9ba3d88f699d12beea36225b67dea7b0c0d572287003d0068f1355', 'audienceId': 4, 'user_id': 'efe79ff4-950a-47eb-8e1a-ae896b0652d8'} urlbase = 'http://localhost:12345' url = f"{urlbase}/delete_fb_audience" r = requests.post(url, json=data) print(repr(r.content)) def test_store_fb_adaccount(): data = {'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'adAccountId': 23423422414, 'adAccountName': 'Test Audience 3', 'adAccountDescription': 'Test AUdience description 4'} urlbase = 'http://localhost:12345' url = f"{urlbase}/store_fb_adaccount" r = requests.post(url, json=data) print(repr(r.content)) def test_get_fb_status(): data = {'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c'} urlbase = 'http://localhost:12345' url = f"{urlbase}/get_fb_status" r = requests.post(url, json=data) print(repr(r.content)) def test_delete_fb_adaccount(): data = {'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'adAccountId': '128568314489533'} urlbase = 'http://localhost:12345' url = f"{urlbase}/delete_fb_adaccount" r = requests.post(url, json=data) print(repr(r.content)) def test_update_fb_schema(): data = {'clientId': 'cc56867d369622c60905d6767421bbbba3ec6384a91ff224fa6e0910c'} urlbase = 'http://localhost:12345' url = f"{urlbase}/update_fb_schema" r = requests.post(url, json=data) print(repr(r.content)) def test_update_fb_sdk_status(): # data = {'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', # 'status': 'connected', # 'response': {'accessToken': 'EAAFcadd17DIBALT3ZBCXJEshesKCUMl9DUkJ4Rk3WwajBT6wsIyZBJ8uFidL9haw8ZCzRm8CAOSCW7SEiXamR6EJyFDKefJDZCMM4C3qaJzlybdecM0bn3LZBmL4kBQ8zkRvgzcM4KeHnbvdtdRjiXbtp9NzWdlpj1KJfcFjwzGZA8nq7P4ZBgJMNjU9BZC3CF4ZD', # 'data_access_expiration_time': '1618938493', # 'expiresIn': '5184000', # 'grantedScopes': 'email,read_insights,ads_management,ads_read,business_management,public_profile', # 'graphDomain': 'facebook', # 'signedRequest': 'LCzaJh6ZVr9WOMEkDVObGP5lCF1ySFzvETe1EYPO_U4.eyJ1c2VyX2lkIjoiMzU1ODczMTg3MDg0NjA1NiIsImNvZGUiOiJBUUQ3TVdGNUFYLXp0RTB5TFZqRzF1T1dqazVXMHo2a3ZlTWw4YVNkb1hIRHRsNVBsRmxXeHlqZVg2RU9qSDFISkdGUzg5bXhrLUtpOFFRZlpOUWVHTEtyYjRfZVpwU3c1eWNJOHNIbmtNN0tNZERKTXVhRldaTE10ek40NWU5RmhlcHlTUHpwSFZRdF9QS1h6WlluR2JMU0hCRC0tU3hyNU1pN2cxU3Nkc1VHX2V2S3FrdVFnZFp6SUlkRy1DMjRxelV3cko3ZVhRMWt4QmEzdGllb0VmOHhKeV9PS0pEVFRqUExWSTFmUTBMQ3BxY0U2M1poYWMwWlJxaG9ZUGtQRHIyejB2cmRnTmNnNFBxWTFobWJtZGttaE9EVkFhTG40QUVTemgxSWc3elhyX2JORVJ1dGdkdzNoVU8taGJVZ3Q5dU5TY0Y5alFQdG1WcGVxT1VsRThYUXA5UXJ4bVBXVlBnc3hwVzNqZDBjZ1EiLCJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImlzc3VlZF9hdCI6MTYxMTE2MjQ5M30', # 'user_id': '3558731870846056'}} data = {'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'status': 'disconnected', 'user_id': 'efe79ff4-950a-47eb-8e1a-ae896b0652d8', 'alliance_schemas': ['c9b9ba3d88f699d12beea36225b67dea7b0c0d572287003d0068f1355'], 'response': {}} urlbase = 'http://localhost:12345' url = f"{urlbase}/update_fb_sdk_status" r = requests.post(url, json=data) print(repr(r.content)) def test_create_and_share_fb_audience(): data = {'collectionId': 7, 'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'audienceName': 'Aleks sharing', 'audienceDescription': '23-dec-2020', 'adAccountId': 128568314489533} urlbase = 'http://localhost:12345' url = f"{urlbase}/create_and_share_fb_audience" r = requests.post(url, json=data) print(repr(r.content)) def test_list_fb_audience(): data = {'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'management_schema': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'user_id': 'efe79ff4-950a-47eb-8e1a-ae896b0652d8'} urlbase = 'http://localhost:12345' url = f"{urlbase}/list_fb_audiences" r = requests.post(url, json=data) print(repr(r.content)) def test_list_fb_audience_with_adaccount(): data = {'clientId': 'cc56867d369622c60905d6767421bbbba3ec6384a91ff224fa6e0910c', 'adAccountIds': ['128568314489533']} urlbase = 'http://localhost:12345' url = f"{urlbase}/list_fb_audiences" r = requests.post(url, json=data) print(repr(r.content)) def test_list_fb_adaccounts(): data = {'clientId': 'c0ffc723792260e9107bf0f45f49d599ac98c94ae86da29ae6ec67b77', 'management_schema': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'user_id': 'efe79ff4-950a-47eb-8e1a-ae896b0652d8'} urlbase = 'http://localhost:12345' url = f"{urlbase}/list_fb_adaccounts" r = requests.post(url, json=data) print(repr(r.content)) def test_get_fb_country_suggestions(): data = {'text': 'uni'} urlbase = 'http://localhost:12345' url = f"{urlbase}/get_fb_country_suggestions" r = requests.post(url, json=data) print(repr(r.content)) def test_generate_lookalike_fb_audience(): data = {'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'audienceName': 'test_lookalike_audience', 'sourceAudienceId': 11, 'audienceRatio': 0.03, 'audienceCountryCodes': ['US', 'GB'], 'audienceDescription': 'TEST DESCRIPTION' } urlbase = 'http://localhost:12345' url = f"{urlbase}/generate_lookalike_fb_audience" r = requests.post(url, json=data) print(repr(r.content)) def test_get_fb_lookalike_ratio_suggestions(): data = {} urlbase = 'http://localhost:12345' url = f"{urlbase}/get_fb_lookalike_ratio_suggestions" r = requests.post(url, json=data) print(repr(r.content)) def test_initiate_fb_audience_sharing(): data = {'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'adAccountId': 426538231809187, 'audienceId': 24, 'user_id': 'efe79ff4-950a-47eb-8e1a-ae896b0652d8'} urlbase = 'http://localhost:12345' url = f"{urlbase}/initiate_fb_audience_sharing" r = requests.post(url, json=data) print(repr(r.content)) def test_revoke_fb_audience_sharing_from_adaccount(): data = {'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'adAccountId': 128568314489533, 'audienceId': 4} urlbase = 'http://localhost:12345' url = f"{urlbase}/revoke_fb_adaccount_sharing" r = requests.post(url, json=data) print(repr(r.content)) def test_read_fb_audience(): data = {'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'audienceId': 2, 'user_id': 'efe79ff4-950a-47eb-8e1a-ae896b0652d8', 'management_schema': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c'} urlbase = 'http://localhost:12345' url = f"{urlbase}/read_fb_audience" r = requests.post(url, json=data) print(repr(r.content)) def test_list_saved_fb_sdk_adaccounts(): data = {'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c'} urlbase = 'http://localhost:12345' url = f"{urlbase}/list_saved_fb_sdk_adaccounts" r = requests.post(url, json=data) print(repr(r.content)) def test_update_fb_sdk_adaccounts(): data = {'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'user_id': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c'} urlbase = 'http://localhost:12345' url = f"{urlbase}/update_fb_sdk_adaccounts" r = requests.post(url, json=data) print(repr(r.content)) def test_get_fb_sdk_status(): data = {'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c'} urlbase = 'http://localhost:12345' url = f"{urlbase}/get_fb_sdk_status" r = requests.post(url, json=data) print(repr(r.content)) def test_store_fb_sdk_adaccount(): data = {'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'adAccountId': '753526402044185'} urlbase = 'http://localhost:12345' url = f"{urlbase}/store_fb_sdk_adaccount" r = requests.post(url, json=data) print(repr(r.content)) def test_store_fb_sdk_user(): data = {'clientId': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'response': '128568314489533', 'status': 'disconnected'} urlbase = 'http://localhost:12345' url = f"{urlbase}/connect_sdk_fb_account" r = requests.post(url, json=data) print(repr(r.content)) def test_deletion_flow(): data = {'appsync_field': 'tryDeleteCollection', 'workspace_schema': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'management_schema': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'collectionId': '25', 'user_id': 'just_testing'} urlbase = 'http://localhost:12345' url = f"{urlbase}/delete_consequences" r = requests.post(url, json=data) j = r.json() pprint.pprint(j, sort_dicts=False) if 'error' not in j: accept_consequences = [] for con in j: accept_consequences.extend(con['items']) data['acceptedConsequences'] = accept_consequences data['async_source'] = "appsync.deleteCollection" url = f"{urlbase}/async_notify" r = requests.post(url, json=data) print(repr(r.content)) def test_delete_consequences(): data = {'appsync_field': 'tryDeleteCollection', 'workspace_schema': 'c2c39528d40007daacf7b0633f0eaf8307c64b6f0c2021bad30a7a21a', 'management_schema': 'c2c39528d40007daacf7b0633f0eaf8307c64b6f0c2021bad30a7a21a', 'collectionId': '1029', 'user_id': '13861d4b-92c2-417a-b928-269e096ae07f'} urlbase = 'http://localhost:12345' url = f"{urlbase}/delete_consequences" r = requests.post(url, json=data) j = r.json() pprint.pprint(j, sort_dicts=False) if 'error' in j and 'info' in j and j['info']: i = j['info'] accept_consequences = [] for con in i: accept_consequences.extend(con['items']) data['acceptedConsequences'] = accept_consequences r = requests.post(url, json=data) print(repr(r.content)) def test_get_klaviyo_status(): data = {'management_schema': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c'} urlbase = 'http://localhost:12345' url = f"{urlbase}/get_klaviyo_status" r = requests.post(url, json=data) print(repr(r.content)) def test_update_klaviyo_status(): data = {'user_id': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'management_schema': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'status': 'connected', 'private_key': 'pk_d26235944ade8290f1c02f954f85caecdc', 'public_key': 'RqY4qT'} urlbase = 'http://localhost:12345' url = f"{urlbase}/update_klaviyo_status" r = requests.post(url, json=data) print(repr(r.content)) def test_list_klaviyo_lists(): data = {'management_schema': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c'} urlbase = 'http://localhost:12345' url = f"{urlbase}/list_klaviyo_lists" r = requests.post(url, json=data) print(repr(r.content)) def test_get_klaviyo_profile_base_data_from_list(): data = {'user_id': 'e69fbcc1-c57c-4de2-ab79-91dc5791b094', 'management_schema': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'workspace_schema': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'listId': ['VnVdkb'], 'collectionName': 'KLAVIYO KLAVIYO 4'} urlbase = 'http://localhost:12345' url = f"{urlbase}/klaviyo_import" r = requests.post(url, json=data) print(repr(r.content)) def test_export_klaviyo_list(): data = {'management_schema': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'workspace_schema': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c', 'listName': 'aleks yet another test', 'collectionId': 266} urlbase = 'http://localhost:12345' url = f"{urlbase}/export_klaviyo_list" r = requests.post(url, json=data) print(repr(r.content)) def test_check_audience_sharing_requests(): data = {'user_id': 'e69fbcc1-c57c-4de2-ab79-91dc5791b094'} urlbase = 'http://localhost:12345' url = f"{urlbase}/check_audience_sharing_requests" r = requests.post(url, json=data) print(repr(r.content)) def test_test_me_please(): data = {'collectionId': 364, 'schema_name': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c'} urlbase = 'http://localhost:12345' url = f"{urlbase}/test_me_please" r = requests.post(url, json=data) print(repr(r.content)) def test_alliance_export(): data = {'collectionId': 364, 'schema_name': 'c2f871f8102269c57c914d38660345cb4cb9b0a272d527ab5b8ccac3c'} urlbase = 'http://localhost:12345' url = f"{urlbase}/test_alliance_export" r = requests.post(url, json=data) print(repr(r.content))