Esempio n. 1
0
    def test_update_updates_game(self):
        update_url = "/games/{}".format(self.game.get_id())
        game_number = self.game.get_id() * 100
        name = get_incremental_game_name(game_number)
        description = get_incremental_game_description(game_number)
        match_size = self.game.get_match_size()
        game_data = {"name": name, "description": description, "is_active": False}
        response = self.put(update_url, data=game_data)
        self.assertEqual(200, response.status_code)
        game = json.loads(response.data)
        self.assertIsNotNone(game.get("id"))
        self.assertIsNotNone(game.get("date_created"))
        self.assertIsNotNone(game.get("date_modified"))
        self.assertEqual(name, game.get("name"))
        self.assertEqual(description, game.get("description"))
        self.assertEqual(match_size, game.get("match_size"))
        self.assertEqual(False, game.get("is_active"))

        # Make sure the game was actually updated in the database
        saved_game = GamesService.get_instance().get(int(game.get("id")))
        self.assertEqual(saved_game.get_id(), game.get("id"))
        self.assertEqual(Game.dump_datetime(saved_game.get_date_created()), game.get("date_created"))
        self.assertEqual(Game.dump_datetime(saved_game.get_date_modified()), game.get("date_modified"))
        self.assertEqual(saved_game.get_name(), game.get("name"))
        self.assertEqual(saved_game.get_description(), game.get("description"))
        self.assertEqual(saved_game.get_match_size(), game.get("match_size"))
        self.assertEqual(saved_game.get_is_active(), game.get("is_active"))
Esempio n. 2
0
    def test_create_returns_created_status(self):
        game_id = self.NUM_GAMES + 1
        create_url = "/games"
        name = get_incremental_game_name(game_id)
        description = get_incremental_game_description(game_id)
        game_data = {"name": name, "description": description, "match_size": 2}
        response = self.post(create_url, data=game_data)
        self.assertEqual(201, response.status_code)
        game = json.loads(response.data)
        self.assertIsNotNone(game.get("id"))
        self.assertIsNotNone(game.get("date_created"))
        self.assertIsNotNone(game.get("date_modified"))
        self.assertEqual(name, game.get("name"))
        self.assertEqual(description, game.get("description"))
        self.assertEqual(2, game.get("match_size"))
        self.assertEqual(True, game.get("is_active"))

        # Make sure the game was actually saved to the database
        saved_game = GamesService.get_instance().get(int(game.get("id")))
        self.assertEqual(saved_game.get_id(), game.get("id"))
        self.assertEqual(Game.dump_datetime(saved_game.get_date_created()), game.get("date_created"))
        self.assertEqual(Game.dump_datetime(saved_game.get_date_modified()), game.get("date_modified"))
        self.assertEqual(saved_game.get_name(), game.get("name"))
        self.assertEqual(saved_game.get_description(), game.get("description"))
        self.assertEqual(saved_game.get_match_size(), game.get("match_size"))
        self.assertEqual(saved_game.get_is_active(), game.get("is_active"))
Esempio n. 3
0
    def test_delete_deletes_game(self):
        delete_url = "/games/{}".format(self.game.get_id())
        self.assertEqual(True, self.game.get_is_active())
        response = self.delete(delete_url)
        self.assertEqual(200, response.status_code)
        game = json.loads(response.data)
        self.assertIsNotNone(game.get("id"))
        self.assertIsNotNone(game.get("date_created"))
        self.assertIsNotNone(game.get("date_modified"))
        self.assertIsNotNone(game.get("name"))
        self.assertIsNotNone(game.get("description"))
        self.assertIsNotNone(game.get("match_size"))
        self.assertEqual(False, game.get("is_active"))

        # Make sure the game was actually updated in the database
        saved_game = GamesService.get_instance().get(int(game.get("id")))
        self.assertEqual(saved_game.get_id(), game.get("id"))
        self.assertEqual(Game.dump_datetime(saved_game.get_date_created()), game.get("date_created"))
        self.assertEqual(Game.dump_datetime(saved_game.get_date_modified()), game.get("date_modified"))
        self.assertEqual(saved_game.get_name(), game.get("name"))
        self.assertEqual(saved_game.get_description(), game.get("description"))
        self.assertEqual(saved_game.get_match_size(), game.get("match_size"))
        self.assertEqual(saved_game.get_is_active(), game.get("is_active"))
Esempio n. 4
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
Esempio n. 5
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())