-
-
Notifications
You must be signed in to change notification settings - Fork 379
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
Add generic HTTP and HTTPS streaming support. #107
Changes from 19 commits
96b886a
a51bedd
d1c9fea
d847291
ad4cac4
df38217
87d782c
6043a01
8a42950
f8dfc73
ef17bcb
0097ac2
d55efd9
6702bf7
18fed99
87d1bc6
86a1306
c5c30ef
9db299d
70b17ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,12 +34,12 @@ class ParseUriTest(unittest.TestCase): | |
def test_scheme(self): | ||
"""Do URIs schemes parse correctly?""" | ||
# supported schemes | ||
for scheme in ("s3", "s3n", "hdfs", "file"): | ||
for scheme in ("s3", "s3n", "hdfs", "file", "http", "https"): | ||
parsed_uri = smart_open.ParseUri(scheme + "://mybucket/mykey") | ||
self.assertEqual(parsed_uri.scheme, scheme) | ||
|
||
# unsupported scheme => NotImplementedError | ||
self.assertRaises(NotImplementedError, smart_open.ParseUri, "http://mybucket/mykey") | ||
self.assertRaises(NotImplementedError, smart_open.ParseUri, "foobar://mybucket/mykey") | ||
|
||
# unknown scheme => default_scheme | ||
parsed_uri = smart_open.ParseUri("blah blah") | ||
|
@@ -168,6 +168,31 @@ def test_webhdfs_read(self): | |
smart_open_object = smart_open.WebHdfsOpenRead(smart_open.ParseUri("webhdfs://127.0.0.1:8440/path/file")) | ||
self.assertEqual(smart_open_object.read().decode("utf-8"), "line1\nline2") | ||
|
||
@responses.activate | ||
def test_http_read(self): | ||
"""Does webhdfs read method work correctly""" | ||
responses.add(responses.GET, "http://127.0.0.1/index.html", body='line1\nline2') | ||
smart_open_object = smart_open.HttpOpenRead(smart_open.ParseUri("http://127.0.0.1/index.html")) | ||
self.assertEqual(smart_open_object.read().decode("utf-8"), "line1\nline2") | ||
|
||
@responses.activate | ||
def test_https_readline(self): | ||
"""Does webhdfs read method work correctly""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo in docstring as well |
||
responses.add(responses.GET, "https://127.0.0.1/index.html", body='line1\nline2') | ||
smart_open_object = smart_open.HttpOpenRead(smart_open.ParseUri("https://127.0.0.1/index.html")) | ||
self.assertEqual(smart_open_object.readline().decode("utf-8"), "line1") | ||
|
||
@responses.activate | ||
def test_http_pass(self): | ||
"""Does http authentication work correctly""" | ||
responses.add(responses.GET, "http://127.0.0.1/index.html", body='line1\nline2') | ||
smart_open_object = smart_open.HttpOpenRead(smart_open.ParseUri("http://127.0.0.1/index.html"), | ||
user='me', password='pass') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: we use hanging (not vertical) indent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, fixed |
||
self.assertEquals(len(responses.calls), 1) | ||
actual_request = responses.calls[0].request | ||
self.assert_('Authorization' in actual_request.headers) | ||
self.assert_(actual_request.headers['Authorization'].startswith('Basic ')) | ||
|
||
@mock.patch('smart_open.smart_open_lib.boto') | ||
@mock.patch('smart_open.smart_open_lib.S3OpenRead') | ||
def test_s3_boto(self, mock_s3_open_read, mock_boto): | ||
|
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.
Just a typo in the docstring ""Does http read method work correctly"""