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 24 def test_url_selection(self): 25 """Tests that GithubArchiveUpdater can choose the right url.""" 26 prefix = "https://github.com/author/project/" 27 urls = [ 28 prefix + "releases/download/ver-1.0/ver-1.0-binary.zip", 29 prefix + "releases/download/ver-1.0/ver-1.0-binary.tar.gz", 30 prefix + "releases/download/ver-1.0/ver-1.0-src.zip", 31 prefix + "releases/download/ver-1.0/ver-1.0-src.tar.gz", 32 prefix + "archive/ver-1.0.zip", 33 prefix + "archive/ver-1.0.tar.gz", 34 ] 35 36 previous_url = prefix + "releases/download/ver-0.9/ver-0.9-src.tar.gz" 37 url = github_archive_updater.choose_best_url(urls, previous_url) 38 expected_url = prefix + "releases/download/ver-1.0/ver-1.0-src.tar.gz" 39 self.assertEqual(url, expected_url) 40 41 previous_url = prefix + "archive/ver-0.9.zip" 42 url = github_archive_updater.choose_best_url(urls, previous_url) 43 expected_url = prefix + "archive/ver-1.0.zip" 44 self.assertEqual(url, expected_url) 45 46 47if __name__ == '__main__': 48 unittest.main() 49