blob: d9378df4cf7e9bd0a4819dcf0825d366971af04d [file] [log] [blame]
Chris Sosa47a7d4e2012-03-28 11:26:55 -07001#!/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 Arnoldc65330c2012-09-20 15:17:48 -07007"""Unit tests for downloader module."""
Chris Sosa47a7d4e2012-03-28 11:26:55 -07008
Chris Sosa76e44b92013-01-31 12:11:38 -08009import mox
Chris Sosa47a7d4e2012-03-28 11:26:55 -070010import os
11import shutil
12import tempfile
13import unittest
14
Gilad Arnoldc65330c2012-09-20 15:17:48 -070015import build_artifact
Chris Sosa47a7d4e2012-03-28 11:26:55 -070016import downloader
17
18
Chris Sosa76e44b92013-01-31 12:11:38 -080019# pylint: disable=W0212,E1120
Chris Masone816e38c2012-05-02 12:22:36 -070020class DownloaderTestBase(mox.MoxTestBase):
Chris Sosa47a7d4e2012-03-28 11:26:55 -070021
22 def setUp(self):
23 mox.MoxTestBase.setUp(self)
24 self._work_dir = tempfile.mkdtemp('downloader-test')
Chris Sosa76e44b92013-01-31 12:11:38 -080025 self.board = 'x86-mario-release'
Chris Sosa47a7d4e2012-03-28 11:26:55 -070026 self.build = 'R17-1413.0.0-a1-b1346'
Chris Sosa76e44b92013-01-31 12:11:38 -080027 self.archive_url = (
28 'gs://chromeos-image-archive/%s/%s' % (self.board, self.build))
Chris Sosa47a7d4e2012-03-28 11:26:55 -070029
30 def tearDown(self):
Gilad Arnold0b8c3f32012-09-19 14:35:44 -070031 shutil.rmtree(self._work_dir, ignore_errors=True)
Chris Sosa47a7d4e2012-03-28 11:26:55 -070032
Chris Sosa76e44b92013-01-31 12:11:38 -080033 def testSimpleDownloadOfTestSuites(self):
34 """Basic test_suites test.
Chris Sosa47a7d4e2012-03-28 11:26:55 -070035
Chris Sosa76e44b92013-01-31 12:11:38 -080036 Verifies that if we request the test_suites, it gets downloaded and
37 the autotest tarball is attempted in the background.
Chris Sosa47a7d4e2012-03-28 11:26:55 -070038 """
Chris Sosa76e44b92013-01-31 12:11:38 -080039 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 Sosa47a7d4e2012-03-28 11:26:55 -070045
Chris Sosa76e44b92013-01-31 12:11:38 -080046 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 Sosa47a7d4e2012-03-28 11:26:55 -070050 self.mox.ReplayAll()
Chris Sosa76e44b92013-01-31 12:11:38 -080051 downloader_instance.Download(artifacts=['test_suites'])
52 # Sanity check the timestamp file exists.
Alex Millera44d5022012-07-27 11:34:16 -070053 self.assertTrue(os.path.exists(
Chris Sosa76e44b92013-01-31 12:11:38 -080054 os.path.join(self._work_dir, self.board, self.build,
55 downloader.Downloader._TIMESTAMP_FILENAME)))
56 self.mox.VerifyAll()
Chris Sosa9164ca32012-03-28 11:04:50 -070057
Chris Sosa76e44b92013-01-31 12:11:38 -080058 def testDownloadSymbols(self):
59 """Basic symbols download."""
60 downloader_instance = downloader.Downloader(self._work_dir,
61 self.archive_url)
62 self.mox.StubOutWithMock(downloader.Downloader,
63 '_DownloadArtifactsSerially')
64 # Should not get called but mocking so that we know it wasn't called.
65 self.mox.StubOutWithMock(downloader.Downloader,
66 '_DownloadArtifactsInBackground')
67 downloader.Downloader._DownloadArtifactsSerially(
68 [mox.IsA(build_artifact.TarballBuildArtifact)], no_wait=True)
Chris Masone816e38c2012-05-02 12:22:36 -070069 self.mox.ReplayAll()
Chris Sosa76e44b92013-01-31 12:11:38 -080070 downloader_instance.Download(artifacts=['symbols'])
Chris Masone816e38c2012-05-02 12:22:36 -070071 self.mox.VerifyAll()
72
73
Chris Sosa47a7d4e2012-03-28 11:26:55 -070074if __name__ == '__main__':
75 unittest.main()