Skip to content

Commit 48ba901

Browse files
committed
Support urls without url scheme #31
1 parent ed9fcf6 commit 48ba901

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

buildnotifylib/core/http_connection.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import socket
44
import ssl
55
import urllib2
6+
from urlparse import urlparse
67

78

89
class HttpConnection(object):
@@ -17,6 +18,8 @@ def connect(self, server, timeout):
1718
unquoted_password = urllib2.unquote(server.password)
1819
encodedstring = base64.encodestring("%s:%s" % (unquoted_username, unquoted_password))[:-1]
1920
headers["Authorization"] = "Basic %s" % encodedstring
21+
parsed = urlparse(server.url)
22+
url = parsed.geturl() if parsed.scheme else 'http://' + server.url
2023
if server.skip_ssl_verification:
21-
return urllib2.urlopen(urllib2.Request(server.url, None, headers), context=ssl._create_unverified_context())
22-
return urllib2.urlopen(urllib2.Request(server.url, None, headers))
24+
return urllib2.urlopen(urllib2.Request(url, None, headers), context=ssl._create_unverified_context())
25+
return urllib2.urlopen(urllib2.Request(url, None, headers))

test/http_connection_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77

88
def test_should_fetch_data():
99
file_path = os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "../../data/cctray.xml")
10-
response = HttpConnection().connect(ServerConfig('file://' + file_path, [], '', '', None, None), 10)
10+
response = HttpConnection().connect(ServerConfig('file://' + file_path, [], '', '', None, None), 3)
1111
assert str(response.read()) == open(file_path, 'r').read()
1212

1313

1414
def test_should_pass_auth_if_provided(mocker):
1515
m = mocker.patch.object(urllib2, 'urlopen', return_value='content')
16-
response = HttpConnection().connect(ServerConfig('url', [], '', '', "user", "pass"), 10)
16+
response = HttpConnection().connect(ServerConfig('url.com/cc.xml', [], '', '', "user", "pass"), 3)
1717
assert str(response) == 'content'
1818

1919
def url_with_auth(a):
20-
return a.get_full_url() == 'url' and a.get_header('Authorization') is not None
20+
return a.get_full_url() == 'http://url.com/cc.xml' and a.get_header('Authorization') is not None
2121

2222
m.assert_called_once_with(Matcher(url_with_auth))
2323

0 commit comments

Comments
 (0)