🐛(backend) fix flaky test with team access #646
Faker sometimes creates users whose name starts with "Ms." or "Mr." The implemented test code computed the order without handling these cases and failed.
This commit is contained in:
@@ -17,6 +17,7 @@ and this project adheres to
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- 🐛(backend) fix flaky test with team access #646
|
||||||
- 🧑💻(dimail) remove 'NoneType: None' log in debug mode
|
- 🧑💻(dimail) remove 'NoneType: None' log in debug mode
|
||||||
- 🐛(frontend) fix flaky e2e test #636
|
- 🐛(frontend) fix flaky e2e test #636
|
||||||
- 🐛(frontend) fix disable mailbox button display #631
|
- 🐛(frontend) fix disable mailbox button display #631
|
||||||
|
|||||||
@@ -338,14 +338,19 @@ def test_api_team_accesses_list_authenticated_ordering():
|
|||||||
def test_api_team_accesses_list_authenticated_ordering_user(ordering_field):
|
def test_api_team_accesses_list_authenticated_ordering_user(ordering_field):
|
||||||
"""Team accesses can be ordered by user's fields."""
|
"""Team accesses can be ordered by user's fields."""
|
||||||
|
|
||||||
user = factories.UserFactory()
|
john = factories.UserFactory(email="john.doe@example.com", name="John Doe")
|
||||||
team = factories.TeamFactory()
|
team = factories.TeamFactory()
|
||||||
models.TeamAccess.objects.create(team=team, user=user)
|
models.TeamAccess.objects.create(team=team, user=john)
|
||||||
|
|
||||||
# create 20 new team members
|
# create new team members
|
||||||
for _ in range(20):
|
dave = factories.UserFactory(email="bowbow@example.com", name="David Bowman")
|
||||||
extra_user = factories.UserFactory()
|
nicole = factories.UserFactory(
|
||||||
factories.TeamAccessFactory(team=team, user=extra_user)
|
email="nicole_foole@example.com", name="Nicole Foole"
|
||||||
|
)
|
||||||
|
frank = factories.UserFactory(email="frank_poole@example.com", name="Frank Poole")
|
||||||
|
mary = factories.UserFactory(email="mary_pol@example.com", name="Mary Pol")
|
||||||
|
for user in (dave, nicole, frank, mary):
|
||||||
|
factories.TeamAccessFactory(team=team, user=user)
|
||||||
|
|
||||||
client = APIClient()
|
client = APIClient()
|
||||||
client.force_login(user)
|
client.force_login(user)
|
||||||
@@ -354,14 +359,11 @@ def test_api_team_accesses_list_authenticated_ordering_user(ordering_field):
|
|||||||
f"/api/v1.0/teams/{team.id!s}/accesses/?ordering=user__{ordering_field}",
|
f"/api/v1.0/teams/{team.id!s}/accesses/?ordering=user__{ordering_field}",
|
||||||
)
|
)
|
||||||
assert response.status_code == HTTP_200_OK
|
assert response.status_code == HTTP_200_OK
|
||||||
assert response.json()["count"] == 21
|
assert response.json()["count"] == 5
|
||||||
|
assert [access["user"]["name"] for access in response.json()["results"]] == [
|
||||||
def normalize(x):
|
dave.name,
|
||||||
"""Mimic Django order_by, which is case-insensitive and space-insensitive"""
|
frank.name,
|
||||||
return x.casefold().replace(" ", "")
|
john.name,
|
||||||
|
mary.name,
|
||||||
results = [
|
nicole.name,
|
||||||
team_access["user"][ordering_field]
|
|
||||||
for team_access in response.json()["results"]
|
|
||||||
]
|
]
|
||||||
assert sorted(results, key=normalize) == results
|
|
||||||
|
|||||||
Reference in New Issue
Block a user