Skip to content

refactor(feature_flags): Migrate function tests to unit tests for Feature Flags #3226

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

Conversation

ryanpudd
Copy link

@ryanpudd ryanpudd commented Oct 18, 2023

Issue number: #2060

Summary

Changes

A start at refactoring FeatureFlag tests. This change converts the existing tests to be Unit Tests rather than functional.

The change is primarily to ensure I'm on the right path with this change, follow up PRs will

  • refactor the fixture usage within this to suit a stub class better
  • remove/refactor function tests (once I have a better understanding of what is considered good functional coverage)

User experience

No change to the User Experience

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@ryanpudd ryanpudd requested a review from a team October 18, 2023 09:21
@boring-cyborg boring-cyborg bot added the tests label Oct 18, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 18, 2023

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@pull-request-size pull-request-size bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Oct 18, 2023
@leandrodamascena leandrodamascena changed the title refactor: Migrate function tests to unit tests for Feature Flags refactor(feature_flags): Migrate function tests to unit tests for Feature Flags Oct 18, 2023
@github-actions
Copy link
Contributor

⚠️Large PR detected⚠️

Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.

@github-actions
Copy link
Contributor

No related issues found. Please ensure there is an open issue related to this change to avoid significant delays or closure.

@github-actions github-actions bot added do-not-merge need-issue PRs that are missing related issues labels Oct 18, 2023
@github-actions
Copy link
Contributor

⚠️Large PR detected⚠️

Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.

@codecov-commenter
Copy link

codecov-commenter commented Oct 18, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (2f21fd9) 95.38% compared to head (c2eaf35) 95.39%.
Report is 9 commits behind head on develop.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3226   +/-   ##
========================================
  Coverage    95.38%   95.39%           
========================================
  Files          208      208           
  Lines         9618     9633   +15     
  Branches      1764     1766    +2     
========================================
+ Hits          9174     9189   +15     
  Misses         330      330           
  Partials       114      114           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leandrodamascena leandrodamascena linked an issue Oct 22, 2023 that may be closed by this pull request
6 tasks
@leandrodamascena leandrodamascena removed do-not-merge need-issue PRs that are missing related issues labels Oct 23, 2023
@leandrodamascena
Copy link
Contributor

Hey @ryanpudd! Thanks for sending this PR... Starting the review now.

Copy link
Member

@roger-zhangg roger-zhangg left a comment

Choose a reason for hiding this comment

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

Hey @ryanpudd a ton of thanks for taking your time to create these test cases. I was astonished by their coverage and quality. I left some comment here and we can discuss on these possible improvements. Thanks again for your time and work!


def test_flags_rule_does_not_match(mocker):
expected_value = True
mocked_app_config_schema = {
Copy link
Member

@roger-zhangg roger-zhangg Oct 31, 2023

Choose a reason for hiding this comment

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

This mocked_app_config_schema is used a lot in different test cases, I think it make sense to make it a fixture and reuse it across different test cases. like here

app_conf_fetcher.get_configuration()

# THEN raise ConfigurationStoreError error
assert "AWS AppConfig configuration" in str(err.value)
Copy link
Member

Choose a reason for hiding this comment

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

Is this still required after with pytest.raises(ConfigurationStoreError)



# check rule match for multiple of action types
def test_flags_conditions_rule_match_multiple_actions_multiple_rules_multiple_conditions(mocker):
Copy link
Member

Choose a reason for hiding this comment

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

This test case seems complicated. Do we need to have all 4 asserts in this single test case? I would suggest using @pytest.mark.parametriz like here to make this test case more explicit

assert toggle == expected_value_fourth_check


# check a case where the feature exists but the rule doesn't match so we revert to the default value of the feature
Copy link
Member

Choose a reason for hiding this comment

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

Is this a TODO here

assert toggle == expected_value


def test_flags_match_rule_with_key_in_value_action(mocker):
Copy link
Member

Choose a reason for hiding this comment

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

The following 4 test cases are pretty similar to me. Could we consider simplify these cases using @pytest.mark.parametrize like here



# Test not equals
def test_flags_not_equal_no_match(mocker):
Copy link
Member

Choose a reason for hiding this comment

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

The same as above, the following 14 test cases test_flag_(not_eq/gt/lt)_(no_match/match) are pretty similar to me. If we could simplify these test cases using @pytest.mark.parametrize this will make these test cases much simpler and easier to follow.

@heitorlessa heitorlessa added the need-customer-feedback Requires more customers feedback before making or revisiting a decision label Dec 6, 2023
Copy link

sonarqubecloud bot commented Dec 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 9 Code Smells

No Coverage information No Coverage information
4.8% 4.8% Duplication

Copy link
Contributor

github-actions bot commented Dec 6, 2023

⚠️Large PR detected⚠️

Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.

@heitorlessa
Copy link
Contributor

Closing as we haven't heard back after the review since Nov 2023, and we want to appreciate everyone's involved time equally; please feel free to reopen if that was missed by accident.

@heitorlessa heitorlessa closed this Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-customer-feedback Requires more customers feedback before making or revisiting a decision size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maintenance: Refactor Feature Flags
5 participants