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

Refactored repository services tests to use fixtures #795

Merged
merged 1 commit into from
Oct 17, 2024

Conversation

michelletran-codecov
Copy link
Contributor

@michelletran-codecov michelletran-codecov commented Oct 17, 2024

This helps reduce database key conflicts by reusing existing objects for tests

This refactor was pulled out of #729 to make changes more manageable. It solved a problem where recreating the objects had conflicts when I switched to Django models (duplicate key errors).

This is also significantly easier to review if you set "hide whitespace" to view the diff because I removed test classes.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

This helps reduce database key conflicts by reusing existing objects for tests
@codecov-qa
Copy link

codecov-qa bot commented Oct 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.00%. Comparing base (c46b6c7) to head (a85f108).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #795      +/-   ##
==========================================
- Coverage   98.01%   98.00%   -0.01%     
==========================================
  Files         443      443              
  Lines       36615    36566      -49     
==========================================
- Hits        35887    35838      -49     
  Misses        728      728              
Flag Coverage Δ
integration 98.00% <100.00%> (-0.01%) ⬇️
unit 98.00% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 95.87% <ø> (ø)
OutsideTasks 97.99% <100.00%> (-0.01%) ⬇️
Files with missing lines Coverage Δ
services/tests/test_repository_service.py 99.77% <100.00%> (-0.02%) ⬇️

@codecov-notifications
Copy link

codecov-notifications bot commented Oct 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #795      +/-   ##
==========================================
- Coverage   98.01%   98.00%   -0.01%     
==========================================
  Files         443      443              
  Lines       36615    36566      -49     
==========================================
- Hits        35887    35838      -49     
  Misses        728      728              
Flag Coverage Δ
integration 98.00% <100.00%> (-0.01%) ⬇️
unit 98.00% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 95.87% <ø> (ø)
OutsideTasks 97.99% <100.00%> (-0.01%) ⬇️
Files with missing lines Coverage Δ
services/tests/test_repository_service.py 99.77% <100.00%> (-0.02%) ⬇️

Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.00%. Comparing base (c46b6c7) to head (a85f108).

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #795      +/-   ##
==========================================
- Coverage   98.01%   98.00%   -0.01%     
==========================================
  Files         443      443              
  Lines       36615    36566      -49     
==========================================
- Hits        35887    35838      -49     
  Misses        728      728              
Flag Coverage Δ
integration 98.00% <100.00%> (-0.01%) ⬇️
unit 98.00% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 95.87% <ø> (ø)
OutsideTasks 97.99% <100.00%> (-0.01%) ⬇️
Files Coverage Δ
services/tests/test_repository_service.py 99.77% <100.00%> (-0.02%) ⬇️

@michelletran-codecov michelletran-codecov marked this pull request as ready for review October 17, 2024 16:20
@michelletran-codecov michelletran-codecov requested a review from a team October 17, 2024 16:20
@adrian-codecov
Copy link
Contributor

Ty for the whitespace suggestion @michelletran-codecov, it did make things easier to compare left <> right

Copy link
Contributor

@joseph-sentry joseph-sentry left a comment

Choose a reason for hiding this comment

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

looks good for the most part, just added a couple comments where i noticed some differences with the original tests

)
dbsession.add(commit)
dbsession.add(compared_to_commit)
dbsession.flush()

commit.pullid = "123"
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was extracted from line 1615. If I leave it in the factory create, it will try to link a pull object and was failing. Since we just needed it to be not null but not actually exist, it was just easier to set it outside the factory call. I don't know why it started failing after I switched to using Django to create the tables 🤷

@@ -2076,6 +2031,10 @@ def test_fetch_commit_yaml_and_possibly_store_commit_yaml_invalid_commit_yaml(
mock_configuration.set_params({"site": {"comment": {"behavior": "new"}}})
commit = CommitFactory.create(
repository__owner__yaml={"coverage": {"precision": 2}},
# User needs to be less than PATCH_CENTRIC_DEFAULT_TIME_START
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, it's a remnant from #729 . Basically, the new Django models adds a default time of now (SQLAlchemy models will just have no default time for the owner object). If the owner is created after the 'PATCH_CENTRIC_DEFAULT_TIME_START', the default owner YAML is actually different and messed up with the tests. So, setting the timestamp is to preserve the test functionality of using the pre-patch_centric yaml behaviour. This doesn't really do anything bad right now, and will be useful later when I start creating the tables with Django later.

@michelletran-codecov michelletran-codecov added this pull request to the merge queue Oct 17, 2024
Merged via the queue into main with commit 4e88e28 Oct 17, 2024
25 of 27 checks passed
@michelletran-codecov michelletran-codecov deleted the make_tests_use_fixtures branch October 17, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants