Skip to content

tests: add unit tests for query type functions in schemas.py#281

Open
Nikitaa104 wants to merge 1 commit intojenkinsci:mainfrom
Nikitaa104:tests/query-type-functions-schemas-277
Open

tests: add unit tests for query type functions in schemas.py#281
Nikitaa104 wants to merge 1 commit intojenkinsci:mainfrom
Nikitaa104:tests/query-type-functions-schemas-277

Conversation

@Nikitaa104
Copy link
Contributor

What this PR does

Adds unit tests for the three query type utility functions in
api/models/schemas.py which had zero test coverage.

Functions Tested

  • is_valid_query_type()—validates if a string is a valid QueryType member
  • str_to_query_type()—converts string to QueryType enum
  • try_str_to_query_type()—safe conversion with fallback to MULTI

Test Cases Added (14 total)

  • is_valid_query_type() returns True for SIMPLE and MULTI
  • is_valid_query_type() returns False for invalid and empty strings
  • is_valid_query_type() is case sensitive
  • str_to_query_type() correctly converts SIMPLE and MULTI
  • str_to_query_type() raises ValueError for invalid and empty input
  • try_str_to_query_type() returns correct QueryType for valid input
  • try_str_to_query_type() falls back to MULTI for invalid input
  • try_str_to_query_type() logs warning on invalid input
  • try_str_to_query_type() falls back to MULTI for empty string

Local Test Results

14 passed, 4 warnings in 0.22s

Closes #277

- test is_valid_query_type() for valid, invalid, empty, and case-sensitive inputs
- test str_to_query_type() for correct conversion and ValueError on invalid input
- test try_str_to_query_type() for fallback to MULTI and warning log on invalid input

Closes jenkinsci#277
@Nikitaa104 Nikitaa104 requested a review from a team as a code owner March 14, 2026 17:15
@Nikitaa104
Copy link
Contributor Author

Hi @berviantoleo, I've added 14 unit tests for the query type utility functions in schemas.py which had zero coverage. All tests pass locally:
14 passed, 4 warnings in 0.22s
Please take a look!

@berviantoleo berviantoleo added the tests This PR adds/removes/updates test cases label Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests This PR adds/removes/updates test cases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Tests] Add unit tests for query type functions in api/models/schemas.py

2 participants