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

refactor(event_source): convert functional tests to unit tests #2506

Merged

Conversation

leandrodamascena
Copy link
Contributor

@leandrodamascena leandrodamascena commented Jun 20, 2023

Issue number: #509

Summary

Changes

This pull request aims to enhance the test structure and organization within the event_source_data_classes module. By breaking down the existing tests into smaller, more focused units, this refactor improves the maintainability and readability of the codebase. The test_data_class.py file had more than 2k LOC and it was becoming impossible to maintain it, so I divided it into small tests to make it easier to maintain.

I've also changed function tests to unit tests, which makes more sense for the type of testing we're doing. Just to explain a little more, these tests specifically test whether given an event source, Powertools can turn it into an object.

User experience

There is no change in the user experience.

Checklist

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

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

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.

@leandrodamascena leandrodamascena linked an issue Jun 20, 2023 that may be closed by this pull request
@leandrodamascena leandrodamascena changed the title ci(event_source): breaking down event_source_data_classes tests tests(event_source): breaking down event_source_data_classes tests Jun 20, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jun 20, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 🎉

Comparison is base (9042039) 97.20% compared to head (56dbb51) 97.21%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2506      +/-   ##
===========================================
+ Coverage    97.20%   97.21%   +0.01%     
===========================================
  Files          158      158              
  Lines         7358     7365       +7     
  Branches       534      537       +3     
===========================================
+ Hits          7152     7160       +8     
+ Misses         159      158       -1     
  Partials        47       47              
Impacted Files Coverage Δ
...wertools/utilities/data_classes/active_mq_event.py 100.00% <100.00%> (ø)
...a_powertools/utilities/data_classes/kafka_event.py 98.57% <100.00%> (+1.60%) ⬆️

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@heitorlessa heitorlessa changed the title tests(event_source): breaking down event_source_data_classes tests refactor(event_source): breaking down event_source_data_classes tests Jun 21, 2023
@heitorlessa heitorlessa added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 21, 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.

@heitorlessa
Copy link
Contributor

looking 👀

@heitorlessa
Copy link
Contributor

@leandrodamascena PR body can be improved - add a note about functional -> unit, before/after (functional -> unit change for a single test), etc.

Copy link
Contributor

@heitorlessa heitorlessa left a comment

Choose a reason for hiding this comment

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

I'm so so happy we're finally getting this tech debt done - THANK YOU.

Two major changes before merging:

  • We need a functional test for @event_source decorator
  • Split raw_event from parsed_event in every example, and assert whether parsed_event.<property> has the same data as the raw_event[<property>]

tests/unit/data_classes/test_api_gateway_proxy_event.py Outdated Show resolved Hide resolved
@leandrodamascena
Copy link
Contributor Author

@leandrodamascena PR body can be improved - add a note about functional -> unit, before/after (functional -> unit change for a single test), etc.

Can you check again please?

@boring-cyborg boring-cyborg bot added the tests label Jun 21, 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.

Copy link
Contributor

@heitorlessa heitorlessa left a comment

Choose a reason for hiding this comment

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

found a hidden bug in ActiveMQ implementation of message property when reviewing an older assertion it was doing.

We need to search for other uses of generators with next() in properties, as it'll lead to the same problem.

tests/unit/data_classes/test_active_mq_event.py Outdated Show resolved Hide resolved
@leandrodamascena leandrodamascena requested a review from a team as a code owner June 22, 2023 17:32
@boring-cyborg boring-cyborg bot added commons dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation event_handlers github-actions Pull requests that update Github_actions code labels Jun 23, 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.

4 similar comments
@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

⚠️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

⚠️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

⚠️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.

@leandrodamascena leandrodamascena force-pushed the techdebt/event_source_tests branch from 26ae39c to d8b2739 Compare June 23, 2023 16:05
heitorlessa
heitorlessa previously approved these changes Jun 23, 2023
Copy link
Contributor

@heitorlessa heitorlessa left a comment

Choose a reason for hiding this comment

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

🚀 ⛴️

@heitorlessa heitorlessa dismissed their stale review June 23, 2023 16:43

Mypy is failing

@heitorlessa
Copy link
Contributor

Just need to fix the typing for self._messages and records because they're being inferred as None, then assigned a generator later

@heitorlessa heitorlessa changed the title refactor(event_source): breaking down event_source_data_classes tests refactor(event_source): convert functional tests to unit tests Jun 23, 2023
@heitorlessa heitorlessa merged commit b1b835b into aws-powertools:develop Jun 23, 2023
rafaelgsr pushed a commit to rafaelgsr/aws-lambda-powertools-python that referenced this pull request Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commons dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement event_handlers github-actions Pull requests that update Github_actions code 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: Break down event_source_data_classes tests
3 participants