twilio-python icon indicating copy to clipboard operation
twilio-python copied to clipboard

test: added test for Video Room, fix: resolved conflict of duplicated names, enhanced code of 'time' logic

Open dlunaaa opened this issue 9 months ago • 0 comments

feat(jwt): Improve JWT expiration handling and fix naming conflicts

  • Replaced time.time() with datetime.datetime.utcnow() to ensure accurate expiration handling.
  • Used datetime.timedelta(seconds=...) for better timestamp calculations.
  • Ensured compatibility with jwt.encode() by converting expiration times using .timestamp().
  • Renamed algorithm to jwt_algorithm to avoid conflicts with the ALGORITHM constant and ensure consistency.

test(twilio): Add unit test for Twilio Video Room creation

  • Integrated unittest framework for structured testing.
  • Used responses library to mock Twilio API calls.
  • Implemented a test case that validates room creation by checking sid, unique_name, and status.

These changes enhance JWT handling, resolve potential naming conflicts, and introduce automated testing for Twilio API interactions.

Fixes #777

Summary of Changes

This PR addresses the following improvements:

  • Fix for Issue #777 (JWT Expiration Handling):

    • Replaced time.time() with datetime.datetime.utcnow() to ensure accurate expiration calculations.
    • Applied datetime.timedelta(seconds=...) to improve timestamp consistency.
    • Ensured compatibility with jwt.encode() by converting expiration times using .timestamp().
    • These changes improve time handling accuracy, ensuring JWTs expire correctly across different time zones.
  • Resolved SonarCloud issue (Naming Conflict with ALGORITHM):

    • Renamed algorithm parameter to jwt_algorithm to prevent confusion with the ALGORITHM constant.
    • This improves maintainability by avoiding case-sensitive conflicts in variable names.
  • Added a new unit test for Twilio Video Room creation:

    • Integrated unittest framework for structured testing.
    • Mocked Twilio API calls using the responses library.
    • Verified room creation by checking sid, unique_name, and status.
    • Note: Existing tests already cover the JWT expiration fix, so no additional tests were needed for that.

Checklist

  • [x] I acknowledge that all my contributions will be made under the project's license.
  • [x] I have made a material change to the repo (functionality, testing, spelling, grammar).
  • [x] I have read the Contribution Guidelines and my PR follows them.
  • [x] I have titled the PR appropriately.
  • [x] I have updated my branch with the main branch.
  • [x] I have added inline documentation to the code I modified.
  • [ ] I have added tests that prove my fix is effective or that my feature works (not required, as existing tests already cover the fix).
  • [ ] I have added the necessary documentation about the functionality in the appropriate .md file (not required).

If you have questions, please file a support ticket, or create a GitHub Issue in this repository.

dlunaaa avatar Feb 25 '25 16:02 dlunaaa