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 all 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
17 changes: 12 additions & 5 deletions app/templates/flask_ext/jinja/filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import arrow
from datetime import datetime

from forex_python.converter import CurrencyCodes
import humanize
import pytz


def humanize_helper(time):
"""Returns time passed from now in a human readable duration"""

if not time:
return "N/A"
return humanize.naturaltime(datetime.now(pytz.utc) - time.astimezone(pytz.utc))

def init_filters(app):
@app.template_filter('currency_symbol')
Expand All @@ -18,7 +28,4 @@ def simple_datetime_display(date):

@app.template_filter('humanize')
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)
1 change: 0 additions & 1 deletion requirements/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ gunicorn==20.0.4
boto==2.49
geoip2==3.0.0
SQLAlchemy-Continuum==1.3.10
arrow==0.15.5 # TODO(Areeb): Only used in 1 place. Removes
bleach==3.1.5
stripe==2.48.0
xhtml2pdf==0.2.4
Expand Down
19 changes: 19 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,19 @@
import datetime

from app.templates.flask_ext.jinja.filters import humanize_helper
from tests.factories.order import OrderFactory


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

test_order = OrderFactory(
created_at=datetime.datetime.now() - datetime.timedelta(days=10)
)
actual_response = humanize_helper(test_order.created_at)
expected_response = '10 days ago'

Choose a reason for hiding this comment

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

Black would make changes.

assert actual_response == expected_response

actual_response = humanize_helper(test_order.completed_at)
expected_response = 'N/A'
assert actual_response == expected_response