potpie icon indicating copy to clipboard operation
potpie copied to clipboard

Generate Unit Tests for github_service.py

Open dhirenmathur opened this issue 1 year ago • 13 comments

Description:

We need to create unit tests for the github_service.py file located in the app/modules/github/ directory. The goal is to ensure that all functions are thoroughly tested for expected behavior, edge cases, and error handling.

Functions to Test:

  1. get_github_repo_details: Test the retrieval of GitHub repository details, including handling of invalid repository names and API errors.

  2. get_file_content: Validate file content retrieval, including:

    • Successful access to private and public repositories.
    • Handling of directory paths instead of file paths.
    • Correct line selection based on start_line and end_line.
  3. get_repos_for_user: Validate the retrieval of repositories for a user, including error handling for missing users and tokens.

  4. get_combined_user_repos: Test the combination of user repositories and project repositories, ensuring no duplicates.

  5. get_branch_list: Validate branch retrieval, including error handling for non-existent repositories.

  6. get_public_github_instance: Ensure that a public GitHub instance is returned correctly.

  7. get_repo: Test the retrieval of a repository, including handling of both private and public access failures.

  8. get_project_structure_async: Validate the fetching of project structure, including caching behavior.

Testing Framework:

  • Use pytest for writing the unit tests.
  • Consider using pytest-mock or unittest.mock to mock external dependencies like GitHub API calls and database interactions.

Acceptance Criteria:

  • All functions have corresponding unit tests.
  • Tests cover both happy paths and edge cases.
  • Code coverage should be at least 80%.

Additional Notes:

  • Please ensure that the tests are organized and follow best practices for readability and maintainability.

dhirenmathur avatar Nov 09 '24 06:11 dhirenmathur

@dhirenmathur I'd like to take up this issue. The tests should go into which folder?

Anu-Ra-g avatar Nov 11 '24 14:11 Anu-Ra-g

@Anu-Ra-g that's great, you should create a new folder in the root directory of the project called tests

dhirenmathur avatar Nov 11 '24 14:11 dhirenmathur

I'm using this for setting up the tests/module/github/test_github_service.py package, instead of using __init__.py

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../')))

from app.modules.github.github_service import GithubService

Will it be okay?

Anu-Ra-g avatar Nov 12 '24 13:11 Anu-Ra-g

@Anu-Ra-g I would recommend to stick to creating the init file, this approach could end up being difficult to maintain and run tests from other directories

dhirenmathur avatar Nov 13 '24 03:11 dhirenmathur

@Anu-Ra-g let us know if you need any help

dhirenmathur avatar Nov 21 '24 05:11 dhirenmathur

@Anu-Ra-g are you still working on this?

dhirenmathur avatar Nov 26 '24 09:11 dhirenmathur

Yes, I'm still working on this but I got a little busy. I will make the PR as soon as possible.

Anu-Ra-g avatar Nov 27 '24 03:11 Anu-Ra-g

Go ahead

Anu-Ra-g avatar Dec 19 '24 17:12 Anu-Ra-g

@dhirenmathur I'd like to solve this one as well if that is okay.

simin75simin avatar Jan 17 '25 15:01 simin75simin

@simin75simin let's do the issues one at a time so that others have a chance as well, there's already an open PR for this one too :)

dhirenmathur avatar Jan 18 '25 07:01 dhirenmathur

@simin75simin let's do the issues one at a time so that others have a chance as well, there's already an open PR for this one too :)

sorry just looking for things to contribute and this one seemed dormant

simin75simin avatar Jan 19 '25 05:01 simin75simin

You are right that this is dormant @simin75simin, if we can validate that no work is needed in the other issue, you can pick this up! Thank you!

dhirenmathur avatar Jan 23 '25 07:01 dhirenmathur

Could I try working on this?

Phantom0110 avatar Feb 10 '25 14:02 Phantom0110