Skip to content

Commit 7155008

Browse files
committed
Update CHANGELOG.md for new namespace command and enhance CLI tests for namespace handling
1 parent b787fb7 commit 7155008

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Add `iop --update` command to update a production from the command line
1111
- New info displayed in `iop --help` command showing current namespace
1212
- `iop --status` command now shows if production needs update, if so a message is displayed
13+
- Command line option `--namespace` alone will show the current namespace
1314

1415
### Fixed
1516
- Fix issue with boolean `response_required` parameter in `send_request_async` method of BusinessProcess

src/iop/_cli.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,29 @@ def __init__(self, args: CommandArgs):
6161
# set environment variable IRISNAMESPACE
6262
os.environ['IRISNAMESPACE'] = self.args.namespace
6363

64+
def _has_primary_command(self) -> bool:
65+
return any([
66+
self.args.default,
67+
self.args.list,
68+
self.args.start,
69+
self.args.stop,
70+
self.args.kill,
71+
self.args.restart,
72+
self.args.status,
73+
self.args.test,
74+
self.args.version,
75+
self.args.export,
76+
self.args.migrate,
77+
self.args.log,
78+
self.args.init,
79+
self.args.update,
80+
])
81+
6482
def execute(self) -> None:
83+
if self.args.namespace == 'not_set' and not self._has_primary_command():
84+
print(os.getenv('IRISNAMESPACE', 'not set'))
85+
return
86+
6587
command_type = self._determine_command_type()
6688
command_handlers = {
6789
CommandType.DEFAULT: self._handle_default,

src/tests/test_cli.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,28 @@ def test_help_and_basic_commands(self):
2323
self.assertEqual(cm.exception.code, 0)
2424
self.assertIn('Namespace:', fake_out.getvalue())
2525

26+
def test_namespace_prints_current(self):
27+
"""Test namespace display when no value is provided."""
28+
with patch.dict(os.environ, {"IRISNAMESPACE": "TESTNS"}, clear=True):
29+
with patch('sys.stdout', new=StringIO()) as fake_out:
30+
with self.assertRaises(SystemExit) as cm:
31+
main(['-n'])
32+
self.assertEqual(cm.exception.code, 0)
33+
self.assertEqual(fake_out.getvalue().strip(), 'TESTNS')
34+
35+
def test_namespace_with_value_prints_help(self):
36+
"""Test namespace assignment prints help when no other command is provided."""
37+
with patch.dict(os.environ, {}, clear=True):
38+
with patch('iop._director._Director.get_default_production') as mock_default:
39+
mock_default.return_value = 'UnitTest.Production'
40+
with patch('sys.stdout', new=StringIO()) as fake_out:
41+
with self.assertRaises(SystemExit) as cm:
42+
main(['-n', 'MyNS'])
43+
self.assertEqual(cm.exception.code, 0)
44+
output = fake_out.getvalue()
45+
self.assertIn('usage:', output)
46+
self.assertIn('Namespace: MyNS', output)
47+
2648
def test_default_settings(self):
2749
"""Test default production settings."""
2850
# Test with name

0 commit comments

Comments
 (0)