Commit cb5de71b authored by Sharad Heft's avatar Sharad Heft

Optionally create characters associated with auth.

parent af5578e3
......@@ -27,7 +27,17 @@ class TESTOAuth2Backend(ModelBackend):
)
if getattr(settings, 'TEST_OAUTH_CREATE_GROUPS', False):
self._do_create_groups(user, profile.get('groups', []))
self._do_create_groups(
user,
profile.get('groups', [])
)
if getattr(settings, 'TEST_OAUTH_CREATE_CHARACTERS', False):
self._do_create_characters(
user,
profile.get('characters', []),
profile.get('primary_character', None),
)
return user
......@@ -55,3 +65,23 @@ class TESTOAuth2Backend(ModelBackend):
user.is_staff = True
user.save()
@transaction.atomic
def _do_create_characters(self, user, characters, primary):
user.auth.characters.clear()
user.auth.primary_character = None
for c in characters:
character, _ = Group.objects.update_or_create(
id=c['id'],
defaults={
'name': c['name'],
'alliance_id': c['alliance']['id'],
'corporation_id': c['corporation']['id']
}
)
user.auth.characters.add(character)
user.auth.primary_character_id = primary['id']
user.auth.save()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment