-
-
Notifications
You must be signed in to change notification settings - Fork 46
feat: added OTP #449
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: added OTP #449
Conversation
WalkthroughThis change adds a new test method in the email tests to verify the format of a retrieved OTP code and updates the mailinator helper to support this functionality. In the helper module, the deprecated Changes
Sequence Diagram(s)sequenceDiagram
participant T as TestEmail
participant M as MailinatorHelper
participant E as Email Service
T->>M: Call get_otp_code("testautomation")
loop Retry until timeout (max 30 sec)
M->>E: Retrieve email message with subject check (casefold)
E-->>M: Return email message (or None)
end
M->>M: Extract OTP code using regex
alt OTP Found
M->>T: Return 6-digit OTP code
else OTP Not Found
M->>T: Raise RuntimeError
end
T->>T: Assert OTP is a digit string of length 6
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
utilities/mailinator_helper.py (1)
103-131: Consider parameterizing the email subject in get_otp_code method.The method works well but has a hard-coded email subject "Verify your email address". To make the method more reusable, consider making the email subject a parameter with a default value.
Also, the regex pattern will match any 6-digit number in the email. If the email could contain multiple 6-digit numbers, you might need a more specific pattern.
- def get_otp_code(self, user_email: str) -> str | None: + def get_otp_code(self, user_email: str, email_subject: str = "Verify your email address") -> str | None: """Retrieves a 6-digit OTP code from an email in the Mailinator inbox. This method: 1. Waits for up to 30 seconds, polling every second, for an email to arrive. 2. Retrieves the email message from Mailinator. 3. Extracts the first 6-digit OTP code found in the email body. Args: user_email (str): The email address to check for an OTP. + email_subject (str, optional): The subject of the email containing the OTP. + Defaults to "Verify your email address". Returns: str: The extracted 6-digit OTP code. Raises: RuntimeError: If no OTP is found in the email message. """ - message: Message = self.get_message(user_email, "Verify your email address") + message: Message = self.get_message(user_email, email_subject) if not message.parts: return None email_body = message.parts[0].body if match := re.search(r"\b(\d{6})\b", email_body): return match[1] raise RuntimeError("OTP not found in email message")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
tests/email_test.py(1 hunks)utilities/mailinator_helper.py(4 hunks)
🔇 Additional comments (3)
tests/email_test.py (1)
23-27: LGTM! Good test coverage for OTP format.The test correctly verifies that the OTP code retrieved from the email is a 6-digit number. The assertions include helpful error messages that will make debugging failures easier.
utilities/mailinator_helper.py (2)
39-43: Good refactoring of the retry logic.The updated retry decorator simplifies the code by using an inline lambda instead of a separate
is_nonemethod, making the code more maintainable.
74-74: Great improvement for case-insensitive comparison.Using
casefold()instead of basic lowercase/uppercase comparison is more robust for international text. This is a good practice for string comparisons.
Description
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist:
Summary by CodeRabbit