7
7
from StringIO import StringIO
11
12
from zope.component import getUtility
14
from canonical.config import config
13
15
from canonical.launchpad.scripts.logger import BufferLogger
14
16
from canonical.launchpad.webapp.interfaces import (
15
17
IStoreSelector, MAIN_STORE, DEFAULT_FLAVOR)
215
217
self.assertEqual(self.logger.buffer.getvalue(), '')
217
219
date = datetime(2008, 6, 13)
218
self.assertEqual(downloads,
220
self.assertEqual(downloads,
219
221
{'/15018215/ul_logo_64x64.png':
220
222
{datetime(2008, 6, 13): {'US': 1}}})
222
224
self.assertEqual(parsed_bytes, fd.tell())
226
def test_max_parsed_lines(self):
227
# The max_parsed_lines config option limits the number of parsed
233
logparser_max_parsed_lines: 2
235
fd = open(os.path.join(
236
here, 'apache-log-files', 'launchpadlibrarian.net.access-log'))
237
downloads, parsed_bytes = parse_file(
238
fd, start_position=0, logger=self.logger,
239
get_download_key=get_path_download_key)
240
config.pop("log_parser config")
242
self.assertEqual(self.logger.buffer.getvalue(), '')
243
date = datetime(2008, 6, 13)
244
self.assertContentEqual(
246
[('/12060796/me-tv-icon-64x64.png', {date: {'AU': 1}}),
247
('/9096290/me-tv-icon-14x14.png', {date: {'AU': 1}})])
249
# We should have parsed only the first two lines of data.
251
lines = fd.readlines()
252
self.assertEqual(parsed_bytes, len(lines[0]) + len(lines[1]))
225
255
class TestParsedFilesDetection(TestCase):
226
256
"""Test the detection of already parsed logs."""
264
294
def test_different_files_with_same_name(self):
265
295
# Thanks to log rotation, two runs of our script may see files with
266
# the same name but completely different content. If we see a file
296
# the same name but completely different content. If we see a file
267
297
# with a name matching that of an already parsed file but with content
268
298
# differing from the last file with that name parsed, we know we need
269
299
# to parse the file from the start.