Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement all_fields test using new framework-tdl-7499 #159

Merged
merged 32 commits into from
Oct 9, 2023

Conversation

bhuvana-talend
Copy link
Contributor

Description of change

https://jira.talendforge.org/browse/TDL-7499
Implement all_fields_test using the new tap-tester framework.
Tested with streams that also has custom fields
Also modified tap-tester/base_suite_tests/base_case.py : get_all_streams_and_fields to exclude unsupported fields

QA steps

  • automated tests passing
  • manual qa steps passing (list below)

Risks

Rollback steps

  • revert this branch

tests/sfbase.py Outdated Show resolved Hide resolved
tests/test_salesforce_all_fields.py Outdated Show resolved Hide resolved
tests/test_salesforce_all_fields.py Outdated Show resolved Hide resolved
tests/test_salesforce_all_fields.py Outdated Show resolved Hide resolved
tests/test_salesforce_custom_fields_test.py Outdated Show resolved Hide resolved
tests/test_salesforce_custom_fields_test.py Outdated Show resolved Hide resolved
tests/test_salesforce_custom_fields_test.py Outdated Show resolved Hide resolved
tests/test_salesforce_non_custom_fields_test.py Outdated Show resolved Hide resolved
@bhtowles
Copy link
Contributor

Re-started commit work flow from start as last test failed due to quota to see if tests will pass.

tests/sfbase.py Outdated Show resolved Hide resolved
tests/test_salesforce_all_fields_custom.py Outdated Show resolved Hide resolved
tests/test_salesforce_all_fields_non_custom.py Outdated Show resolved Hide resolved
@@ -844,6 +852,14 @@ def rest_only_streams(self):
'UndecidedEventRelation',
}

def expected_streams(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these self references may have to change to cls references for some of the methods according to recent changes in sfbase.

tests/test_salesforce_all_fields_custom.py Outdated Show resolved Hide resolved
tests/test_salesforce_all_fields_custom.py Outdated Show resolved Hide resolved
tests/test_salesforce_all_fields_non_custom.py Outdated Show resolved Hide resolved
tests/test_salesforce_all_fields_non_custom.py Outdated Show resolved Hide resolved
def test_non_custom_fields( self ):
for stream in self.streams_to_selected_fields():
expected_non_custom_fields = self.streams_to_selected_fields().get(stream, set() )
replicated_non_custom_fields = self.actual_fields.get(stream, set() ).difference(self.expected_automatic_fields(stream))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to subtract automatic fields here because the automatic fields are non custom fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason to subtract automatic fields - if the replicated fields contain only automatic fields, my assertion for Not none in the next line will not verify if fields other than automatic fields are replicated or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The automatic fields are non custom fields. The test is currently making a sub-set of non_custom fields. Do we need to track both groups? All non custom fields and then all non custom fields that aren't automatic? I'm not sure we need to do this. We could have two assertions if you want to check both cases:
self.assertIsNotNone(replicated_non_custom_fields, msg)
self.assertIsNotNone(replicated_non_custom_fields.difference(self.expected_automatic_fields(stream)), msg)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the test that is still failing. I suggest not removing automatic fields from replicated_non_custom_fields. Then we can add two more assertions

  1. The first assertion to make sure that the count of non custom fields is greater than the count of automatic fields to make sure that we are replicating more than just the automatic fields.
  2. To make sure the number of non custom fields is equal to the number of replicated fields to make sure we didn't miss any.

tests/test_salesforce_all_fields_non_custom.py Outdated Show resolved Hide resolved
def test_non_custom_fields( self ):
for stream in self.streams_to_selected_fields():
expected_non_custom_fields = self.streams_to_selected_fields().get(stream, set() )
replicated_non_custom_fields = self.actual_fields.get(stream, set() ).difference(self.expected_automatic_fields(stream))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The automatic fields are non custom fields. The test is currently making a sub-set of non_custom fields. Do we need to track both groups? All non custom fields and then all non custom fields that aren't automatic? I'm not sure we need to do this. We could have two assertions if you want to check both cases:
self.assertIsNotNone(replicated_non_custom_fields, msg)
self.assertIsNotNone(replicated_non_custom_fields.difference(self.expected_automatic_fields(stream)), msg)

tests/sfbase.py Outdated
non_custom += 1
else:
custom += 1
return ( custom, non_custom )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ( custom, non_custom )
return (custom, non_custom)


def test_custom_fields( self ):
for stream in self.streams_to_selected_fields():
expected_custom_fields = self.streams_to_selected_fields().get(stream, set() )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expected_custom_fields = self.streams_to_selected_fields().get(stream, set() )
expected_custom_fields = self.streams_to_selected_fields().get(stream, set())

replicated_custom_fields = self.actual_fields.get(stream, set() ).difference(self.expected_automatic_fields(stream))

#Verify at least one custom field is replicated
self.assertIsNotNone( replicated_custom_fields, msg = f"Replication didn't return any custom fields for stream {stream}" )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertIsNotNone( replicated_custom_fields, msg = f"Replication didn't return any custom fields for stream {stream}" )
self.assertIsNotNone(replicated_custom_fields, msg = f"Replication didn't return any custom fields for stream {stream}")


#Verify only custom fields are replicated by checking the field name
num_custom, num_non_custom = self.count_custom_non_custom_fields(replicated_custom_fields)
self.assertEqual( num_non_custom, 0, "Replicated some fields that are not custom fields for stream {stream}" )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertEqual( num_non_custom, 0, "Replicated some fields that are not custom fields for stream {stream}" )
self.assertEqual(num_non_custom, 0,
"Replicated some fields that are not custom fields for stream {stream}")

def streams_to_selected_fields():
return SFBaseTest.non_custom_fields

def test_non_custom_fields( self ):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_non_custom_fields( self ):
def test_non_custom_fields(self):


def test_non_custom_fields( self ):
for stream in self.streams_to_selected_fields():
expected_non_custom_fields = self.streams_to_selected_fields().get(stream, set() )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expected_non_custom_fields = self.streams_to_selected_fields().get(stream, set() )
expected_non_custom_fields = self.streams_to_selected_fields().get(stream, set())

replicated_non_custom_fields = self.actual_fields.get(stream, set() ).difference(self.expected_automatic_fields(stream))

#Verify at least one non-custom field is replicated
self.assertIsNotNone( replicated_non_custom_fields, msg = f"Replication didn't return any non-custom fields for stream {stream}" )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertIsNotNone( replicated_non_custom_fields, msg = f"Replication didn't return any non-custom fields for stream {stream}" )
self.assertIsNotNone(replicated_non_custom_fields, msg = f"Replication didn't return any non-custom fields for stream {stream}")

replicated_non_custom_fields = self.actual_fields.get(stream, set() ).difference(self.expected_automatic_fields(stream))

#Verify at least one non-custom field is replicated
self.assertIsNotNone( replicated_non_custom_fields, msg = f"Replication didn't return any non-custom fields for stream {stream}" )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertIsNotNone( replicated_non_custom_fields, msg = f"Replication didn't return any non-custom fields for stream {stream}" )
self.assertIsNotNone(replicated_non_custom_fields, msg = f"Replication didn't return any non-custom fields for stream {stream}")


#Verify ustom fields are not replicated by checking the field name
num_custom, num_non_custom = self.count_custom_non_custom_fields(replicated_non_custom_fields)
self.assertEqual(num_custom, 0, "Replicated some fields that are custom fields for stream {stream}" )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertEqual(num_custom, 0, "Replicated some fields that are custom fields for stream {stream}" )
self.assertEqual(num_custom, 0, "Replicated some fields that are custom fields for stream {stream}")

tests/sfbase.py Outdated
from datetime import timedelta
from datetime import datetime as dt

from operator import itemgetter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unused

tests/sfbase.py Outdated
""" List all the custom_fields for each stream"""
custom_fields = {}
for stream in self.streams_to_test():
with self.subTest(stream=stream):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's any assertions in this function, so we can remove this subTest line

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do that

tests/sfbase.py Outdated
""" List all the non_custom_fields for each stream"""
non_custom_fields = {}
for stream in self.streams_to_test():
with self.subTest(stream=stream):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's any assertions in this function, so we can remove this subTest line

tests/sfbase.py Outdated
Comment on lines 940 to 941
non_custom_fields[stream] = {key for key in schema['properties'].keys() if not key.endswith("__c")
and schema['properties'][key]['inclusion']!="unsupported"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. There's two spaces between and and schema
    • There should be one
  2. There's no spaces around !=
    • There should be one on each side

Optional: I personally think if there's an if in a comprehension, it should get its own line and every and after that too. To me, it helps separate the filtering from the looping

non_custom_fields[stream] = {key 
                             for key in schema['properties'].keys() 
                             if not key.endswith("__c")
                             and schema['properties'][key]['inclusion'] != "unsupported"}

tests/sfbase.py Show resolved Hide resolved
logging=f"verify all fields are replicated for stream {stream}")

#Verify that only custome fields are replicated besides automatic fields
num_custom, num_non_custom = self.count_custom_non_custom_fields(replicated_custom_fields)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here

Comment on lines 17 to 20
def streams_to_test(self):
if self.partitioned_streams:
return self.partitioned_streams
return self.partition_streams(self.get_streams_with_data())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is repeated 4 times and should be moved to sfbase

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these tests are implement in the new tap-tester framework and the All_fields test needs this method to be present in the test as it is a abstract method in tap-tester all_fields test , if I understood it right. Do let me know if thats not the case.
https://github.com/stitchdata/tap-tester/blob/b280a171ce2ecc565d54f96bbef7cac9fe4a61ec/tap_tester/base_suite_tests/all_fields_test.py#L49

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if SFBaseTest implements it then SFNonCustomFieldsTest doesn't have to

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me try to write up a quick test

msg = f"All non_custom fields are not no replicated for stream {stream}")

#verify that automatic fields are also replicated along with non_custom_fields
self.assertTrue(self.expected_automatic_fields(stream).issubset(replicated_non_custom_fields,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertTrue(self.expected_automatic_fields(stream).issubset(replicated_non_custom_fields,
self.assertTrue(self.expected_automatic_fields(stream).issubset(replicated_non_custom_fields),

This missing paren is causing CI to fail

# Run sync
menagerie.set_state(conn_id, {})
_ = self.run_and_verify_sync(conn_id)
record_count_by_stream = self.run_and_verify_sync_mode(conn_id)
actual_streams_with_data ={stream for stream in record_count_by_stream.keys()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so you know, looping over a dictionary gives you the .keys() by default

return non_custom_fields

def test_non_custom_fields(self):
for stream in self.streams_to_selected_fields():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be wrapped in a subTest so that in one run you can see all of the failing streams?


#Verify only custom fields are replicated by checking the field name
num_custom, num_non_custom = self.count_custom_non_custom_fields(replicated_custom_fields)
self.assertEqual(num_non_custom, 0, "Replicated some fields that are not custom fields for stream {stream}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to add a second assertion that the num_custom == replicated_custom_fields + automatic fields. This will make sure we replicated them all and didn't miss any rather than making sure we replicated at least 1 with the is not none check.

@JYOTHINARAYANSETTY JYOTHINARAYANSETTY merged commit 5ae6b93 into master Oct 9, 2023
7 checks passed
@JYOTHINARAYANSETTY JYOTHINARAYANSETTY deleted the tdl-7499 branch October 9, 2023 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants