-
-
Notifications
You must be signed in to change notification settings - Fork 20
Diffing server exception handling #185
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
Merged
Mr0grog
merged 8 commits into
edgi-govdata-archiving:master
from
ftsalamp:diffing_server-exception-handling
May 16, 2018
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6de1d38
Returning some exceptions in JSON format
ftsalamp b54ad85
Code cleanup, used send_error method
ftsalamp 65aa1c6
Handling more errors
ftsalamp 60dfc39
Diffing server unit tests, typo correction
ftsalamp 9e38fed
Allocating a new port for each test, all tests working
ftsalamp 3f92aee
Implementation of requested changes
ftsalamp 6441547
Implementation of requested changes 2
ftsalamp 50ef7db
Implementation of requested changes 3
ftsalamp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import json | ||
from tornado.testing import AsyncHTTPTestCase | ||
import web_monitoring.diffing_server as df | ||
from web_monitoring.diff_errors import UndecodableContentError | ||
|
||
|
||
class DiffingServerExceptionHandlingTest(AsyncHTTPTestCase): | ||
|
||
def get_app(self): | ||
return df.make_app() | ||
|
||
def test_invalid_url_a_format(self): | ||
response = self.fetch(f'/html_token?format=json&include=all&' | ||
f'a=example.org&b=https://example.org') | ||
self.json_check(response) | ||
self.assertEqual(response.code, 400) | ||
|
||
def test_invalid_url_b_format(self): | ||
response = self.fetch(f'/html_token?format=json&include=all&' | ||
f'a=https://example.org&b=example.org') | ||
self.json_check(response) | ||
self.assertEqual(response.code, 400) | ||
|
||
def test_invalid_diffing_method(self): | ||
response = self.fetch(f'/non_existing?format=json&include=all&' | ||
f'a=example.org&b=https://example.org') | ||
self.json_check(response) | ||
self.assertEqual(response.code, 404) | ||
|
||
def test_missing_url_a(self): | ||
response = self.fetch(f'/html_token?format=json&include=all&' | ||
f'b=https://example.org') | ||
self.json_check(response) | ||
self.assertEqual(response.code, 400) | ||
|
||
def test_missing_url_b(self): | ||
response = self.fetch(f'/html_token?format=json&include=all&' | ||
f'a=https://example.org') | ||
self.json_check(response) | ||
self.assertEqual(response.code, 400) | ||
|
||
def test_not_reachable_url_a(self): | ||
response = self.fetch(f'/html_token?format=json&include=all&' | ||
f'a=https://eeexample.org&b=https://example.org') | ||
self.json_check(response) | ||
self.assertEqual(response.code, 400) | ||
|
||
def test_not_reachable_url_b(self): | ||
response = self.fetch(f'/html_token?format=json&include=all&' | ||
f'a=https://example.org&b=https://eeexample.org') | ||
self.json_check(response) | ||
self.assertEqual(response.code, 400) | ||
|
||
def test_missing_params_caller_func(self): | ||
response = self.fetch('http://example.org/') | ||
with self.assertRaises(KeyError): | ||
df.caller(mock_diffing_method, response, response) | ||
|
||
def test_undecodable_content(self): | ||
response = self.fetch('https://www.cl.cam.ac.uk/~mgk25/' | ||
'ucs/examples/UTF-8-test.txt') | ||
with self.assertRaises(UndecodableContentError): | ||
df._decode_body(response, 'a', False) | ||
|
||
def test_fetch_undecodable_content(self): | ||
response = self.fetch(f'/html_token?format=json&include=all&' | ||
f'a=https://example.org&' | ||
f'b=https://www.cl.cam.ac.uk' | ||
f'/~mgk25/ucs/examples/UTF-8-test.txt') | ||
self.json_check(response) | ||
self.assertEqual(response.code, 422) | ||
|
||
def json_check(self, response): | ||
json_header = response.headers.get('Content-Type').split(';') | ||
self.assertEqual(json_header[0], 'application/json') | ||
|
||
json_response = json.loads(response.body) | ||
self.assertTrue(isinstance(json_response['code'], int)) | ||
self.assertTrue(isinstance(json_response['error'], str)) | ||
|
||
def test_a_is_404(self): | ||
response = self.fetch(f'/html_token?format=json&include=all' | ||
f'&a=http://httpstat.us/404' | ||
f'&b=https://example.org') | ||
self.assertEqual(response.code, 404) | ||
self.json_check(response) | ||
|
||
|
||
def mock_diffing_method(c_body): | ||
return |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I’m pretty sure this is a logic error. In
check_response_for_error()
, we have:If
response.rethrow()
raised atornado.httpclient.HTTPError
, it won’t ever get an error response because we didn’t handle it insidecheck_response_for_error()
, but we still stopped here inDiffHandler.get()
as if we did. It basically stops here, but never sends the error message. You can try this by adding a test:…which fails and prints out: