SP/web2py/gluon/tests/test_http.py
Saturneic 064f602b1a Add.
2018-10-25 23:33:13 +08:00

38 lines
1.0 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Unit tests for http.py """
import unittest
from gluon.http import HTTP, defined_status
class TestHTTP(unittest.TestCase):
""" Tests http.HTTP """
def test_status_message(self):
""" Tests http status code message """
h = HTTP
def gen_status_str(code, message):
return str(code) + ' ' + str(message)
message = '1423 This is a custom message'
code = 1423
self.assertEqual(str(h(gen_status_str(code, message))),
gen_status_str(code, message))
# test predefined codes
for code in defined_status.keys():
self.assertEqual(
str(h(code)),
gen_status_str(code, defined_status[code]))
# test correct use of status_message
for code in defined_status.keys():
self.assertEqual(str(h(gen_status_str(code, message))),
gen_status_str(code, message))
# test wrong call detection