Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactored tests to make them easier to maintain #215

Merged
merged 1 commit into from
Nov 10, 2024

Conversation

TeKrop
Copy link
Owner

@TeKrop TeKrop commented Nov 10, 2024

Summary by Sourcery

Refactor test cases to enhance maintainability by simplifying parameterization and removing redundant assertions, and streamline test setup and execution.

Enhancements:

  • Refactor test cases to improve maintainability and readability by simplifying parameterization and removing redundant assertions.

Tests:

  • Reorganize test fixtures and parameterization to streamline test setup and execution.
  • Remove redundant test data and assertions to focus on essential test validations.

@TeKrop TeKrop added the enhancement New feature or request label Nov 10, 2024
@TeKrop TeKrop self-assigned this Nov 10, 2024
Copy link
Contributor

sourcery-ai bot commented Nov 10, 2024

Reviewer's Guide by Sourcery

The changes focus on refactoring and simplifying tests across multiple components. The main changes include removing redundant test assertions, simplifying test data fixtures, and standardizing error message handling. The implementation moves towards more focused testing by verifying core functionality rather than exact response matching.

Class diagram for refactored test structure

classDiagram
    class TestClient {
        +get(url: str) TestResponse
    }
    class TestResponse {
        +status_code: int
        +json() dict
    }
    class Mock {
        +status_code: int
        +text: str
    }
    class PlayerGamemode {
        <<enumeration>>
        QUICKPLAY
    }
    class PlayerPlatform {
        <<enumeration>>
        PC
        CONSOLE
    }
    class HeroKeyCareerFilter {
        <<enumeration>>
        ANA
    }
    class CacheManager {
        +update_search_data_cache(data: dict)
    }
    class MapsParser {
        +data: list
        +parse() void
    }
    class OverfastError {
    }
    class Settings {
        +internal_server_error_message: str
    }
    class RouteTag {
        <<enumeration>>
        HEROES
        GAMEMODES
        MAPS
        PLAYERS
    }
    class FastAPI {
        +title: str
        +description: str
        +version: str
        +openapi_tags: list
        +servers: list
        +contact: dict
        +license_info: dict
    }
    class StaticFiles {
        +directory: str
    }
    class Logger {
        +info(message: str)
    }
    class StarletteHTTPException {
    }
    class PydanticValidationError {
    }
    class Profiler {
        <<enumeration>>
        MEMRAY
        PYINSTRUMENT
    }
    class MemrayInMemoryMiddleware {
    }
    class PyInstrumentMiddleware {
    }
Loading

File-Level Changes

Change Details Files
Simplified test assertions by focusing on core functionality rather than exact response matching
  • Removed exact JSON response matching in favor of simpler length/key presence checks
  • Standardized error message handling using settings.internal_server_error_message
  • Removed redundant response structure validation
tests/heroes/test_heroes_route.py
tests/roles/test_roles_route.py
tests/players/test_player_career_route.py
tests/players/test_player_summary_route.py
Refactored test data fixtures to be more maintainable
  • Removed unused JSON data fixtures
  • Simplified fixture parameters by removing redundant data
  • Added type hints to fixture functions
  • Consolidated duplicate test data
tests/players/conftest.py
tests/roles/conftest.py
tests/players/parsers/test_namecard_parser.py
tests/players/parsers/test_player_career_parser.py
Improved test structure for player stats routes
  • Split large parameterized test into multiple focused test cases
  • Added setup fixture to reduce code duplication
  • Improved test case naming and organization
tests/players/test_player_stats_route.py
tests/players/test_player_stats_summary_route.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

sonarcloud bot commented Nov 10, 2024

Copy link
Contributor

sourcery-ai bot commented Nov 10, 2024

🧙 Sourcery is reviewing your pull request!


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

1 similar comment
Copy link
Contributor

sourcery-ai bot commented Nov 10, 2024

🧙 Sourcery is reviewing your pull request!


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@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 @TeKrop - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Found a potential Optimizely project ID hardcoded in the JavaScript code (link)
  • Found a hardcoded Optimizely project ID that could potentially be used to access the account (link)
  • Found a hardcoded Optimizely project ID that could potentially be used to access the project configuration (link)
  • Found a hardcoded Optimizely project ID that could potentially be used to access the project configuration (link)
  • Found a potential Optimizely API key/project ID in the JavaScript code (link)
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🔴 Security: 5 blocking issues
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

</script><script>var BlzCookieConsent = JSON.parse('{"host":".blizzard.com","cookieInfoUrlPattern":"/cookies/?$","onetrustScriptUrl":"https://cdn.cookielaw.org/scripttemplates/otSDKStub.js","onetrustDomainScript":"22011b0f-2c46-49a3-a7bf-5f98a4d4da65"}');</script><script src="https://static.playoverwatch.com/js/cookie-consent-filter-ed6098b4bf.js"></script><link rel="preload" as="script" crossorigin href="https://cdn.optimizely.com/js/8304241110.js"><link rel="preconnect" href="//logx.optimizely.com"><script>window.addEventListener('CookieConsentChange', (event) => {
if (typeof BlzCookieConsent !== 'undefined' && BlzCookieConsent.initialized && BlzCookieConsent.isPerformanceStorageAllowed() && !window.document.querySelector('script[data-optimizely]')) {
var script = document.createElement('script');
script.src = `https://cdn.optimizely.com/js/8304241110.js`;
Copy link
Contributor

Choose a reason for hiding this comment

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

🚨 issue (security): Found a potential Optimizely project ID hardcoded in the JavaScript code

The Optimizely project ID '8304241110' appears to be hardcoded in the source. While this may be a test fixture, it's worth verifying if this is a real production ID that should be moved to configuration.

</script><script>var BlzCookieConsent = JSON.parse('{"host":".blizzard.com","cookieInfoUrlPattern":"/cookies/?$","onetrustScriptUrl":"https://cdn.cookielaw.org/scripttemplates/otSDKStub.js","onetrustDomainScript":"22011b0f-2c46-49a3-a7bf-5f98a4d4da65"}');</script><script src="https://static.playoverwatch.com/js/cookie-consent-filter-ed6098b4bf.js"></script><link rel="preload" as="script" crossorigin href="https://cdn.optimizely.com/js/8304241110.js"><link rel="preconnect" href="//logx.optimizely.com"><script>window.addEventListener('CookieConsentChange', (event) => {
if (typeof BlzCookieConsent !== 'undefined' && BlzCookieConsent.initialized && BlzCookieConsent.isPerformanceStorageAllowed() && !window.document.querySelector('script[data-optimizely]')) {
var script = document.createElement('script');
script.src = `https://cdn.optimizely.com/js/8304241110.js`;
Copy link
Contributor

Choose a reason for hiding this comment

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

🚨 issue (security): Found a hardcoded Optimizely project ID that could potentially be used to access the account

The Optimizely project ID '8304241110' appears to be hardcoded in the JavaScript. While this ID is often public, it's better to store it in a configuration file or environment variable to make it easier to manage across environments.

</script><script>var BlzCookieConsent = JSON.parse('{"host":".blizzard.com","cookieInfoUrlPattern":"/cookies/?$","onetrustScriptUrl":"https://cdn.cookielaw.org/scripttemplates/otSDKStub.js","onetrustDomainScript":"22011b0f-2c46-49a3-a7bf-5f98a4d4da65"}');</script><script src="https://static.playoverwatch.com/js/cookie-consent-filter-ed6098b4bf.js"></script><link rel="preload" as="script" crossorigin href="https://cdn.optimizely.com/js/8304241110.js"><link rel="preconnect" href="//logx.optimizely.com"><script>window.addEventListener('CookieConsentChange', (event) => {
if (typeof BlzCookieConsent !== 'undefined' && BlzCookieConsent.initialized && BlzCookieConsent.isPerformanceStorageAllowed() && !window.document.querySelector('script[data-optimizely]')) {
var script = document.createElement('script');
script.src = `https://cdn.optimizely.com/js/8304241110.js`;
Copy link
Contributor

Choose a reason for hiding this comment

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

🚨 issue (security): Found a hardcoded Optimizely project ID that could potentially be used to access the project configuration

While this may be intended for client-side use, it's recommended to load Optimizely IDs from configuration rather than hardcoding them to make project ID rotation easier and prevent potential misuse.

</script><script>var BlzCookieConsent = JSON.parse('{"host":".blizzard.com","cookieInfoUrlPattern":"/cookies/?$","onetrustScriptUrl":"https://cdn.cookielaw.org/scripttemplates/otSDKStub.js","onetrustDomainScript":"22011b0f-2c46-49a3-a7bf-5f98a4d4da65"}');</script><script src="https://static.playoverwatch.com/js/cookie-consent-filter-ed6098b4bf.js"></script><link rel="preload" as="script" crossorigin href="https://cdn.optimizely.com/js/8304241110.js"><link rel="preconnect" href="//logx.optimizely.com"><script>window.addEventListener('CookieConsentChange', (event) => {
if (typeof BlzCookieConsent !== 'undefined' && BlzCookieConsent.initialized && BlzCookieConsent.isPerformanceStorageAllowed() && !window.document.querySelector('script[data-optimizely]')) {
var script = document.createElement('script');
script.src = `https://cdn.optimizely.com/js/8304241110.js`;
Copy link
Contributor

Choose a reason for hiding this comment

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

🚨 issue (security): Found a hardcoded Optimizely project ID that could potentially be used to access the project configuration

While this appears to be a client-side Optimizely project ID, it's recommended to store such configuration values in environment variables or configuration files rather than hardcoding them in source code.

</script><script>var BlzCookieConsent = JSON.parse('{"host":".blizzard.com","cookieInfoUrlPattern":"/cookies/?$","onetrustScriptUrl":"https://cdn.cookielaw.org/scripttemplates/otSDKStub.js","onetrustDomainScript":"22011b0f-2c46-49a3-a7bf-5f98a4d4da65"}');</script><script src="https://static.playoverwatch.com/js/cookie-consent-filter-ed6098b4bf.js"></script><link rel="preload" as="script" crossorigin href="https://cdn.optimizely.com/js/8304241110.js"><link rel="preconnect" href="//logx.optimizely.com"><script>window.addEventListener('CookieConsentChange', (event) => {
if (typeof BlzCookieConsent !== 'undefined' && BlzCookieConsent.initialized && BlzCookieConsent.isPerformanceStorageAllowed() && !window.document.querySelector('script[data-optimizely]')) {
var script = document.createElement('script');
script.src = `https://cdn.optimizely.com/js/8304241110.js`;
Copy link
Contributor

Choose a reason for hiding this comment

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

🚨 issue (security): Found a potential Optimizely API key/project ID in the JavaScript code

The number '8304241110' appears to be an Optimizely project identifier. While this may be intended for client-side use, it's recommended to review if this should be exposed or if it provides access to sensitive Optimizely features.

@TeKrop TeKrop merged commit 20341ed into main Nov 10, 2024
3 checks passed
@TeKrop TeKrop deleted the feature/tests-refactoring branch November 10, 2024 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant