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 tests, use db migrations, correct session, rollback automatically #12

Merged
merged 8 commits into from
May 25, 2023

Conversation

omar-selo
Copy link
Collaborator

@omar-selo omar-selo commented May 23, 2023

Refactor how tests work. Main changes are:

  • Fix where api was creating a db session instead of using get_db
  • Seed inside test functions only needed data
  • Rollback automatically in each test function (by creating an overarching transaction and not commiting it)
  • Apply existing alembic migrations on test database to get a consistent view with test db including expected data
  • Avoid use of mocker.patch to replace db engine to avoid undefined behavior (while running mid test I don't know what switching engine could do)

@omar-selo omar-selo requested a review from nadzyah May 23, 2023 11:46
Copy link
Collaborator

@nadzyah nadzyah left a comment

Choose a reason for hiding this comment

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

Thanks for refactoring tests! There're just some changes and questions that are not clear for me.

backend/tests/test_snap_manager.py Show resolved Hide resolved
backend/tests/test_snap_manager.py Show resolved Hide resolved
backend/tests/test_repository.py Show resolved Hide resolved
backend/tests/test_repository.py Outdated Show resolved Hide resolved
backend/tests/test_repository.py Outdated Show resolved Hide resolved
backend/tests/conftest.py Show resolved Hide resolved
@omar-selo omar-selo requested a review from nadzyah May 25, 2023 07:25
backend/tests/test_repository.py Outdated Show resolved Hide resolved
@omar-selo omar-selo requested a review from nadzyah May 25, 2023 09:23
Copy link
Collaborator

@nadzyah nadzyah left a comment

Choose a reason for hiding this comment

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

All my questions were resolved. Thanks for your contribution!

@omar-selo omar-selo merged commit a4a140d into main May 25, 2023
@omar-selo omar-selo deleted the refactor-tests branch May 25, 2023 14:20
mz2 pushed a commit that referenced this pull request May 30, 2023
…cally (#12)

* Refactor tests, use db migrations, correct session, rollback automatically

* Remove unnecessary test

* Remove unnecessary package

* Fix rollback to be global

* Remove unused functions and improve a test case

* Return accidentally deleted test case

* Bring back a couple of tests and fix one

* Apply small review suggestions
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.

2 participants