示例#1
0
文件: test.py 项目: jackuess/SinPy
    def test_not_found(self, isdir):
        s = Static('path')
        with patch('sinpy.open', create=True) as m:
            m.side_effect = IOError(ENOENT, None, None)
            r = list(s.get())

        self.assertEqual(s.response.status_code, 404)
        self.assertEqual(r, ['Not found'])
示例#2
0
文件: test.py 项目: jackuess/SinPy
    def test_static_file(self, isdir):
        s = Static('path')
        with patch('sinpy.open', mock_open(read_data='FILE CONTENTS'),
                   create=True) as m:
            r = list(s.get())

        self.assertEqual(s.response.status_code, 200)
        self.assertEqual(r, ['FILE CONTENTS'])
示例#3
0
文件: test.py 项目: jackuess/SinPy
    def test_dir(self, lsitdir, isdir):
        s = Static('dir')
        s.request = Mock()
        s.request.path = 'dir'
        r = list(s.get())

        self.assertEqual(''.join(r),
                         '<h1>Directory listing</h1>'
                         '<ul><li><a href="dir/path1">path1</a></li>'
                         '<li><a href="dir/path2">path2</a></li>'
                         '<li><a href="dir/path3">path3</a></li></ul>')
        self.assertEqual(s.response.headers, {'Content-type': 'text/html'})
示例#4
0
文件: test.py 项目: jackuess/SinPy
    def test_content_type(self, isdir):
        s = Static('path.css')
        with patch('sinpy.open', mock_open(), create=True) as m:
            r = list(s.get())

        self.assertEqual(s.response.headers, {'Content-type': 'text/css'})
示例#5
0
文件: test.py 项目: jackuess/SinPy
 def test_not_ioerror(self, isdir):
     s = Static('path')
     with self.assertRaises(IOError):
         with patch('sinpy.open', create=True) as m:
             m.side_effect = IOError(-5, None, None)
             list(s.get())