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

Django 2.0 compatibility and improved test coverage #60

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

pieterdd
Copy link

This pull request builds on #40. However, it was failing some code checks because - I assume - the test coverage was lacking. So here are their changes, some additional CI changes and extra unit tests.

madisvain and others added 14 commits December 8, 2017 00:03
This speeds up builds, and it's good practice to upgrade to Django 1.11
(last Python 2 version, LTS) or Django 2.0 anyway.
I discovered a bug in the name() function while writing these. The
abbrtask() function from Celery doesn't actually do what the docstring
of the name() function promises, so I changed the implementation to
something simpler.
@codecov
Copy link

codecov bot commented Feb 14, 2018

Codecov Report

Merging #60 into master will increase coverage by 7.64%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #60      +/-   ##
==========================================
+ Coverage   72.58%   80.22%   +7.64%     
==========================================
  Files           9        9              
  Lines         434      435       +1     
  Branches       54       55       +1     
==========================================
+ Hits          315      349      +34     
+ Misses        114       73      -41     
- Partials        5       13       +8
Impacted Files Coverage Δ
django_celery_monitor/admin.py 64.75% <100%> (+11.03%) ⬆️
django_celery_monitor/utils.py 76.19% <100%> (+11.11%) ⬆️
django_celery_monitor/humanize.py 54.76% <0%> (+30.95%) ⬆️

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 6ec1350...4bde111. Read the comment docs.

@pieterdd pieterdd force-pushed the improve-tests branch 3 times, most recently from cfa9521 to 0619733 Compare February 14, 2018 14:36
Pieter De Decker added 2 commits February 14, 2018 15:49
Also:
- Remove usage of mark_safe that caused undesired side effects and
theoretically allowed for cross-site scripting vulnerabilities.
- Don't pretty print strings. This causes strange behavior that's
inconsistent across certain Python/Django combinations.
@pieterdd
Copy link
Author

All green! I've ensured that everything that @madisvain changed is now covered by tests.

@DEKHTIARJonathan
Copy link

@jezdez Do you think this PR will be ever merged ? I actively support the work of @pieterdd in this PR

@jezdez
Copy link
Member

jezdez commented Mar 6, 2018

@DEKHTIARJonathan Yes, it will be merged once I've done the review, please don't ask questions like that.

Copy link
Member

@jezdez jezdez left a comment

Choose a reason for hiding this comment

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

This needs some more work.

# Allows freezing of current time in tests
freezegun==0.3.9

# Provides unittest.mock when running the test suite on Python 2
Copy link
Member

Choose a reason for hiding this comment

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

That comment seems wrong, the mock package doesn't provide unittest.mock but mock. unittest.mock just happens to be a port to Python 3.x which we could use if we'd only support Python 3.x.

)
short_name = task.name
if task.name and len(task.name) > 16:
short_name = format_html('{0}&hellip;', task.name[0:15])
Copy link
Member

Choose a reason for hiding this comment

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

Please continue to use abbrtask here since it does more than what this code does. Just cutting off the task name would make identifiying a task with a long import path hard to read.

E.g. Imagine a task with the name myproject.some_complex_app.under_module.tasks.version_2.whatever_task (something that I've seen myself). In that case I wouldn't even see the task name with this new code. Instead abbrtask will show [.]whatever_task.

Copy link
Author

@pieterdd pieterdd Mar 8, 2018

Choose a reason for hiding this comment

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

Although I'm sympathetic to your concerns about the way it abbreviates names, sticking with abbrtask from Celery simply didn't seem like an option.

The abbrtask function from Celery doesn't actually do what the docstring of the name function promises. It doesn't cut off at the requested amount of characters. So when I wrote unit tests for the name function, I found behavior that contradicts promises made in the docstring.

I had to choose between:

  • Rewriting the failing test to accept incorrect behavior
  • Sticking with the abbrtask function but doing postprocessing on it as a workaround
  • Stop using the abbrtask function

I went for option 3. Would you make a different choice?

@@ -2,3 +2,9 @@ case>=1.3.1
pytest>=3.0
pytest-django==3.1.2
pytz>dev

# Allows freezing of current time in tests
freezegun==0.3.9
Copy link
Member

Choose a reason for hiding this comment

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

There is 0.3.10, please update.


from freezegun import freeze_time

from django_celery_monitor.admin import colored_state, node_state, eta,\
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 parenthesis for implied line-continuation instead of a backslash here.

tstamp, name


class ColoredStateTest(TestCase):
Copy link
Member

Choose a reason for hiding this comment

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

Please move all the tests under a common TestCase class, e.g. AdminDisplayFieldTests and use proper unittest assert methods (self.assertEqual etc) instead of the assert statement.

"""
mock_task = Mock()
mock_task.name = '1234567890123456'
expected_html = '<div title="1234567890123456"><b>1234567890123456' \
Copy link
Member

Choose a reason for hiding this comment

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

Please don't use backslashes for line continuation.

@@ -24,10 +24,8 @@ deps=
-r{toxinidir}/requirements/test.txt
-r{toxinidir}/requirements/test-ci.txt

dj18: django>=1.8,<1.9
Copy link
Member

Choose a reason for hiding this comment

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

Please don't remove 1.8, 1.9. and 1.10 yet.

@DEKHTIARJonathan
Copy link

@pieterdd : I have the event worker which crashed without any reason without leaving anything on the logs every +/- 24hours. Do you think this could be caused by your modifications ?

I have opened an issue on the official celery repository about this: celery/celery#4623

@pieterdd
Copy link
Author

pieterdd commented Apr 5, 2018

You mention using v4.2 in the ticket. As far as I know, this is pre-release software.

@tony
Copy link
Member

tony commented Jun 19, 2019

@pieterdd Can you try rebasing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants