コード例 #1
0
def test_return_type_for_file():
    response = (
        u'HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n'
        'Content-Length: 96\r\n\r\n'
        'This is a very simple text file.\n'
        'Just to show that we can server it up.\n'
        'It is three lines long.\n')
    request = u'GET /sample.txt HTTP/1.1\r\n\r\n'
    response.encode('utf-8')
    assert http_server.build_response(request) == response
コード例 #2
0
def test_return_type_for_dir():
    response = (
        u'HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n'
        'Content-Length: 116\r\n\r\n'
        '<!DOCTYPE html><html><ul><li>a_web_page.html</li>'
        '<li>images</li><li>make_time.py</li><li>sample.txt</li>'
        '</ul></html>')
    request = u'GET / HTTP/1.1\r\n\r\n'
    response.encode('utf-8')
    assert http_server.build_response(request) == response
コード例 #3
0
    def test_build_response_unitxt(self):
        """Tests whether encoding is done properly and whether response is correct"""
        self.assertEqual('HTTP/1.1 200 OK\r\n\
Date: %s\r\n\
Server: Team Python\r\n\
Content-Type: text/plain; char=UTF-8\r\n\
Content-Length: 4\r\n\
\r\n\
ol\xc3\xa8' % formatdate(usegmt=True),
http_server.build_response(u'olè', 'text/plain'))
コード例 #4
0
    def test_build_response_txt(self):
        """Tests whether the response for a directory request is correct"""
        self.assertEqual('HTTP/1.1 200 OK\r\n\
Date: %s\r\n\
Server: Team Python\r\n\
Content-Type: text/plain; char=UTF-8\r\n\
Content-Length: 52\r\n\
\r\n\
JPEG_example.jpg\n\
sample_1.png\n\
Sample_Scene_Balls.jpg' % formatdate(usegmt=True),
http_server.build_response(
'JPEG_example.jpg\nsample_1.png\nSample_Scene_Balls.jpg',
'text/plain'))
コード例 #5
0
 def test_404(self):
     params = ('404 Not found', '', '404 Not found')
     expected = 'HTTP/1.1 404 Not found\r\n\r\n404 Not found'
     result = http_server.build_response(*params)
     self.assertEqual(expected, result)
コード例 #6
0
 def test_405(self):
     params = ('405 Method not allowed', '', '405 Method not allowed')
     expected = ('HTTP/1.1 405 Method not allowed' +
                 '\r\n\r\n405 Method not allowed')
     result = http_server.build_response(*params)
     self.assertEqual(expected, result)
コード例 #7
0
def call_build_response(step):
    world.response = build_response(world.code, "placeholder data")
コード例 #8
0
 def test_200_folder(self):
     m, c = http_server.get_content('/images/')
     params = ('200 OK', m, c)
     expected = 'HTTP/1.1 200 OK' + m + '\r\n\r\n' + c
     result = http_server.build_response(*params)
     self.assertEqual(expected, result)
コード例 #9
0
 def test_build(self):
     self.assertEqual(http_server.build_response(self.found_code, self.file_type, self.file_body), self.file_response)
     self.assertEqual(http_server.build_response(self.found_code, self.dir_type, self.dir_body), self.dir_response)
     self.assertEqual(http_server.build_response(self.not_found_code, self.error_type), self.four04_response)
     self.assertEqual(http_server.build_response(self.not_allowed_code, self.error_type), self.four05_response)
コード例 #10
0
 def test_build(self):
     self.assertEqual(http_server.build_response(self.found_code, self.file_type, self.file_body), self.file_response)
     self.assertEqual(http_server.build_response(self.found_code, self.dir_type, self.dir_body), self.dir_response)
     self.assertEqual(http_server.build_response(self.not_found_code, self.error_type), self.four04_response)
     self.assertEqual(http_server.build_response(self.not_allowed_code, self.error_type), self.four05_response)
コード例 #11
0
 def test_200_text(self):
     m, c = http_server.get_content('/sample.txt')
     params = ('200 OK', m, c)
     expected = 'HTTP/1.1 200 OK' + m + '\r\n\r\n' + c
     result = http_server.build_response(*params)
     self.assertEqual(expected, result)
コード例 #12
0
 def test_405(self):
     params = ('405 Method not allowed', '', '405 Method not allowed')
     expected = ('HTTP/1.1 405 Method not allowed' +
                 '\r\n\r\n405 Method not allowed')
     result = http_server.build_response(*params)
     self.assertEqual(expected, result)
コード例 #13
0
 def test_404(self):
     params = ('404 Not found', '', '404 Not found')
     expected = 'HTTP/1.1 404 Not found\r\n\r\n404 Not found'
     result = http_server.build_response(*params)
     self.assertEqual(expected, result)