Example #1
0
def test_add_pokemon_to_team():
    uow = FakeUnitOfWork()

    messagebus.handle(commands.AddTeam('My team'), uow)
    messagebus.handle(commands.AddPokemonToTeam('My team',
                                                'Spark',
                                                'Pikachu',
                                                lvl=20,
                                                move_names=['Thunder Shock']),
                      uow=uow)
    assert len(uow.teams.get('My team').pokemons) == 1
Example #2
0
def add_pokemon():
    cmd = commands.AddPokemonToTeam(
        request.json['team_name'],
        request.json['nickname'],
        request.json['species'],
        request.json['level'],
        request.json['moves'],
    )
    uow = unit_of_work.UnitOfWork()
    messagebus.handle(cmd, uow)
    return jsonify({'status': 'OK'}), 200
Example #3
0
def test_opponent_can_choose_first_next_turn_move():
    uow = FakeUnitOfWork()

    battle_ref = create_a_battle(uow)

    messagebus.handle(
        commands.RegisterUseMove(battle_ref, 'opponent', 'Bubble'), uow)

    assert user_events.TurnReady(battle_ref) not in uow.user_messagebus.events

    messagebus.handle(
        commands.RegisterUseMove(battle_ref, 'host', 'Thunder Shock'), uow)

    assert user_events.TurnReady(battle_ref) in uow.user_messagebus.events
Example #4
0
def join_battle():
    cmd = commands.JoinBattle(
        request.json['battle_ref'],
        request.json['team_name'],
    )
    uow = unit_of_work.UnitOfWork()
    battle_ref = messagebus.handle(cmd, uow)
    return jsonify({'status': 'OK'}), 200
Example #5
0
def register_a_pokemon_change():
    cmd = commands.RegisterChangePokemon(
        request.json['battle_ref'],
        request.json['player'],
        request.json['pokemon_nickname'],
    )
    uow = unit_of_work.UnitOfWork()
    battle_ref = messagebus.handle(cmd, uow)
    return jsonify({'status': 'OK'}), 200
Example #6
0
def register_a_move():
    cmd = commands.RegisterUseMove(
        request.json['battle_ref'],
        request.json['player'],
        request.json['move_name'],
    )
    uow = unit_of_work.UnitOfWork()
    battle_ref = messagebus.handle(cmd, uow)
    return jsonify({'status': 'OK'}), 200
Example #7
0
def test_a_battle_turn_is_successfully_complete():
    uow = FakeUnitOfWork()

    battle_ref = create_a_battle(uow)

    messagebus.handle(
        commands.RegisterUseMove(battle_ref, 'host', 'Thunder Shock'), uow)
    messagebus.handle(
        commands.RegisterUseMove(battle_ref, 'opponent', 'Bubble'), uow)

    battle = uow.battles.get(battle_ref)

    expected_events = [
        user_events.BattleReady(battle_ref),
        user_events.PokemonUsedMove(battle_ref, 'Pikachu', 'Thunder Shock', 8),
        user_events.PokemonUsedMove(battle_ref, 'Squirtle', 'Bubble', 13),
        user_events.TurnReady(battle_ref),
    ]

    assert uow.user_messagebus.events == expected_events
Example #8
0
def host_battle():
    cmd = commands.HostBattle(request.json['team_name'], )
    uow = unit_of_work.UnitOfWork()
    battle_ref = messagebus.handle(cmd, uow)
    return jsonify({'battle_ref': battle_ref}), 201
Example #9
0
def add_team():
    cmd = commands.AddTeam(request.json['name'])
    uow = unit_of_work.UnitOfWork()
    messagebus.handle(cmd, uow)
    return jsonify({'status': 'OK'}), 201
Example #10
0
def create_a_battle(uow):
    messagebus.handle(commands.AddTeam('Host team'), uow)
    messagebus.handle(commands.AddTeam('Opponent team'), uow)

    messagebus.handle(commands.AddPokemonToTeam('Host team',
                                                'Spark',
                                                'Pikachu',
                                                lvl=20,
                                                move_names=['Thunder Shock']),
                      uow=uow)
    messagebus.handle(commands.AddPokemonToTeam('Opponent team',
                                                'Bubble',
                                                'Squirtle',
                                                lvl=20,
                                                move_names=['Bubble']),
                      uow=uow)

    battle_ref = messagebus.handle(commands.HostBattle('Host team'), uow)

    messagebus.handle(commands.JoinBattle(battle_ref, 'Opponent team'), uow)

    return battle_ref
Example #11
0
def test_add_team():
    uow = FakeUnitOfWork()

    messagebus.handle(commands.AddTeam('My team'), uow)
    assert uow.teams.get('My team') is not None
    assert uow.commited
Example #12
0
def test_can_change_active_pokemon():
    uow = FakeUnitOfWork()

    messagebus.handle(commands.AddTeam('Host team'), uow)
    messagebus.handle(commands.AddTeam('Opponent team'), uow)

    messagebus.handle(commands.AddPokemonToTeam('Host team',
                                                'Spark',
                                                'Pikachu',
                                                lvl=20,
                                                move_names=['Flamethrower']),
                      uow=uow)
    messagebus.handle(commands.AddPokemonToTeam('Host team',
                                                'Flame',
                                                'Ninetales',
                                                lvl=20,
                                                move_names=['Flamethrower']),
                      uow=uow)
    messagebus.handle(commands.AddPokemonToTeam('Opponent team',
                                                'Bubble',
                                                'Squirtle',
                                                lvl=20,
                                                move_names=['Bubble']),
                      uow=uow)

    battle_ref = messagebus.handle(commands.HostBattle('Host team'), uow)

    messagebus.handle(commands.JoinBattle(battle_ref, 'Opponent team'), uow)

    messagebus.handle(
        commands.RegisterChangePokemon(battle_ref, 'host', 'Flame'), uow)
    messagebus.handle(
        commands.RegisterUseMove(battle_ref, 'opponent', 'Tackle'), uow)

    assert user_events.PokemonChanged(battle_ref, 'host',
                                      'Flame') in uow.user_messagebus.events
Example #13
0
def test_a_battle_finishes():
    uow = FakeUnitOfWork()

    messagebus.handle(commands.AddTeam('Host team'), uow)
    messagebus.handle(commands.AddTeam('Opponent team'), uow)

    messagebus.handle(commands.AddPokemonToTeam('Host team',
                                                'Flame',
                                                'Ninetales',
                                                lvl=100,
                                                move_names=['Flamethrower']),
                      uow=uow)
    messagebus.handle(commands.AddPokemonToTeam('Opponent team',
                                                'Buggy',
                                                'Caterpie',
                                                lvl=5,
                                                move_names=['Tackle']),
                      uow=uow)

    battle_ref = messagebus.handle(commands.HostBattle('Host team'), uow)

    messagebus.handle(commands.JoinBattle(battle_ref, 'Opponent team'), uow)

    messagebus.handle(
        commands.RegisterUseMove(battle_ref, 'host', 'Flamethrower'), uow)
    messagebus.handle(
        commands.RegisterUseMove(battle_ref, 'opponent', 'Tackle'), uow)

    assert user_events.PokemonFainted(battle_ref,
                                      'Caterpie') in uow.user_messagebus.events
    assert user_events.BattleFinished(battle_ref,
                                      'host') in uow.user_messagebus.events