Implement a JSON Review UI that allow user to perform actions on json files
Review Request #9515 — Created Jan. 21, 2018 and updated
Json files is handled as an uneditble attachments in the current
version.
I implemented a new classJSONReviewUI
that
enhence Review board's ability to process JSON file.New features include:
- Rendering JSON in an easy-to-read format.
- Allowing the user to comment on the prettified file based on
line numbers. - Auto-sorting of output keys.
- Allow user to compare the changes of files in diffs
- A thumbnail that render in the easy-to-read format, too.
Ran unit tests.
Tested the development environment with:
- Properly formatted JSON files.
- JSON files with long lines.
- Minified JSON files.
- Highly-nested JSON files.
Description | From | Last Updated |
---|---|---|
Can you wrap your description at 72 characters and format it as markdown? We can do stuff like: New features … |
|
|
As for your testing done, how about: Ran unit tests. Tested the development environment with: - Properly formatted JSON files. … |
|
|
This needs some unit tests ensuring that (at a minimum): the JSON UI is used for JSON files prettified JSON … |
|
|
How about JSONReviewUI ? It's a little shorter and gets the same point across. |
|
|
All methods should have docstring documenting what they do. Check out this guide for our docstring requirements. |
|
|
Do you need to explicitly open the file when use already use the with keyword? or do something like with … |
FL floriecai | |
Is the indent always going to be 4? Maybe keep as a constant? |
FL floriecai | |
Just out of curiosity, what does the _ do before the string? |
FL floriecai | |
Typo: hekper -> helper |
FL floriecai | |
Not sure if this will be a problem - but does os.path.join correctly change slashes based on the appropriate os? |
FL floriecai | |
Keep the function names consistent, so: test_wrong_formatted_JSON |
FL floriecai | |
inconsistent function naming: test_prettified_JSON |
FL floriecai | |
Instead of adding this to the text mimetype, I think we need a new JSONMimetype class that can run the … |
|
|
Can you add a module docstring at the top of this file? |
|
|
This is kind of a weird docstring, and doesn't explain what the return (yield) type is. How about: """Render the … |
|
|
Let's just revert the changes to this file. We should clean up docstrings here (eventually), but it shouldn't be part … |
|
|
Standard library imports should go in a section above 3rd-party imports. |
|
|
This docstring isn't in the proper format. How about just """Set up state for ImageReviewUI tests.""" |
|
|
This should probably be called JSONReviewUITests to match the naming elsewhere. |
|
|
No blank line here. |
|
|
Blank line between these. This should also say "JSONReviewUI" to match the name of the class. |
|
|
Docstring summaries need to start with capital letters and end in periods. This also needs Args and Returns sections to … |
|
|
We should put test data in a directory called "testdata", not "testJsonData". Right now we also have a weird mix … |
|
|
Blank line above this. |
|
|
file is a reserved word in Python. Let's change this name. |
|
|
It's kind of weird to have this set self.attachment as a side effect and then return the uploaded file object … |
|
|
There's an extra space at the end of this docstring. Test docstrings should also always start with "Testing" and include … |
|
|
Just initializing the review UI won't actually run the render function. I think you forgot the code to test get_rendered_lines() |
|
|
Same comment about docstrings. How about: Testing JSONReviewUI render with invalid JSON |
|
|
Can we rename all of these test files to be lower-case with hyphens instead of camelCase or CamelCase? |
|
|
u prefixes on strings aren't necessary since we import unicode_literals. You also don't need to use + to concatenate multiple … |
|
|
Format is wrong here and there's some spelling errors. How about: Testing JSONReviewUI indenting and sorting |
|
|
F401 'django.utils.translation.ugettext as _' imported but unused |
![]() |
|
Undo this. ) should be on the previous line. |
|
|
These should be grouped with the other 3rd-party imports (back where they were) |
|
|
Since we're inheriting from TextMimetype we don't need to redefine these. |
|
|
typo: beautifed -> beautified |
|
|
TextMimetype isn't used |
|
|
Can you keep these names in alphabetical order? |
|
|
Json -> JSON |
|
|
This should fit on one line. |
|
|
Keep in alphabetical order |
|
|
Keep in alphabetical order. |
|
|
Instead of using logging.error with exc_info=True, you can use logging.exception. |
|
|
Docstring isn't in the proper format. Let's just avoid making any changes to this file--if we want to clean up … |
|
|
Test docstrings shouldn't end in periods (since the test runner will add "...") |
|
|
Test docstrings shouldn't end in periods (since the test runner will add "...") |
|
|
Since this is an internal helper, let's add a leading underscore: _get_json_file |
|
|
This needs to be the fully-qualified module path of the type: reviewboard.attachments.models.FileAttachment |
|
|
The directory should be called testdata, not testData. |
|
|
You're still storing this in self.attachment and then calling this method as if it doesn't have a return value. This … |
|
|
Test docstrings shouldn't end in periods (since the test runner will add "...") |
|
|
No blank line here. |
|
|
Don't we want to assert something in here? |
|
|
Test docstrings shouldn't end in periods (since the test runner will add "...") |
|
|
No blank line here. |
|
|
Test docstrings shouldn't end in periods (since the test runner will add "...") |
|
|
No blank line here. |
|
|
We should still wrap by putting everything in parens instead of using the continuation character. |
|
|
This should probably be the same as the class docstring ("A review UI for JSON files") |
|
|
"Review UI" -> "review UI" |
|
|
The line break here is ugly. Please combine these. |
|
|
Blank line isn't necessary here. |
|
|
Blank line isn't necessary here. |
|
|
json file -> JSON file |
|
|
Should list a type in parens: filename (unicode): |
|
|
Indent this 4 more spaces. |
|
|
This is an extra call to get_rendered_lines which is not needed. |
|
|
It might be nicer to hard-code the "correct" result rather than running it through the review UI. Right now if … |
|
|
We wrap long strings with the space characters and the end of previous lines instead of the start of the … |
|
|
Same here--let's hard-code the correct output instead of running it through the review UI. |
|
Summary: |
|
|||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description: |
|
-
-
Can you wrap your description at 72 characters and format it as markdown?
We can do stuff like:
New features include: - Rendering JSON in an easy-to-read format. - Allowing the user to comment on the prettified file based on line numbers. - Auto-sorting of output keys.
etc.
Which will render as a list.
-
As for your testing done, how about:
Ran unit tests. Tested the development environment with: - Properly formatted JSON files. - JSON files with long lines. - Minified JSON files. - Highly-nested JSON files.
The coverage percentage is not required.
-
This needs some unit tests ensuring that (at a minimum):
- the JSON UI is used for JSON files
- prettified JSON files are ordered consistently between viewings
- output is actually prettified
-
reviewboard/reviews/ui/jsonui.py (Diff revision 1) How about
JSONReviewUI
? It's a little shorter and gets the same point across. -
reviewboard/reviews/ui/jsonui.py (Diff revision 1) All methods should have docstring documenting what they do. Check out this guide for our docstring requirements.
Description: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Testing Done: |
|
Checks run (2 succeeded)
Description: |
|
---|
-
-
reviewboard/reviews/ui/jsonui.py (Diff revision 2) Do you need to explicitly open the file when use already use the
with
keyword? or do something like
with open(self.obj.file) as f:
-
reviewboard/reviews/ui/jsonui.py (Diff revision 2) Is the indent always going to be 4? Maybe keep as a constant?
-
reviewboard/reviews/ui/jsonui.py (Diff revision 2) Just out of curiosity, what does the _ do before the string?
-
-
reviewboard/reviews/ui/tests.py (Diff revision 2) Not sure if this will be a problem - but does
os.path.join
correctly change slashes based on the appropriate os? -
reviewboard/reviews/ui/tests.py (Diff revision 2) Keep the function names consistent, so:
test_wrong_formatted_JSON
-
reviewboard/reviews/ui/tests.py (Diff revision 2) inconsistent function naming:
test_prettified_JSON
Change Summary:
fixed the issur that Florie indicated
Diff: |
Revision 3 (+184 -2)
|
---|
Checks run (2 succeeded)
-
-
reviewboard/attachments/mimetypes.py (Diff revision 3) Instead of adding this to the text mimetype, I think we need a new JSONMimetype class that can run the source through DjbletsJSONEncoder like the JSONReviewUI does.
-
reviewboard/reviews/ui/jsonui.py (Diff revision 3) Can you add a module docstring at the top of this file?
-
reviewboard/reviews/ui/jsonui.py (Diff revision 3) This is kind of a weird docstring, and doesn't explain what the return (yield) type is. How about:
"""Render the text. This will render the JSON file in a more readable manner, reindenting the output, sorting keys within dictionaries, and applying syntax highlighting. Yields: unicode: Each line of the rendered output. """
-
reviewboard/reviews/ui/markdownui.py (Diff revision 3) Let's just revert the changes to this file. We should clean up docstrings here (eventually), but it shouldn't be part of this change.
-
reviewboard/reviews/ui/tests.py (Diff revision 3) Standard library imports should go in a section above 3rd-party imports.
-
reviewboard/reviews/ui/tests.py (Diff revision 3) This docstring isn't in the proper format. How about just
"""Set up state for ImageReviewUI tests."""
-
reviewboard/reviews/ui/tests.py (Diff revision 3) This should probably be called
JSONReviewUITests
to match the naming elsewhere. -
-
reviewboard/reviews/ui/tests.py (Diff revision 3) Blank line between these. This should also say "JSONReviewUI" to match the name of the class.
-
reviewboard/reviews/ui/tests.py (Diff revision 3) Docstring summaries need to start with capital letters and end in periods. This also needs Args and Returns sections to explain what
file_directory
is and what the return value is.I think
file_directory
should also be called eitherfilename
orjson_file
. Because it's not a directory at all. -
reviewboard/reviews/ui/tests.py (Diff revision 3) We should put test data in a directory called "testdata", not "testJsonData".
Right now we also have a weird mix of using os.path.join and string concatenation. Everything should be passed in to join and we shouldn't have any directory separators:
file_path = os.path.join( os.path.dirname(__file__), 'testdata', filename)
-
-
reviewboard/reviews/ui/tests.py (Diff revision 3) file
is a reserved word in Python. Let's change this name. -
reviewboard/reviews/ui/tests.py (Diff revision 3) It's kind of weird to have this set
self.attachment
as a side effect and then return the uploaded file object (which nothing uses). Let's change this to return the attachment instead of storing it inself
. -
reviewboard/reviews/ui/tests.py (Diff revision 3) There's an extra space at the end of this docstring. Test docstrings should also always start with "Testing" and include full context. How about:
Testing JSONReviewUI rendering nested objects
-
reviewboard/reviews/ui/tests.py (Diff revision 3) Just initializing the review UI won't actually run the render function. I think you forgot the code to test
get_rendered_lines()
-
reviewboard/reviews/ui/tests.py (Diff revision 3) Same comment about docstrings. How about:
Testing JSONReviewUI render with invalid JSON
-
reviewboard/reviews/ui/tests.py (Diff revision 3) Can we rename all of these test files to be lower-case with hyphens instead of camelCase or CamelCase?
-
reviewboard/reviews/ui/tests.py (Diff revision 3) u prefixes on strings aren't necessary since we import
unicode_literals
. You also don't need to use + to concatenate multiple lines (python will concatenate adjacent strings, like C). -
reviewboard/reviews/ui/tests.py (Diff revision 3) Format is wrong here and there's some spelling errors. How about:
Testing JSONReviewUI indenting and sorting
Diff: |
Revision 4 (+284 -10) |
---|
Checks run (1 failed, 1 succeeded)
flake8
-
reviewboard/attachments/mimetypes.py (Diff revision 4) F401 'django.utils.translation.ugettext as _' imported but unused
Description: |
|
---|
-
-
-
reviewboard/attachments/mimetypes.py (Diff revision 5) These should be grouped with the other 3rd-party imports (back where they were)
-
reviewboard/attachments/mimetypes.py (Diff revision 5) Since we're inheriting from TextMimetype we don't need to redefine these.
-
-
-
-
-
-
-
-
reviewboard/reviews/ui/jsonui.py (Diff revision 5) Instead of using
logging.error
withexc_info=True
, you can uselogging.exception
. -
reviewboard/reviews/ui/markdownui.py (Diff revision 5) Docstring isn't in the proper format. Let's just avoid making any changes to this file--if we want to clean up code, it should be in separate changes.
-
reviewboard/reviews/ui/tests.py (Diff revision 5) Test docstrings shouldn't end in periods (since the test runner will add "...")
-
reviewboard/reviews/ui/tests.py (Diff revision 5) Test docstrings shouldn't end in periods (since the test runner will add "...")
-
reviewboard/reviews/ui/tests.py (Diff revision 5) Since this is an internal helper, let's add a leading underscore:
_get_json_file
-
reviewboard/reviews/ui/tests.py (Diff revision 5) This needs to be the fully-qualified module path of the type:
reviewboard.attachments.models.FileAttachment
-
reviewboard/reviews/ui/tests.py (Diff revision 5) The directory should be called
testdata
, nottestData
. -
reviewboard/reviews/ui/tests.py (Diff revision 5) You're still storing this in
self.attachment
and then calling this method as if it doesn't have a return value. This should just be:return form.create()
and then below, in the test methods:
ui = JSONReviewUI(self.review_request, self.get_json_file('filename.json'))
-
reviewboard/reviews/ui/tests.py (Diff revision 5) Test docstrings shouldn't end in periods (since the test runner will add "...")
-
-
-
reviewboard/reviews/ui/tests.py (Diff revision 5) Test docstrings shouldn't end in periods (since the test runner will add "...")
-
-
reviewboard/reviews/ui/tests.py (Diff revision 5) Test docstrings shouldn't end in periods (since the test runner will add "...")
-
Diff: |
Revision 6 (+282 -8)
|
---|
Checks run (2 succeeded)
-
-
reviewboard/attachments/mimetypes.py (Diff revision 6) We should still wrap by putting everything in parens instead of using the continuation character.
-
reviewboard/reviews/ui/jsonui.py (Diff revision 6) This should probably be the same as the class docstring ("A review UI for JSON files")
-
-
reviewboard/reviews/ui/jsonui.py (Diff revision 6) The line break here is ugly. Please combine these.
-
-
-
-
-
-
reviewboard/reviews/ui/tests.py (Diff revision 6) This is an extra call to
get_rendered_lines
which is not needed. -
reviewboard/reviews/ui/tests.py (Diff revision 6) It might be nicer to hard-code the "correct" result rather than running it through the review UI. Right now if there's some change or bug that affects highlighting or reindenting, it will affect both the original and the "correct" file, making it possibly slip through the test.
-
reviewboard/reviews/ui/tests.py (Diff revision 6) We wrap long strings with the space characters and the end of previous lines instead of the start of the next.
-
reviewboard/reviews/ui/tests.py (Diff revision 6) Same here--let's hard-code the correct output instead of running it through the review UI.
Diff: |
Revision 7 (+278 -8)
|
---|