Exemple #1
0
    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'])
Exemple #2
0
    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'])
Exemple #3
0
    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'})
Exemple #4
0
    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'})
Exemple #5
0
 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())