Skip to content
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

Merged
merged 8 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/api/helpers/humanize_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from datetime import datetime

import humanize
import pytz


def humanize_helper(time):
Copy link
Member

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

"""Returns time passed from now in a human readable duration"""

return humanize.naturaldelta(datetime.now(pytz.utc)

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

- time.astimezone(pytz.utc)) + ' ago'

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Humanize adds ago automatically

Copy link
Contributor Author

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 .

Copy link
Member

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

6 changes: 3 additions & 3 deletions app/templates/flask_ext/jinja/filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import arrow
from forex_python.converter import CurrencyCodes

from app.api.helpers.humanize_helper import humanize_helper


def init_filters(app):
@app.template_filter('currency_symbol')
Expand All @@ -20,5 +21,4 @@ def simple_datetime_display(date):
def humanize_filter(time):
if not time:
return "N/A"
Copy link
Member

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

# TODO(Areeb): Only usage of arrow. Remove
return arrow.get(time).humanize()
return humanize_helper(time)

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

16 changes: 16 additions & 0 deletions tests/all/integration/api/helpers/test_humanize_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import datetime

from app.api.helpers.humanize_helper import humanize_helper
from tests.factories.order import OrderFactory


class TestHumanizeHelper(OpenEventTestCase):

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'

Copy link
Member

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

def test_humanize_helper(self):
"""Method to test humanization of order creation time"""

with self.app.test_request_context():
test_order = OrderFactory(created_at=datetime.datetime.now()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing whitespace

- datetime.timedelta(days=10))

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

actual_response = humanize_helper(test_order.created_at)
expected_response = '10 days ago'
self.assertEqual(actual_response, expected_response)

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