1818
1919import attr
2020import pytest
21+ import requests
2122from saltfactories .utils import random_string
2223from saltfactories .utils .tempfiles import temp_file
2324
@@ -70,9 +71,7 @@ def test_blah():
7071 elif saltenv == "prod" :
7172 directory = RUNTIME_VARS .TMP_PRODENV_STATE_TREE
7273 else :
73- raise RuntimeError (
74- '"saltenv" can only be "base" or "prod", not "{}"' .format (saltenv )
75- )
74+ raise RuntimeError (f'"saltenv" can only be "base" or "prod", not "{ saltenv } "' )
7675 return temp_file (
7776 name , contents , directory = directory , strip_first_newline = strip_first_newline
7877 )
@@ -118,9 +117,7 @@ def test_blah():
118117 elif saltenv == "prod" :
119118 directory = RUNTIME_VARS .TMP_PRODENV_PILLAR_TREE
120119 else :
121- raise RuntimeError (
122- '"saltenv" can only be "base" or "prod", not "{}"' .format (saltenv )
123- )
120+ raise RuntimeError (f'"saltenv" can only be "base" or "prod", not "{ saltenv } "' )
124121 return temp_file (
125122 name , contents , directory = directory , strip_first_newline = strip_first_newline
126123 )
@@ -161,7 +158,7 @@ def salt_loader_module_functions(module):
161158 # Not a function? carry on
162159 continue
163160 funcname = func_alias .get (func .__name__ ) or func .__name__
164- funcs ["{ }.{}" . format ( virtualname , funcname ) ] = func
161+ funcs [f" { virtualname } .{ funcname } " ] = func
165162 return funcs
166163
167164
@@ -178,7 +175,7 @@ def remove_stale_minion_key(master, minion_id):
178175def remove_stale_proxy_minion_cache_file (proxy_minion , minion_id = None ):
179176 cachefile = os .path .join (
180177 proxy_minion .config ["cachedir" ],
181- "dummy-proxy-{}.cache" . format ( minion_id or proxy_minion .id ) ,
178+ f "dummy-proxy-{ minion_id or proxy_minion .id } .cache" ,
182179 )
183180 if os .path .exists (cachefile ):
184181 os .unlink (cachefile )
@@ -273,7 +270,7 @@ def _default_hashed_password(self):
273270 @group_name .default
274271 def _default_group_name (self ):
275272 if self .create_group :
276- return "group-{}" . format ( self .username )
273+ return f "group-{ self .username } "
277274 return None
278275
279276 @_group .default
@@ -788,6 +785,18 @@ def change_cwd(path):
788785 os .chdir (old_cwd )
789786
790787
788+ @pytest .helpers .register
789+ def download_file (url , dest , auth = None ):
790+ # NOTE the stream=True parameter below
791+ with requests .get (url , allow_redirects = True , stream = True , auth = auth ) as r :
792+ r .raise_for_status ()
793+ with salt .utils .files .fopen (dest , "wb" ) as f :
794+ for chunk in r .iter_content (chunk_size = 8192 ):
795+ if chunk :
796+ f .write (chunk )
797+ return dest
798+
799+
791800# Only allow star importing the functions defined in this module
792801__all__ = [
793802 name
0 commit comments