Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def add_team():
    cmd = commands.AddTeam(request.json['name'])
    uow = unit_of_work.UnitOfWork()
    messagebus.handle(cmd, uow)
    return jsonify({'status': 'OK'}), 201
Ejemplo n.º 6
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