twilio-python
twilio-python copied to clipboard
test: added test for Video Room, fix: resolved conflict of duplicated names, enhanced code of 'time' logic
feat(jwt): Improve JWT expiration handling and fix naming conflicts
- Replaced
time.time()withdatetime.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
algorithmtojwt_algorithmto avoid conflicts with theALGORITHMconstant and ensure consistency.
test(twilio): Add unit test for Twilio Video Room creation
- Integrated
unittestframework for structured testing. - Used
responseslibrary to mock Twilio API calls. - Implemented a test case that validates room creation by checking
sid,unique_name, andstatus.
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()withdatetime.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.
- Replaced
-
Resolved SonarCloud issue (Naming Conflict with ALGORITHM):
- Renamed
algorithmparameter tojwt_algorithmto prevent confusion with theALGORITHMconstant. - This improves maintainability by avoiding case-sensitive conflicts in variable names.
- Renamed
-
Added a new unit test for Twilio Video Room creation:
- Integrated
unittestframework for structured testing. - Mocked Twilio API calls using the
responseslibrary. - Verified room creation by checking
sid,unique_name, andstatus. - Note: Existing tests already cover the JWT expiration fix, so no additional tests were needed for that.
- Integrated
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
.mdfile (not required).
If you have questions, please file a support ticket, or create a GitHub Issue in this repository.