1# Copyright (C) 2018 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""Unit tests for external updater.""" 15 16import unittest 17 18import github_archive_updater 19 20 21class ExternalUpdaterTest(unittest.TestCase): 22 """Unit tests for external updater.""" 23 def test_url_selection(self): 24 """Tests that GithubArchiveUpdater can choose the right url.""" 25 prefix = "https://github.com/author/project/" 26 urls = [ 27 prefix + "releases/download/ver-1.0/ver-1.0-binary.zip", 28 prefix + "releases/download/ver-1.0/ver-1.0-binary.tar.gz", 29 prefix + "releases/download/ver-1.0/ver-1.0-src.zip", 30 prefix + "releases/download/ver-1.0/ver-1.0-src.tar.gz", 31 prefix + "archive/ver-1.0.zip", 32 prefix + "archive/ver-1.0.tar.gz", 33 ] 34 35 previous_url = prefix + "releases/download/ver-0.9/ver-0.9-src.tar.gz" 36 url = github_archive_updater.choose_best_url(urls, previous_url) 37 expected_url = prefix + "releases/download/ver-1.0/ver-1.0-src.tar.gz" 38 self.assertEqual(url, expected_url) 39 40 previous_url = prefix + "archive/ver-0.9.zip" 41 url = github_archive_updater.choose_best_url(urls, previous_url) 42 expected_url = prefix + "archive/ver-1.0.zip" 43 self.assertEqual(url, expected_url) 44 45 46if __name__ == '__main__': 47 unittest.main() 48