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

Conversation

mansiag
Copy link
Contributor

@mansiag mansiag commented May 20, 2020

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

  • I have read the Contribution & Best practices Guide and my PR follows them.
  • My branch is up-to-date with the Upstream development branch.
  • The unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • All the functions created/modified in this PR contain relevant docstrings.

- datetime.timedelta(days=10))
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


with self.app.test_request_context():
test_order = OrderFactory(created_at=datetime.datetime.now()
- 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

"""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

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'

@@ -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)

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

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

return humanize.naturaldelta(datetime.now(pytz.utc)
- 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

def humanize_helper(time):
"""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

from tests.factories.order import OrderFactory


class TestHumanizeHelper(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

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

return humanize.naturaldelta(datetime.now(pytz.utc)
- time.astimezone(pytz.utc)) + ' ago'
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

@iamareebjamal
Copy link
Member

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'

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)

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
Copy link

codecov bot commented May 21, 2020

Codecov Report

Merging #7022 into development will increase coverage by 0.00%.
The diff coverage is 87.50%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ
app/templates/flask_ext/jinja/filters.py 77.77% <87.50%> (+20.63%) ⬆️
app/api/role_invites.py 41.96% <0.00%> (-0.52%) ⬇️
app/api/orders.py 26.86% <0.00%> (-0.20%) ⬇️
app/api/tax.py 52.45% <0.00%> (ø)
app/api/events.py 21.70% <0.00%> (ø)
app/api/tracks.py 76.08% <0.00%> (ø)
app/api/sessions.py 41.46% <0.00%> (ø)
app/api/speakers.py 47.42% <0.00%> (ø)
app/api/sponsors.py 79.48% <0.00%> (ø)
app/api/feedbacks.py 50.64% <0.00%> (ø)
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c7f7276...ca2ee7b. Read the comment docs.

return 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.

Suggested change

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

@@ -20,5 +21,5 @@ 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

actual_response = humanize_helper(test_order.created_at)
expected_response = '10 days ago'
assert actual_response == expected_response

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)

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"

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

@niranjan94
Copy link
Member

Codacy Here is an overview of what got changed by this pull request:

Complexity increasing per file
==============================
- tests/all/integration/api/helpers/test_humanize_helper.py  3
         

See the complete overview on Codacy

@iamareebjamal iamareebjamal changed the title Remove arrow dependency from the project chore(refactor): Remove arrow dependency from the project May 22, 2020
@iamareebjamal iamareebjamal merged commit 18a19fa into fossasia:development May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove arrow from project
4 participants