Skip to content

Commit e4b1354

Browse files
committed
Add assertions for data by parsing the key-value strings
1 parent 44ae8bd commit e4b1354

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

backend/tests/daily/connectors/salesforce/test_salesforce_connector.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import time
44
from pathlib import Path
5+
from typing import Any
56

67
import pytest
78

@@ -10,7 +11,20 @@
1011
from onyx.connectors.salesforce.connector import SalesforceConnector
1112

1213

13-
def load_test_data(file_name: str = "test_salesforce_data.json") -> dict[str, dict]:
14+
def extract_key_value_pairs_to_set(
15+
list_of_unparsed_key_value_strings: list[str],
16+
) -> set[str]:
17+
set_of_key_value_pairs = set()
18+
for string_key_value_pairs in list_of_unparsed_key_value_strings:
19+
list_of_parsed_key_values = string_key_value_pairs.split("\n")
20+
for key_value_pair in list_of_parsed_key_values:
21+
set_of_key_value_pairs.add(key_value_pair.strip())
22+
return set_of_key_value_pairs
23+
24+
25+
def load_test_data(
26+
file_name: str = "test_salesforce_data.json",
27+
) -> dict[str, list[str] | dict[str, Any]]:
1428
current_dir = Path(__file__).parent
1529
with open(current_dir / file_name, "r") as f:
1630
return json.load(f)
@@ -51,17 +65,34 @@ def test_salesforce_connector_basic(salesforce_connector: SalesforceConnector) -
5165
assert len(all_docs) == 6
5266
assert target_test_doc is not None
5367

54-
# The order of the sections and of the content of the text fields is not deterministic,
55-
# so we check the links are present and the text isn't empty
68+
# Set of received links
5669
received_links: set[str] = set()
70+
# List of received text fields, which contain key-value pairs seperated by newlines
71+
recieved_text: list[str] = []
72+
73+
# Iterate over the sections of the target test doc to extract the links and text
5774
for section in target_test_doc.sections:
5875
assert section.link
5976
assert section.text
6077
received_links.add(section.link)
78+
recieved_text.append(section.text)
6179

80+
# Check that the received links match the expected links from the test data json
6281
expected_links = set(test_data["expected_links"])
6382
assert received_links == expected_links
6483

84+
# Check that the received key-value pairs from the text fields match the expected key-value pairs from the test data json
85+
expected_text = test_data["expected_text"]
86+
if not isinstance(expected_text, list):
87+
raise ValueError("Expected text is not a list")
88+
unparsed_expected_key_value_pairs: list[str] = expected_text
89+
received_key_value_pairs = extract_key_value_pairs_to_set(recieved_text)
90+
expected_key_value_pairs = extract_key_value_pairs_to_set(
91+
unparsed_expected_key_value_pairs
92+
)
93+
assert received_key_value_pairs == expected_key_value_pairs
94+
95+
# Check that the rest fields match the expected fields from the test data json
6596
assert target_test_doc.source == DocumentSource.SALESFORCE
6697
assert target_test_doc.semantic_identifier == test_data["semantic_identifier"]
6798
assert target_test_doc.metadata == test_data["metadata"]

backend/tests/daily/connectors/salesforce/test_salesforce_data.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
"https://customization-ruby-2195.my.salesforce.com/017fI00000T7hvsQAB",
77
"https://customization-ruby-2195.my.salesforce.com/006fI000000rDvBQAU"
88
],
9+
"expected_text": [
10+
"BillingPostalCode: 60601\nType: Prospect\nWebsite: www.globalistindustries.com\nBillingCity: Chicago\nDescription: Globalist company\nIsDeleted: false\nIsPartner: false\nPhone: (312) 555-0456\nShippingCountry: USA\nShippingState: IL\nIsBuyer: false\nBillingCountry: USA\nBillingState: IL\nShippingPostalCode: 60601\nBillingStreet: 456 Market St\nIsCustomerPortal: false\nPersonActiveTrackerCount: 0\nShippingCity: Chicago\nShippingStreet: 456 Market St",
11+
"FirstName: Michael\nMailingCountry: USA\nActiveTrackerCount: 0\nEmail: m.brown@globalindustries.com\nMailingState: IL\nMailingStreet: 456 Market St\nMailingCity: Chicago\nLastName: Brown\nTitle: CTO\nIsDeleted: false\nPhone: (312) 555-0456\nHasOptedOutOfEmail: false\nIsEmailBounced: false\nMailingPostalCode: 60601",
12+
"ForecastCategory: Closed\nName: Global Industries Equipment Sale\nIsDeleted: false\nForecastCategoryName: Closed\nFiscalYear: 2024\nFiscalQuarter: 4\nIsClosed: true\nIsWon: true\nAmount: 5000000.0\nProbability: 100.0\nPushCount: 0\nHasOverdueTask: false\nStageName: Closed Won\nHasOpenActivity: false\nHasOpportunityLineItem: false",
13+
"Field: created\nDataType: Text\nIsDeleted: false"
14+
],
915
"semantic_identifier": "Unknown Object",
1016
"metadata": {},
1117
"primary_owners": null,

0 commit comments

Comments
 (0)