Centeralize test username lookup

This commit is contained in:
Daniel A. Wozniak 2018-05-06 14:30:37 -07:00
parent 6a6ab69722
commit a056a293f1
No known key found for this signature in database
GPG key ID: 166B9D2C06C82D61
2 changed files with 6 additions and 11 deletions

View file

@ -57,6 +57,7 @@ import multiprocessing
# Import tests support libs
import tests.support.paths as paths
import tests.support.helpers
# Import 3rd-party libs
import salt.ext.six as six
@ -103,12 +104,9 @@ try:
except ImportError:
pass
if sys.platform.startswith('win'):
import win32api # pylint: disable=import-error
RUNNING_TESTS_USER = win32api.GetUserName()
else:
import pwd
RUNNING_TESTS_USER = pwd.getpwuid(os.getuid()).pw_name
RUNNING_TESTS_USER = tests.support.helpers.this_user()
log = logging.getLogger(__name__)

View file

@ -31,6 +31,7 @@ from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import NO_MOCK, NO_MOCK_REASON
from tests.support.paths import TMP, FILES
from tests.support.helpers import this_user
# Import salt libs
import salt.utils.gitfs
@ -207,11 +208,7 @@ class GitFSTest(TestCase, LoaderModuleMockMixin):
if 'USERNAME' not in os.environ:
try:
import salt.utils
if salt.utils.is_windows():
import salt.utils.win_functions
os.environ['USERNAME'] = salt.utils.win_functions.get_current_user()
else:
os.environ['USERNAME'] = pwd.getpwuid(os.geteuid()).pw_name
os.environ['USERNAME'] = this_user()
except AttributeError:
log.error('Unable to get effective username, falling back to '
'\'root\'.')