Skip to content

Conversation

@SmartDever02
Copy link
Contributor

Description

This PR adds comprehensive unit test coverage for DatasetService retrieval and list methods, significantly improving test coverage for dataset querying and filtering functionality.

Test Coverage Added

get_datasets Method Tests (10 test cases)

Basic Functionality:

  • ✅ Basic pagination without user or filters
  • ✅ Search functionality with keyword filtering
  • ✅ Tag filtering (with tags, empty tags)

Permission-Based Filtering:

  • ✅ Without user (only shows ALL_TEAM datasets)
  • ✅ OWNER with include_all flag (sees all datasets)
  • ✅ NORMAL user with ONLY_ME permission (sees own datasets)
  • ✅ NORMAL user with ALL_TEAM permission (sees team datasets)
  • ✅ NORMAL user with PARTIAL_TEAM permission (sees permitted datasets)
  • ✅ DATASET_OPERATOR with permissions (sees only permitted datasets)
  • ✅ DATASET_OPERATOR without permissions (returns empty result)

get_dataset Method Tests (2 test cases)

  • ✅ Successful single dataset retrieval
  • ✅ Dataset not found (returns None)

get_datasets_by_ids Method Tests (3 test cases)

  • ✅ Successful bulk retrieval of multiple datasets
  • ✅ Empty list handling (returns empty result)
  • ✅ None list handling (returns empty result)

get_process_rules Method Tests (2 test cases)

  • ✅ Retrieval with existing process rule
  • ✅ Retrieval without existing rule (returns default rules)

get_dataset_queries Method Tests (2 test cases)

  • ✅ Successful retrieval of dataset queries with pagination
  • ✅ Empty results when no queries exist

get_related_apps Method Tests (2 test cases)

  • ✅ Successful retrieval of apps using the dataset
  • ✅ Empty results when no related apps exist

Testing Approach

  • Follows TDD principles with Arrange-Act-Assert structure
  • Uses factory pattern for test data creation (consistent with existing tests)
  • Comprehensive mocking of dependencies (database, pagination, tag service)
  • Tests cover both success paths and error conditions
  • Follows project conventions from existing test files:
    • test_dataset_service_update_dataset.py
    • test_dataset_service_delete_dataset.py
    • test_dataset_permission.py

Test Statistics

  • Total test cases: 21 test cases
  • New test file: test_dataset_service_retrieval.py
  • Lines of test code: ~767 lines
  • Coverage: All major scenarios including edge cases

Related Work

This complements the existing test coverage:

  • test_dataset_models.py - Dataset model tests (PR feat: complete test script for dataset models #28512)
  • test_dataset_service_update_dataset.py - Update operations
  • test_dataset_service_delete_dataset.py - Delete operations
  • test_dataset_permission.py - Permission checks

Checklist

  • Tests follow TDD principles
  • All tests pass locally
  • Code follows project style guidelines
  • No linting errors
  • Test coverage is comprehensive
  • Tests use proper mocking and fixtures
  • All edge cases covered
  • Permission logic thoroughly tested

Contribution by Gittensor, learn more at https://gittensor.io/

… methods

Add comprehensive test coverage for dataset service retrieval/list methods:

- get_datasets: pagination, search, filtering, permissions
  * Basic pagination
  * Search functionality
  * Tag filtering
  * Permission-based filtering (ONLY_ME, ALL_TEAM, PARTIAL_TEAM)
  * Role-based filtering (OWNER, DATASET_OPERATOR, NORMAL)
  * include_all flag

- get_dataset: single dataset retrieval
  * Successful retrieval
  * Not found cases

- get_datasets_by_ids: bulk retrieval
  * Successful bulk retrieval
  * Empty/None list handling

- get_process_rules: dataset processing rules
  * With existing rule
  * Without existing rule (defaults)

- get_dataset_queries: dataset query history
  * Successful retrieval with pagination
  * Empty results

- get_related_apps: apps using the dataset
  * Successful retrieval
  * Empty results

Follows TDD principles with Arrange-Act-Assert structure and comprehensive
coverage of all scenarios including edge cases.
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Nov 22, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @SmartDever02, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the unit test coverage for the DatasetService by introducing a new test file dedicated to its retrieval and listing methods. The changes ensure the robustness and correctness of functionalities such as dataset querying, filtering by various criteria (including tags and search keywords), and complex permission-based access controls across different user roles. This comprehensive testing effort aims to improve the reliability of data retrieval operations within the service.

Highlights

  • Expanded get_datasets Test Coverage: Added 10 new test cases for the get_datasets method, covering basic pagination, search functionality, tag filtering, and various permission-based scenarios (ONLY_ME, ALL_TEAM, PARTIAL_TEAM) across different user roles (OWNER, NORMAL, DATASET_OPERATOR), including the include_all flag.
  • get_dataset Method Testing: Introduced 2 test cases for the get_dataset method, ensuring correct single dataset retrieval and proper handling of non-existent datasets.
  • Bulk Retrieval (get_datasets_by_ids) Tests: Added 3 test cases for the get_datasets_by_ids method, verifying successful bulk retrieval and robust handling of empty or None input lists.
  • get_process_rules Functionality Tests: Implemented 2 test cases for the get_process_rules method, confirming correct retrieval of existing rules and the return of default rules when none are found.
  • get_dataset_queries and get_related_apps Tests: Included 2 test cases each for get_dataset_queries and get_related_apps, validating successful retrieval and handling of empty results for dataset queries and associated applications.
  • Adherence to Testing Best Practices: The new tests follow Test-Driven Development (TDD) principles, utilize a factory pattern for consistent test data creation, employ comprehensive mocking for dependencies (database, pagination, tag service), and cover both success and error paths, aligning with existing project conventions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive suite of unit tests for the DatasetService retrieval methods, significantly improving test coverage. The tests are well-structured, follow the Arrange-Act-Assert pattern, and cover a wide range of scenarios including pagination, filtering, and permissions.

My review focuses on improving test robustness and correctness. I've suggested using create_autospec consistently for mock creation to make tests more resilient to changes in the underlying models. I also identified and proposed a fix for a test case that had incorrect logic for filtering by tags.

Overall, this is a high-quality contribution that strengthens the reliability of the dataset service.

@SmartDever02
Copy link
Contributor Author

@crazywoola Please review my pr.

SmartDever02 and others added 2 commits November 22, 2025 17:38
When tag_ids is an empty list, the implementation skips tag filtering
entirely (to avoid WHERE false condition) and continues with the normal
query. The test was incorrectly expecting empty results.

Updated the test to:
- Expect normal query results when tag_ids is empty
- Verify that TagService.get_target_ids_by_tag_ids is not called
- Verify that pagination is called normally

This matches the actual behavior where empty tag_ids means 'no tag filter'
rather than 'return empty results'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant