def testMeta1(self):
        """ Full meta data with both etag and last-modified """

        minfo = messagelog.MessageInfo._makeTestMinfo(
            [
                ("Last-Modified", "Sun, 24 Oct 2004 07:29:44 GMT"),
                ("ETag", '"9b2e763b9bb9c41:8b7"'),
                ("Content-Type", "text/plain"),
            ],
            789,
            req_path="http://host/path",
        )
        meta = qmsg_processor._extract_meta(minfo, "2004")

        self.assertEqual(meta["content-type"], "text/plain")

        meta["title"] = "val1"  # these usually filled by distillML
        meta["description"] = "val2"
        meta["keywords"] = "val3"

        buf = StringIO.StringIO()
        distillML.writeHeader(buf, meta)
        s = buf.getvalue()

        self.assert_(0 <= s.find("uri: http://host/path"))
        self.assert_(0 <= s.find("title: val1"))
        self.assert_(0 <= s.find("description: val2"))
        self.assert_(0 <= s.find("keywords: val3"))
        self.assert_(0 <= s.find('etag: "9b2e763b9bb9c41:8b7"'))
        self.assert_(0 > s.find("last-modified"))
    def testMeta1(self):
        """ Full meta data with both etag and last-modified """

        minfo = messagelog.MessageInfo._makeTestMinfo([
                ('Last-Modified', 'Sun, 24 Oct 2004 07:29:44 GMT'),
                ('ETag', '"9b2e763b9bb9c41:8b7"'),
                ('Content-Type', 'text/plain'),],
                789, req_path='http://host/path')
        meta = qmsg_processor._extract_meta(minfo, '2004')

        self.assertEqual(meta['content-type'], 'text/plain')

        meta['title']       = 'val1'    # these usually filled by distillML
        meta['description'] = 'val2'
        meta['keywords']    = 'val3'

        buf = StringIO.StringIO()
        distillML.writeHeader(buf, meta)
        s = buf.getvalue()

        self.assert_(0 <= s.find('uri: http://host/path'))
        self.assert_(0 <= s.find('title: val1'))
        self.assert_(0 <= s.find('description: val2'))
        self.assert_(0 <= s.find('keywords: val3'))
        self.assert_(0 <= s.find('etag: "9b2e763b9bb9c41:8b7"'))
        self.assert_(0 >  s.find('last-modified'))
    def testMaxuri(self):
        uri = "http://host" + "/1234567890" * 10
        minfo = messagelog.MessageInfo._makeTestMinfo([], 789, req_path=uri)
        meta = qmsg_processor._extract_meta(minfo, "2004")

        # uri truncated after 30 characters
        self.assertEqual(len(meta["uri"]), 30 + 3)
        self.assertEqual(meta["uri"], "http://host/1234567890/1234567...")
    def testMaxuri(self):
        uri = 'http://host' + '/1234567890'*10
        minfo = messagelog.MessageInfo._makeTestMinfo([], 789, req_path=uri)
        meta = qmsg_processor._extract_meta(minfo, '2004')

        # uri truncated after 30 characters
        self.assertEqual(len(meta['uri']), 30+3)
        self.assertEqual(meta['uri'], 'http://host/1234567890/1234567...')
    def testMeta2(self):
        """ with only Last-Modified """

        minfo = messagelog.MessageInfo._makeTestMinfo(
            [("Last-Modified", "Sun, 24 Oct 2004 07:29:44 GMT")], 789, req_path="http://host/path"
        )
        meta = qmsg_processor._extract_meta(minfo, "2004")

        buf = StringIO.StringIO()
        distillML.writeHeader(buf, meta)
        s = buf.getvalue()

        self.assert_(0 <= s.find("uri: http://host/path"))
        self.assert_(0 <= s.find("last-modified: Sun, 24 Oct 2004 07:29:44 GMT"))
        self.assert_(0 > s.find("etag"))
    def testMeta2(self):
        """ with only Last-Modified """

        minfo = messagelog.MessageInfo._makeTestMinfo([
            ('Last-Modified', 'Sun, 24 Oct 2004 07:29:44 GMT'),],
            789, req_path='http://host/path',)
        meta = qmsg_processor._extract_meta(minfo, '2004')

        buf = StringIO.StringIO()
        distillML.writeHeader(buf, meta)
        s = buf.getvalue()

        self.assert_(0 <= s.find('uri: http://host/path'))
        self.assert_(0 <= s.find('last-modified: Sun, 24 Oct 2004 07:29:44 GMT'))
        self.assert_(0 >  s.find('etag'))
    def testMeta0(self):
        """ with minimal meta data """

        minfo = messagelog.MessageInfo._makeTestMinfo([], 789, req_path="http://host/path")
        meta = qmsg_processor._extract_meta(minfo, "2004")

        buf = StringIO.StringIO()
        distillML.writeHeader(buf, meta)
        s = buf.getvalue()

        self.assert_(0 <= s.find("uri: http://host/path"))
        self.assert_(0 <= s.find("etag: W/789"))
        self.assert_(0 > s.find("title"))
        self.assert_(0 > s.find("description"))
        self.assert_(0 > s.find("keywords"))
        self.assert_(0 > s.find("last-modified"))
    def testMeta0(self):
        """ with minimal meta data """

        minfo = messagelog.MessageInfo._makeTestMinfo([],789,req_path='http://host/path')
        meta = qmsg_processor._extract_meta(minfo, '2004')

        buf = StringIO.StringIO()
        distillML.writeHeader(buf, meta)
        s = buf.getvalue()

        self.assert_(0 <= s.find('uri: http://host/path'))
        self.assert_(0 <= s.find('etag: W/789'          ))
        self.assert_(0 >  s.find('title'                ))
        self.assert_(0 >  s.find('description'          ))
        self.assert_(0 >  s.find('keywords'             ))
        self.assert_(0 >  s.find('last-modified'        ))