Пример #1
0
def api_get_games(machine_id):
    try:

        if not is_machine(machine_id):
            return str(
                generate_error_reply_JSON(
                    "machine with that id don't exists!"))

        return str(generate_list_of_games_reply_JSON(machine_id))

    except Exception as e:
        return str(generate_error_reply_JSON(str(e)))
Пример #2
0
def api_enter_game(machine_id, game_id):
    try:

        if not is_machine(machine_id):
            return str(
                generate_error_reply_JSON(
                    "machine with that id don't exists!"))

        enter_game(machine_id, game_id)

        return str(generate_success_reply_JSON())

    except Exception as e:
        return str(generate_error_reply_JSON(str(e)))
Пример #3
0
def api_register_card(card_serial_number):

    try:
        validation_result = validate_card_serial_number(card_serial_number)
        if validation_result is not None:
            return str(generate_error_reply_JSON(validation_result))

        new_card = Card(serial_number=card_serial_number)
        db.session.add(new_card)
        db.session.commit()

        return str(generate_success_reply_JSON())

    except Exception as e:
        return str(generate_error_reply_JSON(str(e)))
Пример #4
0
def api_spin(machine_id):
    try:

        if not is_machine(machine_id):
            return str(
                generate_error_reply_JSON(
                    "machine with that id don't exists!"))

        body = request.get_json(force=True)

        spin(machine_id, body['bet'], body['timestamp'])

        return str(generate_success_reply_JSON())

    except Exception as e:
        return str(generate_error_reply_JSON(str(e)))
Пример #5
0
def api_login_card_into_machine(machine_id, card_serial_number):
    try:

        if not is_machine(machine_id):
            return str(
                generate_error_reply_JSON(
                    "machine with that id don't exists!"))

        if not is_card(card_serial_number):
            return str(generate_error_reply_JSON("this card don't exists!"))

        card_login(machine_id, card_serial_number)

        return str(generate_success_reply_JSON())

    except Exception as e:
        return str(generate_error_reply_JSON(str(e)))
Пример #6
0
 def test_generate_error_reply_JSON(self):
     self.assertEqual(generate_error_reply_JSON("reply message"), '{"success": 0, "desc": "reply message"}')
     self.assertEqual(generate_error_reply_JSON(""), '{"success": 0, "desc": ""}')