Skip to content

Commit

Permalink
Merge pull request #308 from AmericaSCORESBayArea/sandbox
Browse files Browse the repository at this point in the history
Sandbox to Production [Dec 5, 2024]
  • Loading branch information
AleksandrMolchagin authored Dec 6, 2024
2 parents d3da16b + 5e02b31 commit eb678c3
Show file tree
Hide file tree
Showing 6 changed files with 941 additions and 26 deletions.
198 changes: 192 additions & 6 deletions docs/Scores - Salesforce Data API.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "efa5ea10-0550-4f96-a0f9-9a20028f5524",
"_postman_id": "3b1bae7a-292c-438d-8084-814f04f11545",
"name": "Scores - Salesforce Data API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "34720049"
Expand Down Expand Up @@ -558,6 +558,9 @@
},
{
"name": "/contacts",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
Expand All @@ -570,13 +573,32 @@
"value": "{{sandbox_client_secret}}"
}
],
"body": {
"mode": "raw",
"raw": "",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{base_url}}/contacts",
"raw": "{{base_url_s}}/contacts?firstName=A&lastName=3",
"host": [
"{{base_url}}"
"{{base_url_s}}"
],
"path": [
"contacts"
],
"query": [
{
"key": "firstName",
"value": "A"
},
{
"key": "lastName",
"value": "3"
}
]
},
"description": "BODY/JSON:\n\n{ \n\"TeamSeasonName\": \"\", \n\"TeamId\": \"\", \n\"SeasonId\": \"\", \n\"SchoolSite\": \"\", \n\"Partnership\": \"\", \n\"TotalNoOfPlayers\": 0, \n\"TotalNoOfSessions\": 0, \n\"SeasonStartDate\": \"\", \n\"SeasonEndDate\": \"\", \n\"CoachSoccer\": \"\", \n\"CoachWriting\": \"\", \n\"ProgramCoordinator\": \"\", \n\"ProgramManager\": \"\" \n}"
Expand Down Expand Up @@ -632,9 +654,9 @@
}
],
"url": {
"raw": "{{base_url}}/contacts/searchByPhoneNumber?phoneNumber=269",
"raw": "{{base_url_s}}/contacts/searchByPhoneNumber?phoneNumber=65032071320",
"host": [
"{{base_url}}"
"{{base_url_s}}"
],
"path": [
"contacts",
Expand All @@ -643,7 +665,7 @@
"query": [
{
"key": "phoneNumber",
"value": "269"
"value": "65032071320"
}
]
},
Expand Down Expand Up @@ -1589,6 +1611,170 @@
"response": []
}
]
},
{
"name": "tasks",
"item": [
{
"name": "/tasks",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "client_id",
"value": "{{sandbox_client_id}}"
},
{
"key": "client_secret",
"value": "{{sandbox_client_secret}}"
}
],
"body": {
"mode": "raw",
"raw": "",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{base_url}}/tasks?contactId=003cX000008IZnXQAW",
"host": [
"{{base_url}}"
],
"path": [
"tasks"
],
"query": [
{
"key": "contactId",
"value": "003cX000008IZnXQAW"
}
]
},
"description": "BODY/JSON:\n\n{ \n\"TeamSeasonName\": \"\", \n\"TeamId\": \"\", \n\"SeasonId\": \"\", \n\"SchoolSite\": \"\", \n\"Partnership\": \"\", \n\"TotalNoOfPlayers\": 0, \n\"TotalNoOfSessions\": 0, \n\"SeasonStartDate\": \"\", \n\"SeasonEndDate\": \"\", \n\"CoachSoccer\": \"\", \n\"CoachWriting\": \"\", \n\"ProgramCoordinator\": \"\", \n\"ProgramManager\": \"\" \n}"
},
"response": []
},
{
"name": "/tasks",
"request": {
"method": "POST",
"header": [
{
"key": "client_id",
"value": "{{sandbox_client_id}}"
},
{
"key": "client_secret",
"value": "{{sandbox_client_secret}}"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"AssignedBy\": \"\",\n \"AssignedTo\": \"003cX000008IZnXQAW\",\n \"CreatedByContact\": \"0051T000009eHfvQAE\",\n \"CreatedContact\": \"\",\n \"Description\": \"This is a test of the POST method #2.\",\n \"DueDate\": \"2020-11-03\",\n \"LastModifiedBy\": \"0051T000009eHfvQAE\",\n \"LastModifiedContact\": \"\",\n \"OwnerId\": \"0051T000009eHfvQAE\",\n \"Priority\": 90.2,\n \"ResourceLink\": \"\",\n \"Session\": \"\",\n \"Name\": \"Third task to do!\",\n \"TaskStatus\": \"Complete\",\n \"TaskType\": \"HR Requirement\" \n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{base_url}}/tasks",
"host": [
"{{base_url}}"
],
"path": [
"tasks"
]
},
"description": "BODY/JSON:\n\n{ \n\"TeamSeasonName\": \"\", \n\"TeamId\": \"\", \n\"SeasonId\": \"\", \n\"SchoolSite\": \"\", \n\"Partnership\": \"\", \n\"TotalNoOfPlayers\": 0, \n\"TotalNoOfSessions\": 0, \n\"SeasonStartDate\": \"\", \n\"SeasonEndDate\": \"\", \n\"CoachSoccer\": \"\", \n\"CoachWriting\": \"\", \n\"ProgramCoordinator\": \"\", \n\"ProgramManager\": \"\" \n}"
},
"response": []
},
{
"name": "/tasks/{taskId}",
"request": {
"method": "PATCH",
"header": [
{
"key": "client_id",
"value": "{{sandbox_client_id}}"
},
{
"key": "client_secret",
"value": "{{sandbox_client_secret}}"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"AssignedBy\": \"\",\n \"AssignedTo\": \"003cX000008IZnXQAW\",\n \"CreatedByContact\": \"0051T000009eHfvQAE\",\n \"CreatedContact\": \"\",\n \"Description\": \"This is a test of the POST method #2.\",\n \"DueDate\": \"2020-11-03\",\n \"LastModifiedBy\": \"0051T000009eHfvQAE\",\n \"LastModifiedContact\": \"\",\n \"OwnerId\": \"0051T000009eHfvQAE\",\n \"Priority\": 90.2,\n \"ResourceLink\": \"\",\n \"Session\": \"\",\n \"Name\": \"Third task to do!!\",\n \"TaskStatus\": \"Complete\",\n \"TaskType\": \"HR Requirement\" \n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{base_url}}/tasks/a40cX000000GcR7QAK",
"host": [
"{{base_url}}"
],
"path": [
"tasks",
"a40cX000000GcR7QAK"
]
},
"description": "BODY/JSON:\n\n{ \n\"TeamSeasonName\": \"\", \n\"TeamId\": \"\", \n\"SeasonId\": \"\", \n\"SchoolSite\": \"\", \n\"Partnership\": \"\", \n\"TotalNoOfPlayers\": 0, \n\"TotalNoOfSessions\": 0, \n\"SeasonStartDate\": \"\", \n\"SeasonEndDate\": \"\", \n\"CoachSoccer\": \"\", \n\"CoachWriting\": \"\", \n\"ProgramCoordinator\": \"\", \n\"ProgramManager\": \"\" \n}"
},
"response": []
},
{
"name": "/tasks/{taskId}/tags",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "client_id",
"value": "{{sandbox_client_id}}"
},
{
"key": "client_secret",
"value": "{{sandbox_client_secret}}"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"contactId\": \"003U8000008Mz3RIAS\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{base_url}}/tasks/a40cX000000GVRFQA4/tags",
"host": [
"{{base_url}}"
],
"path": [
"tasks",
"a40cX000000GVRFQA4",
"tags"
]
},
"description": "BODY/JSON:\n\n{ \n\"TeamSeasonName\": \"\", \n\"TeamId\": \"\", \n\"SeasonId\": \"\", \n\"SchoolSite\": \"\", \n\"Partnership\": \"\", \n\"TotalNoOfPlayers\": 0, \n\"TotalNoOfSessions\": 0, \n\"SeasonStartDate\": \"\", \n\"SeasonEndDate\": \"\", \n\"CoachSoccer\": \"\", \n\"CoachWriting\": \"\", \n\"ProgramCoordinator\": \"\", \n\"ProgramManager\": \"\" \n}"
},
"response": []
}
]
}
],
"event": [
Expand Down
95 changes: 95 additions & 0 deletions docs/concurrency_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import asyncio
import aiohttp
import json
import time

# ==============================================================
# HOW TO USE THIS SCRIPT FOR TESTING API ENDPOINTS CONCURRENTLY
# ==============================================================
#
# 1. **Setting Up the API URL**:
# - Replace the `url` variable with the actual endpoint URL you want to test.
# - Example:
# url = "https://api.example.com/enrollments"
#
# 2. **Headers**:
# - Ensure the `headers` dictionary contains any necessary authentication/authorization headers required by the API.
# - Common headers include:
# - `'client_id'`: Your client ID or application key.
# - `'client_secret'`: Your client secret or API key.
# - `'Content-Type'`: Typically set to `'application/json'` if sending JSON data.
#
# Example:
# headers = {
# 'client_id': 'your-client-id',
# 'client_secret': 'your-client-secret',
# 'Content-Type': 'application/json'
# }
#
# 3. **Request Payload**:
# - Modify the `payload` variable to match the structure and data your API expects.
# - For example, if testing an enrollment API, ensure fields like `TeamSeasonId`, `StudentId`, `StartDate`, and `EndDate` are populated with valid test data.
#
# Example:
# payload = json.dumps({
# "TeamSeasonId": "12345",
# "StudentId": "67890",
# "StartDate": "2024-01-01",
# "EndDate": "2024-12-31"
# })
#
# 4. **Number of Requests**:
# - The script sends 20 concurrent requests to the API (default).
# - If you need to change the number of requests to test different loads, simply adjust the `number_of_requests` variable.
#
# Example:
# number_of_requests = 50 # Send 50 concurrent requests
#
# 5. **Running the Script**:
# - Run the script to test the API. It will send requests concurrently and print out:
# - The HTTP status code for each request.
# - The response time for each request.
# - The response body returned by the API.
#
# ================================================

number_of_requests = 20
url = "https://production-salesforce-data-api.us-e2.cloudhub.io/api/enrollments"
headers = {
'client_id': '',
'client_secret': '',
'Content-Type': 'application/json'
}
payload = json.dumps({
"TeamSeasonId": "",
"StudentId": "",
"StartDate": "",
"EndDate": ""
})

async def send_post_request(session, url, headers, payload, idx):
start_time = time.time()
print(f"Starting request {idx + 1} to {url}")
async with session.post(url, headers=headers, data=payload) as response:
elapsed_time = time.time() - start_time
print(f"Completed request {idx + 1} to {url}")
return await response.text(), response.status, elapsed_time


async def main():
async with aiohttp.ClientSession() as session:
tasks = [send_post_request(session, url, headers, payload, idx) for idx in range(number_of_requests)]
responses = await asyncio.gather(*tasks)

for idx, (response_text, status_code, elapsed_time) in enumerate(responses):
print(f"Response from Request {idx + 1}:")
print(f"Status Code: {status_code}")
print(f"Time Taken: {elapsed_time:.2f} seconds")
print(response_text)

start_total_time = time.time()

asyncio.run(main())

end_total_time = time.time()
print(f"\nTotal time for all requests to complete: {end_total_time - start_total_time:.2f} seconds")
Loading

0 comments on commit eb678c3

Please sign in to comment.