-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
Use mocked exec_msar_func
calls for RPC tests
#4015
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start, but:
You should check the whole call to exec_msar_func
, including the connection and function name. This helps these tests catch a whole bunch of easy-to-make errors as we modify the python wrappers.
actual_result = columns.patch( | ||
column_data_list=column_data_list, | ||
table_oid=table_oid, | ||
database_id=database_id, | ||
request=request | ||
) | ||
call_args = mocked_exec_msar_func.call_args_list[0][0] | ||
transformed_column_data = [ | ||
_transform_column_alter_dict(column) for column in column_data_list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, I'd prefer avoiding using this function in this test. The reason is that it makes it harder to modify the underlying function (e.g., making it so that we don't even need the transform function), since it breaks this test for unrelated reasons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point @mathemancer, but, for the case you're describing I think I would prefer if the test did break, since the way the function under test used to work has changed.
If we were to not use these functions in these tests however, here are some of the possible ways I see to achieve that:
- Not checking
assert call_args[3] == json.dumps(transformed_column_data)
(Doesn't seem ideal). - Hardcoding the result from the function in the test (Test would still fail if the behavior of the underlying function changes).
- Using the transformed result as an argument to API call in the test (Test fails since the underlying function expects the argument to be not transformed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer (2).
- It clearly specifies the actual form that needs to be made to the DB layer.
- It verifies that no changes in the transformation have happened unintentionally, for example if someone were to introduce a bug in the
_transform_column_alter_dict
function itself. - It detaches the test from the internal implementation of the function being tested as much as possible.
I agree the test should break if we align the API column_data_list
with the form of the SQL layer column_data_list
, but we don't want it to break because (for example) the function being used in the test is now missing, which it would in that case with this test as currently written. We want it to break because we expect the input and output to be different, but they're now the same. I.e., we want the test assertion to say "Hey! this JSON isn't what I expected", not "Hey! There's a private function missing!".
Hopefully that makes sense.
assert actual_col_list == expect_col_list | ||
assert call_args[2] == table_oid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should check all the arguments. That way, if someone fatfingers a function name down the road (i.e., messes up the string describing the SQL function), or accidentally switches the order of the connection and function name, this will catch it. Same for the other similar tests.
Also, we should use something more identifiable than True
for the mock connect yield. Maybe something like:
class MockConnection:
pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should check all the arguments. That way, if someone fatfingers a function name down the road (i.e., messes up the string describing the SQL function), or accidentally switches the order of the connection and function name, this will catch it.
@mathemancer These conditions are already covered by test_db_wrapper
. Not only will it check whether the 2nd argument in each exec_msar_func
call is a string, it'll also verify that a function specified in the string exists on the underlying database. This would mean that we would also catch any accidentally switches of order between the connection and function name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhhh you're right. I forgot about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, LGTM!
Checklist
Update index.md
).develop
branch of the repositoryvisible errors.
Developer Certificate of Origin
Developer Certificate of Origin