Following up #757 - Fixed remaining non-idempotent tests #758
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Following up #757 : this PRs fixed the remaining non-idempotent unit tests in the repository.
Test that depend on access permission:
Reason: The test first asserts that guest login is disabled in default state, and then enables guest login. In the second execution, the assertion will fail since guest login is globally enabled after the first test run.
Fix: Disable guest login before finishing test execution.
Test that depend on default theme resource:
Reason: The test first asserts that the main color is (by default)
#ffffff
, but later changed it to#ff0000
. It does not reset it back to#ffffff
in the end, so the assertion will fail in the second test execution.Fix: Reset main color to
#ffffff
at the end of the test.Tests that creates users with fixed usernames:
Reason: Similarly to previous discussion of
TestUserResource#testTotp
in Fixed non-idempotent unit tests #757 , the test creates a users with specific names without deleting them in the end. Therefore,HTTP 400 Bad Request
errors will occur on creating the users with the same names in the second executions, since the users already exist in the database.Fix: Delete the created users at the end of the tests.
Tests that depend on the inherently non-idempotent
POST
method:Reason: Similarly to previous discussion of
TestAppResource#TestInbox
in #757 , these tests initially get specific configurations and asserts they're in default state. However, the non-revertiblePOST
method changes these configurations, and there's no trivial way to restore this configurations to default. Hence, assertions of default configurations shall only be made in the first run of the test.Fix: Add static flags to ensure that assertions with respect to default configurations are only executed in the first test execution.