blob: 3c8083a32213dab29ff1f82a549b78ca9d912935 [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 Sosa6b0c6172013-08-05 17:01:33 -070051 downloader_instance.Download(artifacts=['test_suites'],
52 files=None)
Chris Sosa76e44b92013-01-31 12:11:38 -080053 # Sanity check the timestamp file exists.
Alex Millera44d5022012-07-27 11:34:16 -070054 self.assertTrue(os.path.exists(
Chris Sosa76e44b92013-01-31 12:11:38 -080055 os.path.join(self._work_dir, self.board, self.build,
56 downloader.Downloader._TIMESTAMP_FILENAME)))
57 self.mox.VerifyAll()
Chris Sosa9164ca32012-03-28 11:04:50 -070058
Chris Sosa76e44b92013-01-31 12:11:38 -080059 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 Masone816e38c2012-05-02 12:22:36 -070070 self.mox.ReplayAll()
Chris Sosa6b0c6172013-08-05 17:01:33 -070071 downloader_instance.Download(artifacts=['symbols'],
72 files=None)
Chris Masone816e38c2012-05-02 12:22:36 -070073 self.mox.VerifyAll()
74
75
Chris Sosa47a7d4e2012-03-28 11:26:55 -070076if __name__ == '__main__':
77 unittest.main()