blob: d9378df4cf7e9bd0a4819dcf0825d366971af04d [file] [log] [blame]
Chris Sosa47a7d4e2012-03-28 18:26:551#!/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 22:17:487"""Unit tests for downloader module."""
Chris Sosa47a7d4e2012-03-28 18:26:558
Chris Sosa76e44b92013-01-31 20:11:389import mox
Chris Sosa47a7d4e2012-03-28 18:26:5510import os
11import shutil
12import tempfile
13import unittest
14
Gilad Arnoldc65330c2012-09-20 22:17:4815import build_artifact
Chris Sosa47a7d4e2012-03-28 18:26:5516import downloader
17
18
Chris Sosa76e44b92013-01-31 20:11:3819# pylint: disable=W0212,E1120
Chris Masone816e38c2012-05-02 19:22:3620class DownloaderTestBase(mox.MoxTestBase):
Chris Sosa47a7d4e2012-03-28 18:26:5521
22 def setUp(self):
23 mox.MoxTestBase.setUp(self)
24 self._work_dir = tempfile.mkdtemp('downloader-test')
Chris Sosa76e44b92013-01-31 20:11:3825 self.board = 'x86-mario-release'
Chris Sosa47a7d4e2012-03-28 18:26:5526 self.build = 'R17-1413.0.0-a1-b1346'
Chris Sosa76e44b92013-01-31 20:11:3827 self.archive_url = (
28 'gs://chromeos-image-archive/%s/%s' % (self.board, self.build))
Chris Sosa47a7d4e2012-03-28 18:26:5529
30 def tearDown(self):
Gilad Arnold0b8c3f32012-09-19 21:35:4431 shutil.rmtree(self._work_dir, ignore_errors=True)
Chris Sosa47a7d4e2012-03-28 18:26:5532
Chris Sosa76e44b92013-01-31 20:11:3833 def testSimpleDownloadOfTestSuites(self):
34 """Basic test_suites test.
Chris Sosa47a7d4e2012-03-28 18:26:5535
Chris Sosa76e44b92013-01-31 20:11:3836 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 18:26:5538 """
Chris Sosa76e44b92013-01-31 20:11:3839 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 18:26:5545
Chris Sosa76e44b92013-01-31 20:11:3846 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 18:26:5550 self.mox.ReplayAll()
Chris Sosa76e44b92013-01-31 20:11:3851 downloader_instance.Download(artifacts=['test_suites'])
52 # Sanity check the timestamp file exists.
Alex Millera44d5022012-07-27 18:34:1653 self.assertTrue(os.path.exists(
Chris Sosa76e44b92013-01-31 20:11:3854 os.path.join(self._work_dir, self.board, self.build,
55 downloader.Downloader._TIMESTAMP_FILENAME)))
56 self.mox.VerifyAll()
Chris Sosa9164ca32012-03-28 18:04:5057
Chris Sosa76e44b92013-01-31 20:11:3858 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 19:22:3669 self.mox.ReplayAll()
Chris Sosa76e44b92013-01-31 20:11:3870 downloader_instance.Download(artifacts=['symbols'])
Chris Masone816e38c2012-05-02 19:22:3671 self.mox.VerifyAll()
72
73
Chris Sosa47a7d4e2012-03-28 18:26:5574if __name__ == '__main__':
75 unittest.main()