Exemple #1
0
    def insert_dummy_games(self):
        game = None
        large_game = None
        for game_index in range(1, self.NUM_GAMES + 1):
            name = get_incremental_game_name(game_index)
            description = get_incremental_game_description(game_index)
            if game_index % 2 == 0:
                match_size = 4
                large_game = Game(name, description, match_size)
                large_game.save()
            else:
                match_size = 2
                game = Game(name, description, match_size)
                game.save()

        self.game = game
        self.large_game = large_game
Exemple #2
0
def create():
    """
    Request:
    {
        "name": "name",
        "description": "description",
        "match_size": "match_size",
        "definition_filler_count": "definition_filler_count"
    }

    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": {
            "name": "value passed in. empty string if missing",
            "description": "value passed in. empty string if missing",
            "match_size": "value passed in. empty string if missing",
            "definition_filler_count": "value passed in. empty string if missing"
        }
    }

    Response [422] (save failure):
    {
        "errors": {
            "IntegrityError": [
                "Reason saving to the db failed, such as name uniqueness"
            ]
        },
        "inputs": {
            "name": "value passed in. empty string if missing",
            "description": "value passed in. empty string if missing",
            "match_size": "value passed in. empty string if missing",
            "definition_filler_count": "value passed in. empty string if missing"
        }
    }

    Response [200] (success):
    {
        "id": "current value",
        "date_created": "current value",
        "date_modified": "current value",
        "name": "current value",
        "description": "current value",
        "match_size": "current value",
        "definition_filler_count": "current value",
        "is_active": "current value"
    }
    """
    # Get the input validator
    inputs = CreateInputs(get_inputs())

    # Verify the game creation inputs
    if inputs.validate_on_submit():

        game = Game(
            inputs.name.data, inputs.description.data, inputs.match_size.data, inputs.definition_filler_count.data
        )
        try:
            game.save()
            return render_view('games/show', 201, game=game.serialized)
        except Exception as e:
            return render_view('422', 422, errors={e.__class__.__name__: [e.message]}, inputs=inputs.serialized())

    return render_view('422', 422, errors=inputs.errors, inputs=inputs.serialized())