Changes charcreateview to use new typeclass create() method instead.
This commit is contained in:
parent
4f6b8f323c
commit
659b264160
2 changed files with 25 additions and 23 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
from django.test import Client
|
from django.test import Client, override_settings
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from evennia.utils.test_resources import EvenniaTest
|
from evennia.utils.test_resources import EvenniaTest
|
||||||
|
|
||||||
|
|
@ -97,7 +97,29 @@ class CharacterCreateView(EvenniaWebTest):
|
||||||
url_name = 'character-create'
|
url_name = 'character-create'
|
||||||
unauthenticated_response = 302
|
unauthenticated_response = 302
|
||||||
|
|
||||||
def test_valid_access(self):
|
@override_settings(MULTISESSION_MODE=0)
|
||||||
|
def test_valid_access_multisession_0(self):
|
||||||
|
"Account1 with no characters should be able to create a new one"
|
||||||
|
self.account.db._playable_characters = []
|
||||||
|
|
||||||
|
# Login account
|
||||||
|
self.login()
|
||||||
|
|
||||||
|
# Post data for a new character
|
||||||
|
data = {
|
||||||
|
'db_key': 'gannon',
|
||||||
|
'desc': 'Some dude.'
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.post(reverse(self.url_name), data=data, follow=True)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# Make sure the character was actually created
|
||||||
|
self.assertTrue(len(self.account.db._playable_characters) == 1, 'Account only has the following characters attributed to it: %s' % self.account.db._playable_characters)
|
||||||
|
|
||||||
|
@override_settings(MULTISESSION_MODE=2)
|
||||||
|
@override_settings(MAX_NR_CHARACTERS=10)
|
||||||
|
def test_valid_access_multisession_2(self):
|
||||||
"Account1 should be able to create a new character"
|
"Account1 should be able to create a new character"
|
||||||
# Login account
|
# Login account
|
||||||
self.login()
|
self.login()
|
||||||
|
|
|
||||||
|
|
@ -363,28 +363,8 @@ class CharacterCreateView(CharacterMixin, ObjectCreateView):
|
||||||
description = self.attributes.pop('desc')
|
description = self.attributes.pop('desc')
|
||||||
|
|
||||||
# Create a character
|
# Create a character
|
||||||
permissions = settings.PERMISSION_ACCOUNT_DEFAULT
|
|
||||||
typeclass = self.model
|
|
||||||
default_home = ObjectDB.objects.get_id(settings.DEFAULT_HOME)
|
|
||||||
|
|
||||||
from evennia.utils import create
|
|
||||||
try:
|
try:
|
||||||
character = create.create_object(typeclass, key=charname, home=default_home, permissions=permissions)
|
character, errors = self.model.create(charname, account, description=description)
|
||||||
# set playable character list
|
|
||||||
account.db._playable_characters.append(character)
|
|
||||||
|
|
||||||
# allow only the character itself and the account to puppet this character (and Developers).
|
|
||||||
character.locks.add("puppet:id(%i) or pid(%i) or perm(Developer) or pperm(Developer)" %
|
|
||||||
(character.id, account.id))
|
|
||||||
|
|
||||||
# If no description is set, set a default description
|
|
||||||
if not description:
|
|
||||||
character.db.desc = "This is a character."
|
|
||||||
else:
|
|
||||||
character.db.desc = description
|
|
||||||
|
|
||||||
# We need to set this to have @ic auto-connect to this character
|
|
||||||
account.db._last_puppet = character
|
|
||||||
|
|
||||||
# Assign attributes from form
|
# Assign attributes from form
|
||||||
[setattr(character.db, key, value) for key,value in self.attributes.items()]
|
[setattr(character.db, key, value) for key,value in self.attributes.items()]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue