def insert_dummy_players(self): player = None for player_index in range(1, self.NUM_PLAYERS + 1): username = get_incremental_username(player_index) email = get_incremental_email(player_index) avatar_url = get_incremental_avatar_url(player_index) if player_index % 2 == 0 else None player = Player(username, self.PLAYER_PASSWORD, email, avatar_url) player.save() self.player = player
def create(): """ Request: { "username": "******", "password": "******", "confirm": "confirm", "email": "email", "avatar_url": "avatar_url" } Response [422] (invalid parameters): { "errors": { "name of parameter that failed validation": [ "Reason for validation failure" ], "name of another parameter that failed validation": [ "Reason for validation failure" ], }, "inputs": { "username": "******", "password": NULL, "confirm": NULL, "email": "value passed in. empty string if missing", "avatar_url": "value passed in. empty string if missing" } } Response [422] (save failure): { "errors": { "IntegrityError": [ "Reason saving to the db failed, such as username/email uniqueness" ] }, "inputs": { "username": "******", "password": NULL, "confirm": NULL, "email": "value passed in. empty string if missing", "avatar_url": "value passed in. empty string if missing" } } Response [200] (success): { "id": "current value", "date_created": "current value", "date_modified": "current value", "username": "******", "email": "current value", "avatar_url": "current value", "is_active": "current value", "auth_token": "current value" } """ # Get the input validator inputs = CreateInputs(get_inputs()) # Verify the player creation inputs if inputs.validate_on_submit(): avatar_url = inputs.avatar_url.data if inputs.avatar_url.data else None player = Player(inputs.username.data, inputs.password.data, inputs.email.data, avatar_url) try: player.save() player_data = dict(player.serialized.items() + {'auth_token': player.get_auth_token()}.items()) return render_view('players/show', 201, player=player_data) except Exception as e: return render_view('422', 422, errors={e.__class__.__name__: [e.message]}, inputs=inputs.obfuscated()) return render_view('422', 422, errors=inputs.errors, inputs=inputs.obfuscated())