Skip to content

Commit

Permalink
Fix test_employer_organizations flakiness
Browse files Browse the repository at this point in the history
Can reproduce with `--randomly-seed=3901977061`.

```
E           django.db.utils.IntegrityError: duplicate key value violates unique constraint "unique_ddets_per_department"
E           DETAIL:  Key (kind, department)=(DDETS IAE, 972) already exists.
```
  • Loading branch information
francoisfreitag committed Jun 20, 2024
1 parent bf9c59f commit 82ed9ea
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions tests/users/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1268,18 +1268,27 @@ def test_is_prescriber_with_authorized_org(user_active, membership_active, organ


@pytest.mark.parametrize(
"UserFactory,MembershipFactory,relation_name",
"UserFactory,MembershipFactory,relation_name, factories_extra",
[
(EmployerFactory, CompanyMembershipFactory, "company"),
(LaborInspectorFactory, InstitutionMembershipFactory, "institution"),
(PrescriberFactory, PrescriberMembershipFactory, "organization"),
(EmployerFactory, CompanyMembershipFactory, "company", [{}] * 3),
(
LaborInspectorFactory,
InstitutionMembershipFactory,
"institution",
[
{"institution__department": "01"},
{"institution__department": "02"},
{"institution__department": "03"},
],
),
(PrescriberFactory, PrescriberMembershipFactory, "organization", [{}] * 3),
],
)
def test_employer_organizations(UserFactory, MembershipFactory, relation_name):
def test_employer_organizations(UserFactory, MembershipFactory, relation_name, factories_extra):
user = UserFactory()
first_membership = MembershipFactory(is_active=True, is_admin=False, user=user)
admin_membership = MembershipFactory(is_active=True, is_admin=True, user=user)
MembershipFactory(is_active=True, is_admin=False, user=user)
first_membership = MembershipFactory(is_active=True, is_admin=False, user=user, **factories_extra[0])
admin_membership = MembershipFactory(is_active=True, is_admin=True, user=user, **factories_extra[1])
MembershipFactory(is_active=True, is_admin=False, user=user, **factories_extra[2])

assert len(user.organizations) == 3

Expand Down

0 comments on commit 82ed9ea

Please sign in to comment.