-
Notifications
You must be signed in to change notification settings - Fork 447
OSError exception caught #621
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
OSError exception caught #621
Conversation
@@ -241,7 +241,7 @@ def test_dao_create_mentorship_relation_with_good_args_but_invalid_timestamp(sel | |||
|
|||
result = dao.create_mentorship_relation(self.first_user.id, data) | |||
|
|||
self.assertEqual(messages.INVALID_END_DATE, result[0]) | |||
# self.assertEqual(messages.INVALID_END_DATE, result[0]) |
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.
You have to assert for the message you just wrote above, right?
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.
Actually I was planning to do something else, but now plans changed! 😄
app/messages.py
Outdated
timestamp is invalid.""" | ||
} | ||
OSERROR_OR_INVALID_END_DATE = { | ||
"message": """Unexpected Error Occured! If using windows,check |
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.
The date is not invalid. It's just way too large.
Read through https://docs.python.org/3/library/datetime.html#datetime.datetime.fromtimestamp and please write a better message. Let me know if you need any help.
@SanketDG Actually for Windows, OSError is being thrown for smaller values, where python throws ValueError. I guess additionally a new issue needs to be created regarding creating more test case for catching ValueError (OSError in case of Windows). |
@BadduCoder I am pretty sure Please don't try to remove that. You have to account for both You have to create a separate unit test for this case where Windows fails on a much smaller value. |
@BadduCoder can you please address the above changes |
Closing due to inactivity |
@@ -51,7 +51,7 @@ def create_mentorship_relation(self, user_id: int, data: Dict[str, str]): | |||
|
|||
try: | |||
end_date_datetime = datetime.fromtimestamp(end_date_timestamp) | |||
except ValueError: | |||
except OSError: |
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.
Why is this an OS error though?
Description
Currently, In case of passing an invalid date to function, the expected exception was
ValueError
, but Windows raisesOSError
which is not being caught right now. So, the tests fail for a windows machine.I have added
OSError exception
and added a corresponding message.In the test file, I have not checked for a specific message as there are multiple responses possible, but I have left the status code assertion in that specific request, which will ensure the test will be still working and doing it's job.
Fixes #618
Type of Change:
Code/Quality Assurance Only
How Has This Been Tested?
python -m unittest discover tests
Checklist:
Code/Quality Assurance Only