Skip to content

Commit

Permalink
tests simplified and moved in the player method
Browse files Browse the repository at this point in the history
  • Loading branch information
padawin committed Apr 7, 2016
1 parent 5247a1b commit 76d1ee5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
15 changes: 1 addition & 14 deletions core/commands/createPlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,7 @@ def run(self):

(login, genderId, speciesId) = self._args

if len(player.model.loadBy({'login': login})):
raise player.exception(_('ERROR_SIGNUP_LOGIN_ALREADY_USED'))

genders = [str(g['id_gender']) for g in gender.model.loadAll()]
if str(genderId) not in genders:
raise player.exception(_('ERROR_SIGNUP_INVALID_GENDER'))

sps = [str(s['id_species']) for s in species.model.getSpecies()]
if str(speciesId) not in sps:
raise player.exception(_('ERROR_SIGNUP_INVALID_SPECIES'))

self._player.createNewPlayer(
login, speciesId, genderId
)
self._player.createNewPlayer(login, speciesId, genderId)

saved_game.saved_game.cleanSavedGame(self._savedGameId)
saved_game.saved_game.updateSavedGame(
Expand Down
11 changes: 10 additions & 1 deletion models/player.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import core.exception
from models import character
from models import character, gender, species
from models.Model import Model
import datetime
import json
Expand Down Expand Up @@ -28,6 +28,15 @@ def connect(self, login):
return True

def createNewPlayer(self, login, speciesId, genderId):
if len(model.loadBy({'login': login})):
raise exception(_('ERROR_SIGNUP_LOGIN_ALREADY_USED'))

if gender.model.loadById(genderId) == {}:
raise exception(_('ERROR_SIGNUP_INVALID_GENDER'))

if species.model.loadById(speciesId) == {}:
raise exception(_('ERROR_SIGNUP_INVALID_SPECIES'))

m = {
'login': login,
'name': login,
Expand Down

0 comments on commit 76d1ee5

Please sign in to comment.