Skip to content

Add unit tests for osism/utils connection initialization helpers - #2247

Merged
ideaship merged 1 commit into
mainfrom
gh2228
May 19, 2026
Merged

Add unit tests for osism/utils connection initialization helpers#2247
ideaship merged 1 commit into
mainfrom
gh2228

Conversation

@berendt

@berendt berendt commented May 3, 2026

Copy link
Copy Markdown
Member

Cover _init_redis, _init_nb, _init_secondary_nb_list, _get_timeout_http_adapter_class, NetBoxSessionManager, cleanup_netbox_sessions, get_netbox_connection,
get_openstack_connection and the lazy getattr indirection in osism/utils/init.py.

Closes #2228

AI-assisted: Claude Code

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The reset_module_globals fixture duplicates the same reset logic before and after yield; consider extracting this into a small helper function or loop to avoid repetition and make future updates less error-prone.
  • Many of the _init_secondary_nb_list tests share similar setup and assertion patterns; you could use pytest.mark.parametrize to consolidate these into fewer parametrized tests and improve readability and maintainability.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `reset_module_globals` fixture duplicates the same reset logic before and after `yield`; consider extracting this into a small helper function or loop to avoid repetition and make future updates less error-prone.
- Many of the `_init_secondary_nb_list` tests share similar setup and assertion patterns; you could use `pytest.mark.parametrize` to consolidate these into fewer parametrized tests and improve readability and maintainability.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@berendt
berendt force-pushed the gh2228 branch 2 times, most recently from caeb0a5 to 22a94da Compare May 3, 2026 19:51
@berendt
berendt requested a review from ideaship May 4, 2026 05:56

@ideaship ideaship left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty_url, missing_token, and whitespace_token cases all pass
log_substring=None. But the production code reaches the except
(yaml.YAMLError, TypeError, ValueError) branch for all three and logs "Error
parsing settings NETBOX_SECONDARIES: ...". The tests only verify result == [],
leaving the error-logging path unverified — yet the six other error cases in
the same parametrize do check logs. Inconsistency means a future deletion of
the logger.error(...) call would not be caught by these three cases.

Cover _init_redis, _init_nb, _init_secondary_nb_list,
_get_timeout_http_adapter_class, NetBoxSessionManager,
cleanup_netbox_sessions, get_netbox_connection,
get_openstack_connection and the lazy __getattr__ indirection
in osism/utils/__init__.py.

Closes #2228

AI-assisted: Claude Code

Signed-off-by: Christian Berendt <berendt@osism.tech>
@ideaship
ideaship merged commit 4a75ee5 into main May 19, 2026
3 checks passed
@ideaship
ideaship deleted the gh2228 branch May 19, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unit tests for osism/utils/__init__.py — connection initialization

3 participants