Skip to content

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

Open
berendt wants to merge 1 commit intomainfrom
gh2228
Open

Add unit tests for osism/utils connection initialization helpers#2247
berendt wants to merge 1 commit intomainfrom
gh2228

Conversation

@berendt
Copy link
Copy Markdown
Member

@berendt berendt commented May 3, 2026

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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

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
Copy link
Copy Markdown
Contributor

@ideaship ideaship left a comment

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>
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