-
-
Notifications
You must be signed in to change notification settings - Fork 66
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
base: master
Are you sure you want to change the base?
Conversation
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 Report
@@ 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
Continue to review full report at Codecov.
|
cfa9521
to
0619733
Compare
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.
0619733
to
4bde111
Compare
All green! I've ensured that everything that @madisvain changed is now covered by tests. |
@DEKHTIARJonathan Yes, it will be merged once I've done the review, please don't ask questions like that. |
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.
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 |
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.
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}…', task.name[0:15]) |
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 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
.
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.
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 |
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.
There is 0.3.10, please update.
|
||
from freezegun import freeze_time | ||
|
||
from django_celery_monitor.admin import colored_state, node_state, eta,\ |
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 parenthesis for implied line-continuation instead of a backslash here.
tstamp, name | ||
|
||
|
||
class ColoredStateTest(TestCase): |
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 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' \ |
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 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 |
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 don't remove 1.8, 1.9. and 1.10 yet.
@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 |
You mention using v4.2 in the ticket. As far as I know, this is pre-release software. |
@pieterdd Can you try rebasing? |
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.