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

Upgrades isort webtest and pylint quotes #6938

Merged
merged 7 commits into from
Jun 20, 2019
Merged

Conversation

NishealJ
Copy link
Contributor

@NishealJ NishealJ commented Jun 15, 2019

Explanation

This PR upgrades Upgrades isort webtest and pylint quotes.
To see the library status please visit here
Please visit here for the testing doc

Checklist

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes. (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • The PR explanation includes the words "Fixes #bugnum: ..." (or "Fixes part of #bugnum" if the PR only partially fixes an issue).
  • The linter/Karma presubmit checks have passed.
    • These should run automatically, but if not, you can manually trigger them locally using python scripts/pre_commit_linter.py and bash scripts/run_frontend_tests.sh.
  • The PR is made from a branch that's not called "develop".
  • The PR has an appropriate "CHANGELOG: ..." label (If you are unsure of which label to add, ask the reviewers for guidance).
  • The PR follows the style guide.
  • The PR addresses the points mentioned in the codeowner checks for the files/folders changed. (See the codeowner's wiki page.)
  • The PR is assigned to an appropriate reviewer.
    • If you're a new contributor, please ask on Gitter for someone to assign a reviewer and don't tick this checkbox.
    • If you're not sure who the appropriate reviewer is, please assign to the issue's "owner" -- see the "talk-to" label on the issue. Do not only request the review but also add the reviewer as an assignee.

System Administrator and others added 2 commits June 16, 2019 01:05
@codecov
Copy link

codecov bot commented Jun 16, 2019

Codecov Report

Merging #6938 into develop will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #6938   +/-   ##
========================================
  Coverage    95.73%   95.73%           
========================================
  Files          371      371           
  Lines        51604    51604           
========================================
  Hits         49404    49404           
  Misses        2200     2200
Impacted Files Coverage Δ
core/tests/gae_suite.py 74.41% <ø> (ø) ⬆️
core/controllers/base.py 100% <100%> (ø) ⬆️
core/controllers/base_test.py 98.33% <100%> (ø) ⬆️

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 7cdd42c...2185c32. Read the comment docs.

@codecov
Copy link

codecov bot commented Jun 16, 2019

Codecov Report

Merging #6938 into develop will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #6938   +/-   ##
========================================
  Coverage    95.73%   95.73%           
========================================
  Files          371      371           
  Lines        51604    51604           
========================================
  Hits         49404    49404           
  Misses        2200     2200
Impacted Files Coverage Δ
core/tests/gae_suite.py 74.41% <ø> (ø) ⬆️
core/controllers/base.py 100% <100%> (ø) ⬆️

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 7cdd42c...f2fe911. Read the comment docs.

@NishealJ
Copy link
Contributor Author

Hi @apb7,
I've tested this and here is the testing doc.
I'm removing the labels Thanks!

Copy link
Contributor

@apb7 apb7 left a comment

Choose a reason for hiding this comment

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

Hi @NishealJ, left some comments. PTAL!

@@ -339,8 +339,9 @@ def render_template(self, filepath, iframe_restriction='DENY'):
self.response.headers['X-Xss-Protection'] = '1; mode=block'

if iframe_restriction is not None:
if iframe_restriction in ['SAMEORIGIN', 'DENY']:
self.response.headers['X-Frame-Options'] = iframe_restriction
if iframe_restriction in [str('SAMEORIGIN'), str('DENY')]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @apb7,
The latest version of web test supports latin 1 string formats while sending a request.
If they are not typecasted into str they where moved to 500 error and the backend tests fails view here

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please point me to some documentation for webtest re this change?
Also, you can drop the str here since you're already converting iframe_restriction to a string below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @apb7,

if we dont str() them, they throw an error AssertionError: Header names must be latin1 string (not Py2 unicode or Py3 bytes type). i've read more about it here and here, seems like HTTP response headers should be a native strings - byte strings in Python 2 and unicode strings in Python 3, here is the issue raised in webtest repo for the same

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please point to the changelog of the version which mentions this change? There must be some documentation for this.
And I think you missed this:

Also, you can drop the str here since you're already converting iframe_restriction to a string below.

I suggest not to blindly put up str everywhere without first understanding the need.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @apb7 I've made it tedious and justifying please PTAL Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the changelog of wbetest they haven't mentioned in the changelog but the changes in the version below are notable for the cause

2.0.11 : Depend on unittest2 only for Python versions lower than 2.7 [iElectric]
2.0.28 : Fixed #119: Assertion error should be raised when you have non-string response header

Also similar notes can be found in requests changelog here

2.14.0 Breaking changes: Much improved handling of non-ASCII Location header values in redirects. Fewer UnicodeDecodeErrors are encountered on Python 2, and Python 3 now correctly understands that Latin-1 is unlikely to be the correct encoding.

Reading through the above docs and here as well looks like the application should return the native strings for headers and Python 2 build-in WSGI server don't help us in encoding/decoding and it must must be handled by the application itself in Python 2 whereas the case is different in Python 3.

@@ -831,8 +831,8 @@ def test_responses_with_valid_iframe_restriction(self):
self.get_html_response('/mock')

response = self.get_html_response(
'/mock', params={'iframe_restriction': 'DENY'})
self.assertEqual(response.headers['X-Frame-Options'], 'DENY')
'/mock', params={str('iframe_restriction'): str('DENY')})
Copy link
Contributor

Choose a reason for hiding this comment

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

Why these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @apb7, This is also for a similar reason I mentioned above

package-lock.json Outdated Show resolved Hide resolved
@@ -339,8 +339,9 @@ def render_template(self, filepath, iframe_restriction='DENY'):
self.response.headers['X-Xss-Protection'] = '1; mode=block'

if iframe_restriction is not None:
if iframe_restriction in ['SAMEORIGIN', 'DENY']:
self.response.headers['X-Frame-Options'] = iframe_restriction
if iframe_restriction in [str('SAMEORIGIN'), str('DENY')]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please point me to some documentation for webtest re this change?
Also, you can drop the str here since you're already converting iframe_restriction to a string below.

'/mock', params={'iframe_restriction': 'DENY'})
self.assertEqual(response.headers['X-Frame-Options'], 'DENY')
'/mock', params={str('iframe_restriction'): str('DENY')})
self.assertEqual(response.headers[str('X-Frame-Options')], str('DENY'))

response = self.get_html_response(
'/mock', params={'iframe_restriction': 'SAMEORIGIN'})
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do these lines work then (that is, without the conversion)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @apb7,

i also thought about it but seeing the tests failing here it clearly mentioned that 'u'DENY' is not a valid latin1 string' that's why I only str() it and tested again

Screenshot 2019-06-18 at 1 31 49 AM

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that this is valid reasoning. I agree that only a particular test fails but we should be clear what's happening behind the scenes and why the other test does not fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @apb7, I've updated the changes with reason PTAL Thanks!

@apb7
Copy link
Contributor

apb7 commented Jun 17, 2019

Hi @NishealJ, ptal! Thanks!

@NishealJ
Copy link
Contributor Author

Hi @NishealJ, ptal! Thanks!
Hi @abp7 I've addressed your comments Thanks!

Copy link
Contributor

@apb7 apb7 left a comment

Choose a reason for hiding this comment

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

Hi @NishealJ, ptal!

@@ -339,8 +339,9 @@ def render_template(self, filepath, iframe_restriction='DENY'):
self.response.headers['X-Xss-Protection'] = '1; mode=block'

if iframe_restriction is not None:
if iframe_restriction in ['SAMEORIGIN', 'DENY']:
self.response.headers['X-Frame-Options'] = iframe_restriction
if iframe_restriction in [str('SAMEORIGIN'), str('DENY')]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please point to the changelog of the version which mentions this change? There must be some documentation for this.
And I think you missed this:

Also, you can drop the str here since you're already converting iframe_restriction to a string below.

I suggest not to blindly put up str everywhere without first understanding the need.

'/mock', params={'iframe_restriction': 'DENY'})
self.assertEqual(response.headers['X-Frame-Options'], 'DENY')
'/mock', params={str('iframe_restriction'): str('DENY')})
self.assertEqual(response.headers[str('X-Frame-Options')], str('DENY'))

response = self.get_html_response(
'/mock', params={'iframe_restriction': 'SAMEORIGIN'})
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that this is valid reasoning. I agree that only a particular test fails but we should be clear what's happening behind the scenes and why the other test does not fail.

Copy link
Contributor

@apb7 apb7 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the explanation, @NishealJ! Please revert the changes in package-lock.json. Also, @nithusha21, @seanlip and @vojtechjelinek, ptal as code owners. Thanks!

@seanlip
Copy link
Member

seanlip commented Jun 19, 2019

I won't be reviewing until I see a testing doc with links to the changelogs for the various libraries and an explanation that analyzes any breaking changes and calls out what is being done about them.

(@NishealJ, I think I've asked for this before -- please take note of this for all library upgrades.)

@seanlip seanlip removed their assignment Jun 19, 2019
@NishealJ
Copy link
Contributor Author

NishealJ commented Jun 19, 2019

I won't be reviewing until I see a testing doc with links to the changelogs for the various libraries and an explanation that analyzes any breaking changes and calls out what is being done about them.

(@NishealJ, I think I've asked for this before -- please take note of this for all library upgrades.)

Hi @seanlip, sorry for the issue.
I've updated the testing docs PTAL Thanks!

Copy link
Contributor

@vojtechjelinek vojtechjelinek left a comment

Choose a reason for hiding this comment

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

LGTM from code owner's perspective. Thanks!

Copy link
Contributor

@vojtechjelinek vojtechjelinek left a comment

Choose a reason for hiding this comment

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

LGTM from code owner's perspective. Thanks!

Copy link
Contributor

@nithusha21 nithusha21 left a comment

Choose a reason for hiding this comment

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

LGTM as a codeowner.

@seanlip seanlip merged commit 995b667 into oppia:develop Jun 20, 2019
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