Skip to content

Commit 52ce090

Browse files
committed
test(beahave): Added one more step
* Card ID: CCT-1921 * Added check that productid.json contains wanted repo_id and product_id * Make black more happy Signed-off-by: Jiri Hnidek <jhnidek@redhat.com>
1 parent c36eb4d commit 52ce090

2 files changed

Lines changed: 47 additions & 9 deletions

File tree

features/productid.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ Feature: Management of productid certificate by libdnf5 plugin productid
77
| never-enabled-content-37060 |
88
When rpm "slow-eagle" is installed from RPM repository
99
Then productid certificate "37060.pem" is installed in "/etc/pki/product"
10+
And product database contains
11+
| repo_id | product_id |
12+
| never-enabled-content-37060 | 37060 |

features/steps/test_impl_productid.py

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import json
66

7+
78
def run(cmd, shell=True, cwd=None):
89
"""
910
Run a command.
@@ -35,7 +36,7 @@ def run_in_context(context, cmd, can_fail=False, expected_exit_code=None, **run_
3536
:return: None
3637
"""
3738
if getattr(context, "faketime", None) is not None:
38-
cmd = 'NO_FAKE_STAT=1 ' + context.faketime + cmd
39+
cmd = "NO_FAKE_STAT=1 " + context.faketime + cmd
3940

4041
if getattr(context, "fake_kernel_release", None) is not None:
4142
cmd = context.fake_kernel_release + cmd
@@ -45,19 +46,23 @@ def run_in_context(context, cmd, can_fail=False, expected_exit_code=None, **run_
4546

4647
context.cmd = cmd
4748

48-
if hasattr(context.scenario, "working_dir") and 'cwd' not in run_args:
49-
run_args['cwd'] = context.scenario.working_dir
49+
if hasattr(context.scenario, "working_dir") and "cwd" not in run_args:
50+
run_args["cwd"] = context.scenario.working_dir
5051

5152
context.cmd_exitcode, context.cmd_stdout, context.cmd_stderr = run(cmd, **run_args)
5253

5354
if not can_fail and context.cmd_exitcode != 0:
54-
raise AssertionError('Running command "%s" failed: %s' % (cmd, context.cmd_exitcode))
55+
raise AssertionError(
56+
'Running command "%s" failed: %s' % (cmd, context.cmd_exitcode)
57+
)
5558
elif expected_exit_code is not None and expected_exit_code != context.cmd_exitcode:
5659
raise AssertionError(
57-
'Running command "%s" had unexpected exit code: %s' % (cmd, context.cmd_exitcode)
60+
'Running command "%s" had unexpected exit code: %s'
61+
% (cmd, context.cmd_exitcode)
5862
)
5963

60-
@given('system is registered against candlepin server')
64+
65+
@given("system is registered against candlepin server")
6166
def step_impl(context):
6267
"""
6368
Check if the system is registered against the candlepin server. If not, register it.
@@ -71,7 +76,8 @@ def step_impl(context):
7176
cmd = "rhc connect --username admin --password admin --organization donaldduck"
7277
run_in_context(context, cmd, can_fail=False)
7378

74-
@given('repositories are enabled')
79+
80+
@given("repositories are enabled")
7581
def step_impl(context):
7682
"""
7783
Enable repositories for the system.
@@ -82,6 +88,7 @@ def step_impl(context):
8288
cmd = f"dnf5 config-manager setopt {row['repo_id']}.enabled=1"
8389
run_in_context(context, cmd, can_fail=False)
8490

91+
8592
@when('rpm "{rpm_name}" is installed from RPM repository')
8693
def step_impl(context, rpm_name):
8794
"""
@@ -93,7 +100,10 @@ def step_impl(context, rpm_name):
93100
cmd = f"dnf5 install -y {rpm_name}"
94101
run_in_context(context, cmd, can_fail=False)
95102

96-
@then('productid certificate "{product_cert_name}" is installed in "{product_cert_dir_path}"')
103+
104+
@then(
105+
'productid certificate "{product_cert_name}" is installed in "{product_cert_dir_path}"'
106+
)
97107
def step_impl(context, product_cert_name, product_cert_dir_path):
98108
"""
99109
Check if the productid certificate is installed in the specified directory.
@@ -103,4 +113,29 @@ def step_impl(context, product_cert_name, product_cert_dir_path):
103113
:return: None
104114
"""
105115
product_cert_path = os.path.join(product_cert_dir_path, product_cert_name)
106-
assert os.path.exists(product_cert_path)
116+
assert os.path.exists(product_cert_path)
117+
118+
119+
PRODUCTDB_PATH = "/var/lib/rhsm/productid.json"
120+
121+
122+
@then("product database contains")
123+
def step_impl(contex):
124+
"""
125+
Check if the product database contains the expected products and repositories.
126+
:param contex: behave context
127+
:return: None
128+
"""
129+
productdb_content = None
130+
assert os.path.exists(PRODUCTDB_PATH)
131+
with open(PRODUCTDB_PATH) as f:
132+
productdb_content = json.loads(f.read())
133+
134+
assert productdb_content is not None
135+
assert isinstance(productdb_content, dict)
136+
for row in contex.table:
137+
product_id = row["product_id"]
138+
repo_id = row["repo_id"]
139+
assert product_id in productdb_content
140+
repo_list = productdb_content[product_id]
141+
assert repo_id in repo_list

0 commit comments

Comments
 (0)