Exemplo n.º 1
0
 def test_passthrough_filter(self):
     # Test the passthrough filter returns an image stream
     gen = self.get_generator('openstack_logo.png')
     first = gen.next()
     self.assertNotIn('html', first)
     with open(base.samples_path('samples') + 'openstack_logo.png') as f:
         self.assertEqual(first, f.readline())
Exemplo n.º 2
0
 def fake_get_container(self, container, prefix=None, delimiter=None):
     index_items = []
     if _swift_index_items:
         for i in _swift_index_items:
             if i[-1] == '/':
                 index_items.append({'subdir': os.path.join(prefix, i)})
             else:
                 index_items.append({'name': os.path.join(prefix, i),
                                     'last_modified': '2042-12-31T23:59:59',
                                     'bytes': 4200})
     elif _swift_index_items == []:
         name = prefix[len('non-existent/'):]
         p = os.path.join(base.samples_path('samples'), name)
         for i in os.listdir(p):
             if os.path.isdir(os.path.join(p, i)):
                 index_items.append(
                     {'subdir': os.path.join(prefix, i + '/')})
             else:
                 index_items.append({'name': os.path.join(prefix, i),
                                     'last_modified': '2042-12-31T23:59:59',
                                     'bytes': 4200})
     else:
         # No swift container data.
         pass
     return {}, index_items
Exemplo n.º 3
0
        def _object_body():
            with open(base.samples_path('samples') + name) as f:

                buf = f.read(resp_chunk_size)
                while buf:
                    yield buf
                    buf = f.read(resp_chunk_size)
Exemplo n.º 4
0
    def test_folder_index(self):
        self.wsgi_config_file = (base.samples_path('samples') +
                                 'wsgi_folder_index.conf')
        gen = self.get_generator('')
        full = ''
        for line in gen:
            full += line

        full_lines = full.split('\n')
        self.assertEqual('<!DOCTYPE html>', full_lines[0])
        self.assertIn('samples/</title>', full_lines[3])
        # self.assertEqual("foo", full_lines)
        self.assertThat(
            full_lines[9],
            testtools.matchers.MatchesRegex(
                r'        <tr><td><a href="/samples/console.html.gz">'
                r'console.html.gz</a></td><td>' + ISO8601RE + r'</td>'
                r'<td style="text-align: right">277.4KB</td></tr>'),
            "\nFull log: %s" % full_lines)
        self.assertThat(
            full_lines[-5],
            testtools.matchers.MatchesRegex(
                r'        <tr><td><a href="/samples/wsgi_plain.conf">'
                r'wsgi_plain.conf</a></td><td>' + ISO8601RE + r'</td>'
                r'<td style="text-align: right">47.0B</td></tr>'),
            "\nFull log: %s" % full_lines)
        self.assertEqual('</html>', full_lines[-1],
                         "\nFull log: %s" % full_lines)
Exemplo n.º 5
0
    def test_folder_index(self):
        self.wsgi_config_file = (base.samples_path('samples') +
                                 'wsgi_folder_index.conf')
        gen = self.get_generator('')
        full = ''
        for line in gen:
            full += line

        full_lines = full.split('\n')
        self.assertEqual('<!DOCTYPE html>', full_lines[0])
        self.assertIn('samples/</title>', full_lines[3])
        # self.assertEqual("foo", full_lines)
        self.assertThat(
            full_lines[9],
            testtools.matchers.MatchesRegex(
                r'        <tr><td><a href="/samples/console.html.gz">'
                r'console.html.gz</a></td><td>' + ISO8601RE + r'</td>'
                r'<td style="text-align: right">277.4KB</td></tr>'),
            "\nFull log: %s" % full_lines)
        self.assertThat(
            full_lines[-5],
            testtools.matchers.MatchesRegex(
                r'        <tr><td><a href="/samples/wsgi_plain.conf">'
                r'wsgi_plain.conf</a></td><td>' + ISO8601RE + r'</td>'
                r'<td style="text-align: right">47.0B</td></tr>'),
            "\nFull log: %s" % full_lines)
        self.assertEqual('</html>', full_lines[-1],
                         "\nFull log: %s" % full_lines)
Exemplo n.º 6
0
 def test_passthrough_filter(self):
     # Test the passthrough filter returns an image stream
     gen = self.get_generator('openstack_logo.png')
     first = gen.next()
     self.assertNotIn('html', first)
     with open(base.samples_path('samples') + 'openstack_logo.png') as f:
         self.assertEqual(first, f.readline())
Exemplo n.º 7
0
    def test_config_passthrough_view(self):
        self.wsgi_config_file = (base.samples_path('samples') +
                                 'wsgi_plain.conf')
        # Check there is no HTML on a file that should otherwise have it
        gen = self.get_generator('devstacklog.txt.gz')

        first = gen.next()
        self.assertNotIn('<html>', first)
Exemplo n.º 8
0
    def test_config_passthrough_view(self):
        self.wsgi_config_file = (base.samples_path('samples') +
                                 'wsgi_plain.conf')
        # Check there is no HTML on a file that should otherwise have it
        gen = self.get_generator('devstacklog.txt.gz')

        first = gen.next()
        self.assertNotIn('<html>', first)
Exemplo n.º 9
0
 def get_generator(self, fname):
     # Override base's get_generator because we don't want the full
     # wsgi application. We just need the generator to give to Views.
     root_path = base.samples_path(self.samples_directory)
     kwargs = {'PATH_INFO': '/htmlify/%s' % fname}
     file_generator = osgen.get_file_generator(self.fake_env(**kwargs),
                                               root_path)
     filter_generator = osfilter.SevFilter(file_generator)
     return filter_generator
Exemplo n.º 10
0
 def get_generator(self, fname):
     # Override base's get_generator because we don't want the full
     # wsgi application. We just need the generator to give to Views.
     root_path = base.samples_path(self.samples_directory)
     kwargs = {'PATH_INFO': '/htmlify/%s' % fname}
     file_generator = osgen.get_file_generator(self.fake_env(**kwargs),
                                               root_path)
     filter_generator = osfilter.SevFilter(file_generator)
     return filter_generator
Exemplo n.º 11
0
def fake_get_object(self, container, name, resp_chunk_size=None):
    name = name[len('non-existent/'):]
    if not os.path.isfile(base.samples_path('samples') + name):
        return {}, None
    if resp_chunk_size:

        def _object_body():
            with open(base.samples_path('samples') + name) as f:

                buf = f.read(resp_chunk_size)
                while buf:
                    yield buf
                    buf = f.read(resp_chunk_size)

        object_body = _object_body()
    else:
        with open(base.samples_path('samples') + name) as f:
            object_body = f.read()
    resp_headers = os_loganalyze.util.get_headers_for_file(
        base.samples_path('samples') + name)
    return resp_headers, object_body
Exemplo n.º 12
0
    def test_file_conditions(self):
        self.wsgi_config_file = (base.samples_path('samples') +
                                 'wsgi_file_conditions.conf')
        # Check we are matching and setting the HTML filter
        gen = self.get_generator('devstacklog.txt.gz')

        first = gen.next()
        self.assertIn('<html>', first)

        # Check for simple.html we don't have HTML but do have date lines
        gen = self.get_generator('simple.txt')

        first = gen.next()
        self.assertIn('2013-09-27 18:22:35.392 testing 123', first)

        # Test images go through the passthrough filter
        gen = self.get_generator('openstack_logo.png')
        first = gen.next()
        self.assertNotIn('html', first)
        with open(base.samples_path('samples') + 'openstack_logo.png') as f:
            self.assertEqual(first, f.readline())
Exemplo n.º 13
0
    def test_file_conditions(self):
        self.wsgi_config_file = (base.samples_path('samples') +
                                 'wsgi_file_conditions.conf')
        # Check we are matching and setting the HTML filter
        gen = self.get_generator('devstacklog.txt.gz')

        first = gen.next()
        self.assertIn('<html>', first)

        # Check for simple.html we don't have HTML but do have date lines
        gen = self.get_generator('simple.txt')

        first = gen.next()
        self.assertIn('2013-09-27 18:22:35.392 testing 123', first)

        # Test images go through the passthrough filter
        gen = self.get_generator('openstack_logo.png')
        first = gen.next()
        self.assertNotIn('html', first)
        with open(base.samples_path('samples') + 'openstack_logo.png') as f:
            self.assertEqual(first, f.readline())
Exemplo n.º 14
0
    def test_folder_index_dual(self):
        # Test an index is correctly generated where files may exist on disk as
        # well as in swift.
        self.samples_directory = 'samples'
        self.wsgi_config_file = (base.samples_path('samples') +
                                 'wsgi_folder_index.conf')

        gen = self.get_generator('')
        full = ''
        for line in gen:
            full += line

        full_lines = full.split('\n')
        self.assertEqual('<!DOCTYPE html>', full_lines[0])
        self.assertIn('samples/</title>', full_lines[3])
        self.assertThat(
            full_lines[9],
            testtools.matchers.MatchesRegex(
                r'        <tr><td><a href="/samples/a">a</a></td>'
                r'<td>' + ISO8601RE + r'</td>'
                r'<td style="text-align: right">4.1KB</td></tr>'))
        self.assertThat(
            full_lines[11],
            testtools.matchers.MatchesRegex(
                r'        <tr><td><a href="/samples/b">b</a></td>'
                r'<td>' + ISO8601RE + r'</td>'
                r'<td style="text-align: right">4.1KB</td></tr>'))
        self.assertThat(
            full_lines[13],
            testtools.matchers.MatchesRegex(
                r'        <tr><td><a href="/samples/console.html.gz">'
                r'console.html.gz</a></td><td>' + ISO8601RE + r'</td>'
                r'<td style="text-align: right">277.4KB</td></tr>'))
        self.assertEqual(
            full_lines[17],
            '        <tr><td><a href="/samples/dir/">dir/</a></td>'
            '<td>unknown</td><td style="text-align: right">0.0B</td></tr>')
        self.assertThat(
            full_lines[-7],
            testtools.matchers.MatchesRegex(
                r'        <tr><td><a href="/samples/wsgi_plain.conf">'
                r'wsgi_plain.conf</a></td><td>' + ISO8601RE + r'</td>'
                r'<td style="text-align: right">177.0B</td></tr>'))
        self.assertThat(
            full_lines[-5],
            testtools.matchers.MatchesRegex(
                r'        <tr><td><a href="/samples/z">z</a></td>'
                r'<td>' + ISO8601RE + r'</td>'
                r'<td style="text-align: right">4.1KB</td></tr>'))
        self.assertEqual('</html>', full_lines[-1])
Exemplo n.º 15
0
    def test_config_no_filter(self):
        self.wsgi_config_file = (base.samples_path('samples') +
                                 'wsgi_plain.conf')
        # Try to limit the filter to 10 lines, but we should get the full
        # amount.
        gen = self.get_generator('devstacklog.txt.gz', limit=10)

        lines = 0
        for line in gen:
            lines += 1

        # the lines should actually be 2 + the limit we've asked for
        # given the header and footer, but we expect to get the full file
        self.assertNotEqual(12, lines)
Exemplo n.º 16
0
    def test_config_no_filter(self):
        self.wsgi_config_file = (base.samples_path('samples') +
                                 'wsgi_plain.conf')
        # Try to limit the filter to 10 lines, but we should get the full
        # amount.
        gen = self.get_generator('devstacklog.txt.gz', limit=10)

        lines = 0
        for line in gen:
            lines += 1

        # the lines should actually be 2 + the limit we've asked for
        # given the header and footer, but we expect to get the full file
        self.assertNotEqual(12, lines)
Exemplo n.º 17
0
 def test_compare_disk_to_swift_no_chunks(self):
     self.wsgi_config_file = (base.samples_path('samples') +
                              'wsgi_no_chunks.conf')
     self.test_compare_disk_to_swift_no_compression()
     self.test_compare_disk_to_swift_plain()
     self.test_compare_disk_to_swift_html()