Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
sqozz | 6b10ee6093 | ||
sqozz | ef2046b610 |
|
@ -5,10 +5,11 @@ from urllib.parse import urlparse
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
# HEAD is implicit with flask
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
@app.route('/<shortLink>', methods=['GET', 'POST'])
|
@app.route('/<shortLink>', methods=['GET', 'POST'])
|
||||||
def short(shortLink=""):
|
def short(shortLink=""):
|
||||||
if request.method == "GET":
|
if request.method == "GET" or request.method == "HEAD":
|
||||||
if shortLink:
|
if shortLink:
|
||||||
noauto = shortLink[-1] == "+"
|
noauto = shortLink[-1] == "+"
|
||||||
if noauto: shortLink = shortLink[:-1]
|
if noauto: shortLink = shortLink[:-1]
|
||||||
|
|
|
@ -17,6 +17,11 @@ class WebTestCase(object):
|
||||||
self.assertEqual(req.status_code, 200, msg="Get request unsuccessful")
|
self.assertEqual(req.status_code, 200, msg="Get request unsuccessful")
|
||||||
return req
|
return req
|
||||||
|
|
||||||
|
def assertHeadReq(self, url):
|
||||||
|
req = requests.head(url)
|
||||||
|
self.assertEqual(req.status_code, 301, msg="Head request unsuccessful")
|
||||||
|
return req
|
||||||
|
|
||||||
def assertGetStatusReq(self, expected_status, url, params = {}):
|
def assertGetStatusReq(self, expected_status, url, params = {}):
|
||||||
req = requests.get(url, params=params, allow_redirects=False)
|
req = requests.get(url, params=params, allow_redirects=False)
|
||||||
self.assertEqual(req.status_code, expected_status, msg="Returned status code does not match the expected one")
|
self.assertEqual(req.status_code, expected_status, msg="Returned status code does not match the expected one")
|
||||||
|
@ -77,6 +82,11 @@ class SchortShortLinkCase(object):
|
||||||
req = self.assertGetReq(BASE_URL + "/" + self.shortID, params = {"resolve" : ""})
|
req = self.assertGetReq(BASE_URL + "/" + self.shortID, params = {"resolve" : ""})
|
||||||
self.assertEqual(req.text, self.shortDest)
|
self.assertEqual(req.text, self.shortDest)
|
||||||
|
|
||||||
|
def test_head_resolve(self):
|
||||||
|
"""Test resolving by using a HEAD request"""
|
||||||
|
req = self.assertHeadReq(BASE_URL + "/" + self.shortID)
|
||||||
|
self.assertEqual(req.headers.get("Location", ""), self.shortDest)
|
||||||
|
|
||||||
def test_HTMLresolve(self):
|
def test_HTMLresolve(self):
|
||||||
"""Test HTML displaying of the shortened URL"""
|
"""Test HTML displaying of the shortened URL"""
|
||||||
HTML_keyword = "+"
|
HTML_keyword = "+"
|
||||||
|
|
Loading…
Reference in a new issue