Chris Sosa | 47a7d4e | 2012-03-28 18:26:55 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
Gilad Arnold | c65330c | 2012-09-20 22:17:48 | [diff] [blame] | 7 | """Unit tests for downloader module.""" |
Chris Sosa | 47a7d4e | 2012-03-28 18:26:55 | [diff] [blame] | 8 | |
Chris Sosa | 76e44b9 | 2013-01-31 20:11:38 | [diff] [blame] | 9 | import mox |
Chris Sosa | 47a7d4e | 2012-03-28 18:26:55 | [diff] [blame] | 10 | import os |
| 11 | import shutil |
| 12 | import tempfile |
| 13 | import unittest |
| 14 | |
Gilad Arnold | c65330c | 2012-09-20 22:17:48 | [diff] [blame] | 15 | import build_artifact |
Chris Sosa | 47a7d4e | 2012-03-28 18:26:55 | [diff] [blame] | 16 | import downloader |
| 17 | |
| 18 | |
Chris Sosa | 76e44b9 | 2013-01-31 20:11:38 | [diff] [blame] | 19 | # pylint: disable=W0212,E1120 |
Chris Masone | 816e38c | 2012-05-02 19:22:36 | [diff] [blame] | 20 | class DownloaderTestBase(mox.MoxTestBase): |
Chris Sosa | 47a7d4e | 2012-03-28 18:26:55 | [diff] [blame] | 21 | |
| 22 | def setUp(self): |
| 23 | mox.MoxTestBase.setUp(self) |
| 24 | self._work_dir = tempfile.mkdtemp('downloader-test') |
Chris Sosa | 76e44b9 | 2013-01-31 20:11:38 | [diff] [blame] | 25 | self.board = 'x86-mario-release' |
Chris Sosa | 47a7d4e | 2012-03-28 18:26:55 | [diff] [blame] | 26 | self.build = 'R17-1413.0.0-a1-b1346' |
Chris Sosa | 76e44b9 | 2013-01-31 20:11:38 | [diff] [blame] | 27 | self.archive_url = ( |
| 28 | 'gs://chromeos-image-archive/%s/%s' % (self.board, self.build)) |
Chris Sosa | 47a7d4e | 2012-03-28 18:26:55 | [diff] [blame] | 29 | |
| 30 | def tearDown(self): |
Gilad Arnold | 0b8c3f3 | 2012-09-19 21:35:44 | [diff] [blame] | 31 | shutil.rmtree(self._work_dir, ignore_errors=True) |
Chris Sosa | 47a7d4e | 2012-03-28 18:26:55 | [diff] [blame] | 32 | |
Chris Sosa | 76e44b9 | 2013-01-31 20:11:38 | [diff] [blame] | 33 | def testSimpleDownloadOfTestSuites(self): |
| 34 | """Basic test_suites test. |
Chris Sosa | 47a7d4e | 2012-03-28 18:26:55 | [diff] [blame] | 35 | |
Chris Sosa | 76e44b9 | 2013-01-31 20:11:38 | [diff] [blame] | 36 | Verifies that if we request the test_suites, it gets downloaded and |
| 37 | the autotest tarball is attempted in the background. |
Chris Sosa | 47a7d4e | 2012-03-28 18:26:55 | [diff] [blame] | 38 | """ |
Chris Sosa | 76e44b9 | 2013-01-31 20:11:38 | [diff] [blame] | 39 | downloader_instance = downloader.Downloader(self._work_dir, |
| 40 | self.archive_url) |
| 41 | self.mox.StubOutWithMock(downloader.Downloader, |
| 42 | '_DownloadArtifactsSerially') |
| 43 | self.mox.StubOutWithMock(downloader.Downloader, |
| 44 | '_DownloadArtifactsInBackground') |
Chris Sosa | 47a7d4e | 2012-03-28 18:26:55 | [diff] [blame] | 45 | |
Chris Sosa | 76e44b9 | 2013-01-31 20:11:38 | [diff] [blame] | 46 | downloader.Downloader._DownloadArtifactsInBackground(mox.In(mox.IsA( |
| 47 | build_artifact.AutotestTarballBuildArtifact))) |
| 48 | downloader.Downloader._DownloadArtifactsSerially( |
| 49 | [mox.IsA(build_artifact.TarballBuildArtifact)], no_wait=True) |
Chris Sosa | 47a7d4e | 2012-03-28 18:26:55 | [diff] [blame] | 50 | self.mox.ReplayAll() |
Chris Sosa | 6b0c617 | 2013-08-06 00:01:33 | [diff] [blame] | 51 | downloader_instance.Download(artifacts=['test_suites'], |
| 52 | files=None) |
Chris Sosa | 76e44b9 | 2013-01-31 20:11:38 | [diff] [blame] | 53 | # Sanity check the timestamp file exists. |
Alex Miller | a44d502 | 2012-07-27 18:34:16 | [diff] [blame] | 54 | self.assertTrue(os.path.exists( |
Chris Sosa | 76e44b9 | 2013-01-31 20:11:38 | [diff] [blame] | 55 | os.path.join(self._work_dir, self.board, self.build, |
| 56 | downloader.Downloader._TIMESTAMP_FILENAME))) |
| 57 | self.mox.VerifyAll() |
Chris Sosa | 9164ca3 | 2012-03-28 18:04:50 | [diff] [blame] | 58 | |
Chris Sosa | 76e44b9 | 2013-01-31 20:11:38 | [diff] [blame] | 59 | def testDownloadSymbols(self): |
| 60 | """Basic symbols download.""" |
| 61 | downloader_instance = downloader.Downloader(self._work_dir, |
| 62 | self.archive_url) |
| 63 | self.mox.StubOutWithMock(downloader.Downloader, |
| 64 | '_DownloadArtifactsSerially') |
| 65 | # Should not get called but mocking so that we know it wasn't called. |
| 66 | self.mox.StubOutWithMock(downloader.Downloader, |
| 67 | '_DownloadArtifactsInBackground') |
| 68 | downloader.Downloader._DownloadArtifactsSerially( |
| 69 | [mox.IsA(build_artifact.TarballBuildArtifact)], no_wait=True) |
Chris Masone | 816e38c | 2012-05-02 19:22:36 | [diff] [blame] | 70 | self.mox.ReplayAll() |
Chris Sosa | 6b0c617 | 2013-08-06 00:01:33 | [diff] [blame] | 71 | downloader_instance.Download(artifacts=['symbols'], |
| 72 | files=None) |
Chris Masone | 816e38c | 2012-05-02 19:22:36 | [diff] [blame] | 73 | self.mox.VerifyAll() |
| 74 | |
| 75 | |
Chris Sosa | 47a7d4e | 2012-03-28 18:26:55 | [diff] [blame] | 76 | if __name__ == '__main__': |
| 77 | unittest.main() |