| Index: tools/telemetry/telemetry/page/page_set_archive_info_unittest.py
|
| diff --git a/tools/telemetry/telemetry/page/page_set_archive_info_unittest.py b/tools/telemetry/telemetry/page/page_set_archive_info_unittest.py
|
| index f499bdf9bdb3f52a58d773d97226f99468b8972c..e72f76bcc7e1b0c47816b85bb0bd78a66a1254ee 100644
|
| --- a/tools/telemetry/telemetry/page/page_set_archive_info_unittest.py
|
| +++ b/tools/telemetry/telemetry/page/page_set_archive_info_unittest.py
|
| @@ -6,12 +6,15 @@ import shutil
|
| import tempfile
|
| import unittest
|
|
|
| +from telemetry.page import cloud_storage
|
| from telemetry.page import page_set_archive_info
|
|
|
| +
|
| class MockPage(object):
|
| def __init__(self, url):
|
| self.url = url
|
|
|
| +
|
| url1 = 'http://www.foo.com/'
|
| url2 = 'http://www.bar.com/'
|
| url3 = 'http://www.baz.com/'
|
| @@ -29,6 +32,7 @@ page1 = MockPage(url1)
|
| page2 = MockPage(url2)
|
| page3 = MockPage(url3)
|
|
|
| +
|
| class TestPageSetArchiveInfo(unittest.TestCase):
|
| def setUp(self):
|
| self.tmp_dir = tempfile.mkdtemp()
|
| @@ -50,6 +54,11 @@ class TestPageSetArchiveInfo(unittest.TestCase):
|
| def tearDown(self):
|
| shutil.rmtree(self.tmp_dir)
|
|
|
| + def assertCorrectHashFile(self, file_path):
|
| + self.assertTrue(os.path.exists(file_path + '.sha1'))
|
| + with open(file_path + '.sha1', 'rb') as f:
|
| + self.assertEquals(cloud_storage.GetHash(file_path), f.read())
|
| +
|
| def testReadingArchiveInfo(self):
|
| self.assertEquals(recording1, os.path.basename(
|
| self.archive_info.WprFilePathForPage(page1)))
|
| @@ -59,7 +68,10 @@ class TestPageSetArchiveInfo(unittest.TestCase):
|
| self.archive_info.WprFilePathForPage(page3)))
|
|
|
| def testModifications(self):
|
| - new_recording1 = 'data_003.wpr'
|
| + recording1_path = os.path.join(self.tmp_dir, recording1)
|
| + recording2_path = os.path.join(self.tmp_dir, recording2)
|
| +
|
| + new_recording1 = os.path.join(self.tmp_dir, 'data_003.wpr')
|
| new_temp_recording = os.path.join(self.tmp_dir, 'recording.wpr')
|
| with open(new_temp_recording, 'w') as f:
|
| f.write('wpr data')
|
| @@ -75,27 +87,27 @@ class TestPageSetArchiveInfo(unittest.TestCase):
|
|
|
| self.archive_info.AddRecordedPages([page2.url])
|
|
|
| - self.assertTrue(os.path.exists(os.path.join(self.tmp_dir, new_recording1)))
|
| - self.assertFalse(os.path.exists(
|
| - os.path.join(self.tmp_dir, new_temp_recording)))
|
| + self.assertTrue(os.path.exists(new_recording1))
|
| + self.assertFalse(os.path.exists(new_temp_recording))
|
|
|
| - self.assertTrue(os.path.exists(os.path.join(self.tmp_dir, recording1)))
|
| - self.assertTrue(os.path.exists(os.path.join(self.tmp_dir, recording2)))
|
| + self.assertTrue(os.path.exists(recording1_path))
|
| + self.assertTrue(os.path.exists(recording2_path))
|
| + self.assertCorrectHashFile(new_recording1)
|
|
|
| - new_recording2 = 'data_004.wpr'
|
| + new_recording2 = os.path.join(self.tmp_dir, 'data_004.wpr')
|
| with open(new_temp_recording, 'w') as f:
|
| f.write('wpr data')
|
|
|
| self.archive_info.AddNewTemporaryRecording(new_temp_recording)
|
| self.archive_info.AddRecordedPages([page3.url])
|
|
|
| - self.assertTrue(os.path.exists(os.path.join(self.tmp_dir, new_recording2)))
|
| - self.assertFalse(os.path.exists(
|
| - os.path.join(self.tmp_dir, new_temp_recording)))
|
| + self.assertTrue(os.path.exists(new_recording2))
|
| + self.assertCorrectHashFile(new_recording2)
|
| + self.assertFalse(os.path.exists(new_temp_recording))
|
|
|
| - self.assertTrue(os.path.exists(os.path.join(self.tmp_dir, recording1)))
|
| + self.assertTrue(os.path.exists(recording1_path))
|
| # recording2 is no longer needed, so it was deleted.
|
| - self.assertFalse(os.path.exists(os.path.join(self.tmp_dir, recording2)))
|
| + self.assertFalse(os.path.exists(recording2_path))
|
|
|
| def testCreatingNewArchiveInfo(self):
|
| # Write only the page set without the corresponding metadata file.
|
| @@ -135,9 +147,9 @@ class TestPageSetArchiveInfo(unittest.TestCase):
|
| # Expected name for the recording (decided by PageSetArchiveInfo).
|
| new_recording = os.path.join(self.tmp_dir, 'new_000.wpr')
|
|
|
| - self.assertTrue(os.path.exists(os.path.join(self.tmp_dir, new_recording)))
|
| - self.assertFalse(os.path.exists(
|
| - os.path.join(self.tmp_dir, new_temp_recording)))
|
| + self.assertTrue(os.path.exists(new_recording))
|
| + self.assertFalse(os.path.exists(new_temp_recording))
|
| + self.assertCorrectHashFile(new_recording)
|
|
|
| # Check that the archive info was written correctly.
|
| self.assertTrue(os.path.exists(self.page_set_archive_info_file))
|
| @@ -146,3 +158,4 @@ class TestPageSetArchiveInfo(unittest.TestCase):
|
| os.path.join(tempfile.gettempdir(), 'pageset.json'))
|
| self.assertEquals(new_recording,
|
| read_archive_info.WprFilePathForPage(page1))
|
| + self.assertCorrectHashFile(self.page_set_archive_info_file)
|
|
|