-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpmbuild: basic sanity check for rhsm
Check that we can actually import the script module, and that we call the script with correct arguments.
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
import sys | ||
import io | ||
import importlib | ||
from unittest import mock, skipIf | ||
|
||
try: | ||
import subscription_manager | ||
except ImportError: | ||
subscription_manager = None | ||
|
||
|
||
def load_module(mod, filename, caller_filename=None): | ||
if caller_filename: | ||
filename = os.path.realpath(os.path.join(caller_filename, "..", | ||
filename)) | ||
|
||
# With the help of: | ||
# https://stackoverflow.com/questions/2601047/import-a-python-module-without-the-py-extension | ||
spec = importlib.util.spec_from_loader( | ||
mod, | ||
importlib.machinery.SourceFileLoader(mod, filename), | ||
) | ||
module = importlib.util.module_from_spec(spec) | ||
spec.loader.exec_module(module) | ||
sys.modules[mod] = module | ||
return module | ||
|
||
|
||
@skipIf(subscription_manager is None, "subscription-manager not installed") | ||
def test_rhsm_subscribe_script(): | ||
with mock.patch("os.getuid", return_value=0): | ||
script = load_module("script", | ||
"../bin/copr-builder-rhsm-subscribe", | ||
__file__) | ||
sys.argv = ["foo", "--org-id", "1", "--system-name", "system"] | ||
|
||
with mock.patch("sys.stdin", io.StringIO("foo")): | ||
with mock.patch("script.rhsm"): | ||
script._main() # pylint: disable=protected-access | ||
assert sys.argv == ['subscription-manager', 'register', | ||
'--force', '--org', '1', '--name', 'system', | ||
'--activationkey', 'foo'] |