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

Feat 1695 testing concept #15

Merged
merged 12 commits into from
Jun 21, 2024
Merged

Feat 1695 testing concept #15

merged 12 commits into from
Jun 21, 2024

Conversation

parth-kulkarni1
Copy link
Collaborator

Jira-1695 (Major/Minor/Bug Fix): Major

JIRA Ticket 1695

Checklist

  • If tests are required for this change, are they implemented?
  • Are user documentation changes required, if so, is there a task to track it and/or is it completed?
  • If developer/system documentation updates are required, is there a task to track it and/or is it completed?
  • At least one developer has reviewed this change (unless PR is being used to mark a commit point without need for review)?

Description

  1. Completed unit tests across L1, and L2 layers exploring various scenarios by mocking the httpx client.
  2. Added method to identify exceptions thrown in the exception chain, due to our L2 layer returning a general exception.
  3. Changed typing of params argument to use Mapping, some weird issues were going on where it couldn't accept dict[str,str] as a type even though it should according to the original type hint.
  4. Changed CI/CD script to only trigger once and updated pyproject.toml file release_to_pyPI configuration, thus we should not have to use the hacky workaround to release the library.

Notes for reviewer

Copy link
Contributor

@PeterBaker0 PeterBaker0 left a comment

Choose a reason for hiding this comment

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

Great work - it was a tricky set of testing to organise - couple of minor changes suggested but otherwise looks good.

"""

@pytest.mark.asyncio
async def test_http_client_get_request_mock(httpx_mock: HTTPXMock) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

is httpx_mock a fixture - if so could it be put with the other fixtures above? or am I missing something

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

httpx_mock is a fixture imported from pytest-httpx.

Comment on lines +308 to +309
assert is_exception_in_chain(exec_info.value, httpx.ConnectError), "httpx.ConnectError not found in exception chain"
assert error_message in str(exec_info.value), f"Error message: {error_message} not found in Exception."
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool this seems good

Comment on lines 27 to 53
class MockedAuthService(AuthManager):

def __init__(self) -> None:
self.token = "mock_access_token"
self.refresh_token = "mock_refresh_token"
self.public_key = "mock_public_key"

def refresh_tokens(self) -> None:
"""Simulate refreshing tokens."""
self.token = "refreshed_mock_access_token"
self.refresh_token = "refreshed_mock_refresh_token"

def force_refresh(self) -> None:
"""Simulate force refreshing tokens."""
self.refresh_tokens()

def get_token(self) -> str:
"""Return the mock access token."""
return self.token

def get_auth(self) -> HttpxBearerAuth:
"""Return a mock HttpxBearerAuth object."""
return HttpxBearerAuth(token=self.token)

def validate_token(self, tokens: Tokens) -> bool:
"""Simulate token validation."""
return True
Copy link
Contributor

Choose a reason for hiding this comment

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

can you simplify this to just the base class methods?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

okay I have updated accordingly.

while current_exception:
if isinstance(current_exception, exception_type):
return True
current_exception = current_exception.__context__
Copy link
Contributor

Choose a reason for hiding this comment

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

will this attribute always exist? Maybe wrap a try/catch around this line and if it fails return False - feels a little dangerous

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah okay I see what you mean here, I think given that all our exceptions are using default Python Exceptions/ our custom exceptions are inherited from Exception itself, I think the context attribute will always exist, but just for safety I will wrap a try-catch around it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure what type of exceptions to throw with this, so just throwing a general Exception in the try except block.

@parth-kulkarni1 parth-kulkarni1 merged commit 8c52602 into main Jun 21, 2024
2 checks passed
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.

2 participants