test_util_partials.py (5064B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 import unittest 6 from unittest import mock 7 8 from mozunit import main 9 10 from gecko_taskgraph.util import partials 11 12 release_blob = { 13 "fileUrls": { 14 "release-localtest": { 15 "completes": { 16 "*": "%OS_FTP%/%LOCALE%/firefox-92.0.1.complete.mar", 17 } 18 } 19 }, 20 "platforms": { 21 "WINNT_x86_64-msvc": { 22 "locales": { 23 "en-US": { 24 "buildID": "20210922161155", 25 } 26 } 27 } 28 }, 29 } 30 31 32 def nightly_blob(release): 33 # Added for bug 1883046, where we identified a case where a Balrog release 34 # that does not contain completes will throw an unnecessary exception. 35 if release == "Firefox-mozilla-central-nightly-20211001214601": 36 return { 37 "platforms": { 38 "WINNT_x86_64-msvc": { 39 "locales": { 40 "en-US": { 41 "buildID": release[-14:], 42 "partials": [{"fileUrl": release}], 43 } 44 } 45 } 46 } 47 } 48 else: 49 return { 50 "platforms": { 51 "WINNT_x86_64-msvc": { 52 "locales": { 53 "en-US": { 54 "buildID": release[-14:], 55 "completes": [{"fileUrl": release}], 56 } 57 } 58 } 59 } 60 } 61 62 63 class TestReleaseHistory(unittest.TestCase): 64 @mock.patch("gecko_taskgraph.util.partials.get_release_builds") 65 @mock.patch("gecko_taskgraph.util.partials.get_sorted_releases") 66 def test_populate_release_history(self, get_sorted_releases, get_release_builds): 67 self.assertEqual( 68 partials.populate_release_history( 69 "Firefox", "mozilla-release", partial_updates={} 70 ), 71 {}, 72 ) 73 get_sorted_releases.assert_not_called() 74 get_release_builds.assert_not_called() 75 76 def patched_get_sorted_releases(product, branch): 77 assert branch == "mozilla-central" 78 return [ 79 "Firefox-mozilla-central-nightly-20211003201113", 80 "Firefox-mozilla-central-nightly-20211003100640", 81 "Firefox-mozilla-central-nightly-20211002213629", 82 "Firefox-mozilla-central-nightly-20211002095048", 83 "Firefox-mozilla-central-nightly-20211001214601", 84 "Firefox-mozilla-central-nightly-20211001093323", 85 ] 86 87 def patched_get_release_builds(release, branch): 88 if branch == "mozilla-central": 89 return nightly_blob(release) 90 if branch == "mozilla-release": 91 return release_blob 92 93 get_sorted_releases.side_effect = patched_get_sorted_releases 94 get_release_builds.side_effect = patched_get_release_builds 95 96 self.assertEqual( 97 partials.populate_release_history( 98 "Firefox", 99 "mozilla-release", 100 partial_updates={"92.0.1": {"buildNumber": 1}}, 101 ), 102 { 103 "WINNT_x86_64-msvc": { 104 "en-US": { 105 "target-92.0.1.partial.mar": { 106 "buildid": "20210922161155", 107 "mar_url": "win64/en-US/firefox-92.0.1.complete.mar", 108 "previousVersion": "92.0.1", 109 "previousBuildNumber": 1, 110 "product": "Firefox", 111 } 112 } 113 } 114 }, 115 ) 116 self.assertEqual( 117 partials.populate_release_history("Firefox", "mozilla-central"), 118 { 119 "WINNT_x86_64-msvc": { 120 "en-US": { 121 "target.partial-1.mar": { 122 "buildid": "20211003201113", 123 "mar_url": "Firefox-mozilla-central-nightly-20211003201113", 124 }, 125 "target.partial-2.mar": { 126 "buildid": "20211003100640", 127 "mar_url": "Firefox-mozilla-central-nightly-20211003100640", 128 }, 129 "target.partial-3.mar": { 130 "buildid": "20211002213629", 131 "mar_url": "Firefox-mozilla-central-nightly-20211002213629", 132 }, 133 "target.partial-4.mar": { 134 "buildid": "20211002095048", 135 "mar_url": "Firefox-mozilla-central-nightly-20211002095048", 136 }, 137 } 138 } 139 }, 140 ) 141 142 143 if __name__ == "__main__": 144 main()