@@ -23,9 +23,7 @@ def make_host(*fact_pairs):
2323 def get_fact (cls , * args ):
2424 if cls not in facts :
2525 registered = ", " .join (c .__name__ for c in facts )
26- raise LookupError (
27- f"unexpected get_fact({ cls .__name__ } ); only registered: { registered } "
28- )
26+ raise LookupError (f"unexpected get_fact({ cls .__name__ } ); only registered: { registered } " )
2927 return facts [cls ]
3028
3129 return SimpleNamespace (get_fact = get_fact )
@@ -83,9 +81,7 @@ def test_download_dovecot_package_skips_epoch_matched_install(monkeypatch):
8381 lambda ** kwargs : downloads .append (kwargs ),
8482 )
8583
86- deb , changed = dovecot_deployer ._download_dovecot_package (
87- "core" , "amd64" , codename = "bookworm"
88- )
84+ deb , changed = dovecot_deployer ._download_dovecot_package ("core" , "amd64" , deb_release = 12 )
8985
9086 assert deb is None , f"expected no deb path when version matches, got { deb !r} "
9187 assert changed is False , "should not flag changed when version already installed"
@@ -112,14 +108,11 @@ def test_download_dovecot_package_uses_archive_version_for_url_and_filename(
112108 lambda ** kwargs : downloads .append (kwargs ),
113109 )
114110
115- deb , changed = dovecot_deployer ._download_dovecot_package (
116- "core" , "amd64" , codename = "bookworm"
117- )
111+ deb , changed = dovecot_deployer ._download_dovecot_package ("core" , "amd64" , deb_release = 12 )
118112
119- archive_version = dovecot_deployer .DOVECOT_ARCHIVE_VERSION .replace ("+" , "%2B" )
120- expected_deb = f"/root/dovecot-core_{ archive_version } _amd64.deb"
113+ expected_deb = f"/root/dovecot-core_{ dovecot_deployer .DOVECOT_ARCHIVE_VERSION } +deb12u1_amd64.deb"
121114
122- # Verify the returned path uses archive version, not package version (with epoch)
115+ # Verify the returned path uses archive version with distro suffix , not package version (with epoch)
123116 assert changed is True , "should flag changed when package not yet installed"
124117 assert deb == expected_deb , f"deb path mismatch: { deb !r} != { expected_deb !r} "
125118 assert dovecot_deployer .DOVECOT_PACKAGE_VERSION not in deb , (
@@ -144,7 +137,7 @@ def test_install_skips_dpkg_path_when_epoch_matched_packages_present(
144137 },
145138 ),
146139 (dovecot_deployer .Arch , "x86_64" ),
147- (Command , "bookworm" ),
140+ (Command , 'VERSION_ID="12"' ),
148141 ),
149142 )
150143 downloads = []
@@ -158,20 +151,16 @@ def test_install_skips_dpkg_path_when_epoch_matched_packages_present(
158151
159152 assert downloads == [], "should not download when all packages epoch-matched"
160153 assert track_shell == [], "should not run dpkg when all packages epoch-matched"
161- assert deployer .need_restart is False , (
162- "need_restart should be False when nothing changed"
163- )
154+ assert deployer .need_restart is False , "need_restart should be False when nothing changed"
164155
165156
166- def test_install_unsupported_arch_falls_back_to_apt (
167- deployer , patch_blocked , mock_files_put , track_shell , monkeypatch
168- ):
157+ def test_install_unsupported_arch_falls_back_to_apt (deployer , patch_blocked , mock_files_put , track_shell , monkeypatch ):
169158 monkeypatch .setattr (
170159 dovecot_deployer ,
171160 "host" ,
172161 make_host (
173162 (dovecot_deployer .Arch , "riscv64" ),
174- (Command , "bookworm" ),
163+ (Command , 'VERSION_ID="12"' ),
175164 ),
176165 )
177166 apt_calls = []
@@ -192,9 +181,7 @@ def fake_apt(**kwargs):
192181 f"expected apt install of core/imapd/lmtpd, got { actual_pkgs } "
193182 )
194183 assert track_shell == [], "should not run dpkg for unsupported arch"
195- assert deployer .need_restart is True , (
196- "need_restart should be True when apt installed a package"
197- )
184+ assert deployer .need_restart is True , "need_restart should be True when apt installed a package"
198185
199186
200187def test_install_runs_dpkg_when_packages_need_download (
@@ -206,7 +193,7 @@ def test_install_runs_dpkg_when_packages_need_download(
206193 make_host (
207194 (dovecot_deployer .DebPackages , {}),
208195 (dovecot_deployer .Arch , "x86_64" ),
209- (Command , "bookworm" ),
196+ (Command , 'VERSION_ID="12"' ),
210197 ),
211198 )
212199 monkeypatch .setattr (
@@ -222,19 +209,15 @@ def test_install_runs_dpkg_when_packages_need_download(
222209
223210 deployer .install ()
224211
225- assert len (track_shell ) == 1 , (
226- f"expected one server.shell() call for dpkg install, got { len (track_shell )} "
227- )
212+ assert len (track_shell ) == 1 , f"expected one server.shell() call for dpkg install, got { len (track_shell )} "
228213 cmds = track_shell [0 ]["commands" ]
229214 assert len (cmds ) == 1 , f"expected single apt-get install command, got: { cmds } "
230215 assert "apt-get install -y" in cmds [0 ]
231216 assert '-o Dpkg::Options::="--force-confdef"' in cmds [0 ]
232217 assert '-o Dpkg::Options::="--force-confold"' in cmds [0 ]
233218 assert "--allow-downgrades" in cmds [0 ]
234219 assert ".deb" in cmds [0 ]
235- assert deployer .need_restart is True , (
236- "need_restart should be True after dpkg install"
237- )
220+ assert deployer .need_restart is True , "need_restart should be True after dpkg install"
238221
239222
240223def test_pick_url_falls_back_on_primary_error (monkeypatch ):
@@ -243,22 +226,25 @@ def raise_error(req, timeout):
243226
244227 monkeypatch .setattr (dovecot_deployer .urllib .request , "urlopen" , raise_error )
245228 result = dovecot_deployer ._pick_url ("http://primary" , "http://fallback" )
246- assert result == "http://fallback" , (
247- f"should fall back when primary fails, got { result !r} "
248- )
229+ assert result == "http://fallback" , f"should fall back when primary fails, got { result !r} "
249230
250231
251- def test_install_fails_on_unsupported_debian_version (
252- deployer , patch_blocked , monkeypatch
253- ):
232+ def test_install_fails_on_unsupported_debian_version (deployer , patch_blocked , monkeypatch ):
254233 monkeypatch .setattr (
255234 dovecot_deployer ,
256235 "host" ,
257236 make_host (
258237 (dovecot_deployer .Arch , "x86_64" ),
259- (Command , "sid" ),
238+ (Command , 'VERSION_ID="99"' ),
260239 ),
261240 )
262241
263- with pytest .raises (ValueError , match = "Unsupported Debian codename" ):
264- deployer .install ()
242+ # Mock apt.packages to handle unsupported release gracefully
243+ def fake_apt (** kwargs ):
244+ return SimpleNamespace (changed = False )
245+
246+ monkeypatch .setattr (dovecot_deployer .apt , "packages" , fake_apt )
247+
248+ # Should not error, just skip the dovecot-specific packages and use apt
249+ deployer .install ()
250+ assert deployer .need_restart is False , "unsupported release should not trigger restart"
0 commit comments