Skip to content

Conversation

@stefanotroncaro
Copy link
Contributor

@stefanotroncaro stefanotroncaro commented Oct 10, 2025

Implemented factories to make test suite maintainable and scalable. Fixtures have been implemented for them, and current tests suite has been refactored to make use of these factory classes.

Client factory

Has a method to create a TestClient.

Optionally, an User can be passed to have them be logged in. This is essential for apps that need to test endpoints blocked behind authentication, as manually login the user on each test:

  • adds a lot of redundancy,
  • is brittle (prone to breaking if the authentication mechanism changes),
  • will struggle to deal with the limiter on the login endpoint as tests accumulate.

User factory

Has methods to create one user or many users at once. The created user/s can be configured in two ways:

  • With config objects, which can be instantiated with the .config property
  • With keyword arguments, which are internally passed to the constructor of the config object. This is provided for convenience, as it makes the syntax much cleaner

🚨 Issues

The .create_many creates all users by hitting the db once, but two bottlenecks currently exist:

  • Creating the password hashes, which could be solved by caching the results of security.get_password_hash
  • Creating the 2fas (if requested) requires hitting once per 2fa to be created, which could be solved by adding bulk creation methods to the repository/service

Both of these issues seemed to be outside the scope of this PR, as they are improvements to other parts of the boilerplate that could be worked on separately.

Proof

image

@stefanotroncaro stefanotroncaro marked this pull request as ready for review October 10, 2025 15:57
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