-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
chore(refactor): Remove arrow dependency from the project #7022
Conversation
- datetime.timedelta(days=10)) | ||
actual_response = humanize_helper(test_order.created_at) | ||
expected_response = '10 days ago' | ||
self.assertEqual(actual_response, expected_response) |
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.
no newline at end of file
|
||
with self.app.test_request_context(): | ||
test_order = OrderFactory(created_at=datetime.datetime.now() | ||
- datetime.timedelta(days=10)) |
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.
continuation line over-indented for visual indent
"""Method to test humanization of order creation time""" | ||
|
||
with self.app.test_request_context(): | ||
test_order = OrderFactory(created_at=datetime.datetime.now() |
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.
trailing whitespace
from tests.factories.order import OrderFactory | ||
|
||
|
||
class TestHumanizeHelper(OpenEventTestCase): |
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.
Black would make changes.
trailing whitespace
undefined name 'OpenEventTestCase'
@@ -20,5 +21,4 @@ def simple_datetime_display(date): | |||
def humanize_filter(time): | |||
if not time: | |||
return "N/A" | |||
# TODO(Areeb): Only usage of arrow. Remove | |||
return arrow.get(time).humanize() | |||
return humanize_helper(time) |
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.
no newline at end of file
app/api/helpers/humanize_helper.py
Outdated
"""Returns time passed from now in a human readable duration""" | ||
|
||
return humanize.naturaldelta(datetime.now(pytz.utc) | ||
- time.astimezone(pytz.utc)) + ' ago' |
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.
continuation line under-indented for visual indent
no newline at end of file
app/api/helpers/humanize_helper.py
Outdated
def humanize_helper(time): | ||
"""Returns time passed from now in a human readable duration""" | ||
|
||
return humanize.naturaldelta(datetime.now(pytz.utc) |
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.
Black would make changes.
trailing whitespace
from tests.factories.order import OrderFactory | ||
|
||
|
||
class TestHumanizeHelper(OpenEventTestCase): |
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.
Please use new pytest style test
app/api/helpers/humanize_helper.py
Outdated
"""Returns time passed from now in a human readable duration""" | ||
|
||
return humanize.naturaldelta(datetime.now(pytz.utc) | ||
- time.astimezone(pytz.utc)) + ' ago' |
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.
Humanize adds ago automatically
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.
it adds ago with naturaltime, not with naturaldelta .
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 can use naturaltime with timedelta
humanize.naturaltime(dt.timedelta(seconds=1001)) == 16 minutes ago
Remove arrow from requirements as well |
created_at=datetime.datetime.now() - datetime.timedelta(days=10) | ||
) | ||
actual_response = humanize_helper(test_order.created_at) | ||
expected_response = '10 days ago' |
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.
Black would make changes.
# TODO(Areeb): Only usage of arrow. Remove | ||
return arrow.get(time).humanize() | ||
return humanize_helper(time) | ||
|
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.
blank line at end of file
blank line contains whitespace
Codecov Report
@@ Coverage Diff @@
## development #7022 +/- ##
============================================
Coverage 60.55% 60.55%
============================================
Files 260 259 -1
Lines 12877 12872 -5
============================================
- Hits 7798 7795 -3
+ Misses 5079 5077 -2
Continue to review full report at Codecov.
|
return humanize_helper(time) | ||
|
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.
app/api/helpers/humanize_helper.py
Outdated
import pytz | ||
|
||
|
||
def humanize_helper(time): |
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.
No need to create a new file for it, add this function in filters.py
@@ -20,5 +21,5 @@ def simple_datetime_display(date): | |||
def humanize_filter(time): | |||
if not time: | |||
return "N/A" |
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 can move this logic to the function as well and add a test for it too
actual_response = humanize_helper(test_order.created_at) | ||
expected_response = '10 days ago' | ||
assert actual_response == expected_response | ||
|
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.
blank line contains whitespace
# TODO(Areeb): Only usage of arrow. Remove | ||
return arrow.get(time).humanize() | ||
return humanize_helper(time) | ||
|
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.
blank line at end of file
blank line contains whitespace
"""Returns time passed from now in a human readable duration""" | ||
|
||
if not time: | ||
return "N/A" |
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.
Black would make changes.
over-indented
Complexity increasing per file
==============================
- tests/all/integration/api/helpers/test_humanize_helper.py 3
See the complete overview on Codacy |
Fixes #6927
Short description of what this resolves:
Removes arrow dependency from the project by using pytz and humanize libraries for the same functionality
Checklist
development
branch.