Fix fixtures

This commit is contained in:
zandercymatics 2024-04-30 12:35:30 -06:00
parent 74978ba5ba
commit 9119339203
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7

View file

@ -196,12 +196,12 @@ class UserFixture:
}, },
] ]
def load_users(cls, users, group_name): def load_users(cls, users, group_name, set_users_superusers=False):
logger.info(f"Going to load {len(users)} users in group {group_name}") logger.info(f"Going to load {len(users)} users in group {group_name}")
for user_data in users: for user_data in users:
try: try:
user, _ = User.objects.get_or_create(username=user_data["username"]) user, _ = User.objects.get_or_create(username=user_data["username"])
user.is_superuser = False user.is_superuser = set_users_superusers
user.first_name = user_data["first_name"] user.first_name = user_data["first_name"]
user.last_name = user_data["last_name"] user.last_name = user_data["last_name"]
if "email" in user_data: if "email" in user_data:
@ -229,5 +229,5 @@ class UserFixture:
# steps now do not need to close/reopen a db connection, # steps now do not need to close/reopen a db connection,
# instead they share one. # instead they share one.
with transaction.atomic(): with transaction.atomic():
cls.load_users(cls, cls.ADMINS, "full_access_group") cls.load_users(cls, cls.ADMINS, "full_access_group", set_users_superusers=True)
cls.load_users(cls, cls.STAFF, "cisa_analysts_group") cls.load_users(cls, cls.STAFF, "cisa_analysts_group")