def test_buy_when_success():
  Proxy()
  player = PlayerFactory(position=1)
  card = CardFactory(position=1)
  Proxy().load(full=True)
  response = WebsocketService().buy(player.game_id, player.user_id)
  assert response['status'] == 1000
def test_skip_when_success():
  Proxy()
  player = PlayerFactory(move=1)
  player2 = PlayerFactory(game_id=player.game_id)
  Proxy().load()
  response = WebsocketService().skip(player.game_id, player.user_id)
  assert response['status'] == 1003
def test_tax_property_does_not_exists():
  Proxy()
  player = PlayerFactory(position=1)
  card = CardFactory(position=1)
  Proxy().load(full=True)
  response = WebsocketService().tax(player.game_id, player.user_id)
  assert response['status'] == 2007
Пример #4
0
def test_player_decrement_jail():
    Proxy()
    player = PlayerFactory(position=3, move=2, jailed=2)
    Proxy().load()
    player, status = PositionService().move_player(game_id=player.game_id,
                                                   user_id=player.user_id)
    assert player.jailed == 1
Пример #5
0
def test_update_balance():
    Proxy()
    player = PlayerFactory()
    Proxy().load()
    old_balance = player.balance
    player.update_balance(100)
    assert old_balance != player.balance
def test_chance_player_wrong_position():
    Proxy()
    chance = ChanceFactory(value=-1500)
    player = PlayerFactory(balance=2500, position=4)
    Proxy().load(full=True)
    chance, status = ChanceService().get_chance_card(game_id=player.game.id,
                                                     user_id=player.user.id)
    assert 2018 == status
Пример #7
0
def test_move_player_player_cannot_move():
    Proxy()
    player = PlayerFactory(position=3, move=0)
    Proxy().load()
    old_position = player.position
    player_changed_position, status = PositionService().move_player(
        player.game_id, player.user_id)
    assert old_position == player_changed_position.position
Пример #8
0
def test_player_in_jail_last_time():
    Proxy()
    player = PlayerFactory(position=3, move=2, jailed=1)
    Proxy().load()
    old_position = player.position
    player, status = PositionService().move_player(game_id=player.game_id,
                                                   user_id=player.user_id)
    assert player.jailed == 0
Пример #9
0
def test_player_on_go_to_jail_position_changes_position_to_jail():
    Proxy()
    player = PlayerFactory(position=16, move=2)
    Proxy().load()
    dice = MockDice(2)
    player, status = PositionService(dice).move_player(game_id=player.game_id,
                                                       user_id=player.user_id)
    assert player.position == settings.DEFAULT_GAME_SETTINGS['jail_position']
def test_sell_building_when_success():
  Proxy()
  player = PlayerFactory(position=3, move=1)
  card = CardFactory(position=7)
  property = PropertyFactory(player=player, game=player.game, card=card, buildings=2, deposited=False)
  Proxy().load(full=True)
  response = WebsocketService().sell_building(player.game_id, player.user_id, card.id)
  assert response['status'] == 1000
Пример #11
0
def test_player_on_go_to_jail_position_is_jailed():
    Proxy()
    player = PlayerFactory(position=16, move=2)
    Proxy().load()
    dice = MockDice(2)
    player, status = PositionService(dice).move_player(game_id=player.game_id,
                                                       user_id=player.user_id)
    assert player.jailed == 3
def test_chance_add_minus_value():
    Proxy()
    chance = ChanceFactory(value=-1500)
    player = PlayerFactory(balance=2500, position=3)
    Proxy().load(full=True)
    chance, status = ChanceService().get_chance_card(game_id=player.game.id,
                                                     user_id=player.user.id)
    new_balance = PlayerProvider().get_player_with_id(player.id).balance
    assert new_balance == (player.balance + chance.value)
Пример #13
0
def test_add_game_creates_new_game_with_code():
    # GIVEN
    Proxy()
    user = UserFactory()
    Proxy().load(full=True)
    # WHEN
    new_game, _ = GameService().add_game(host_id=user.id, players_amount=5)
    # THEN
    assert GameProvider().get_game(new_game.id).code is not None
Пример #14
0
def test_add_game_creates_new_game():
    # GIVEN
    Proxy()
    user = UserFactory()
    Proxy().load(full=True)
    # WHEN
    new_game, _ = GameService().add_game(host_id=user.id, players_amount=5)
    # THEN
    assert len(Proxy().games_dict) == 1
Пример #15
0
def test_skip_turn_doestn_set_move_to_zero_if_move_eq_two():
    # GIVEN
    Proxy()
    player = PlayerFactory(move=2)
    Proxy().load(full=True)
    # WHEN
    GameService().skip_turn(game_id=player.game_id, user_id=player.user_id)
    # THEN
    assert PlayerProvider().get_player_with_id(player.id).move == 2
Пример #16
0
def test_charge_provider_returns_valid_charge():
    # GIVEN
    Proxy()
    charge = ChargeFactory(id=1)
    Proxy().load(full=True)
    # WHEN
    provided_charge = ChargeProvider().get_charge(1)
    # THEN
    assert provided_charge == charge
Пример #17
0
def test_player_on_go_to_jail_position_has_set_move_to_zero():
    Proxy()
    player = PlayerFactory(position=16, move=2)
    player2 = PlayerFactory(game_id=player.game_id, order=1)
    Proxy().load()
    dice = MockDice(2)
    player, status = PositionService(dice).move_player(game_id=player.game_id,
                                                       user_id=player.user_id)
    assert player.move == 0
def test_offer_when_card_is_owned():
  Proxy()
  game = GameFactory()
  card = CardFactory(position=1)
  property = PropertyFactory(game_id=game.id,card_id=card.id)
  player = PlayerFactory(game_id=game.id,position=1)
  Proxy().load(full=True)
  response = WebsocketService().offer(player.game_id, player.user_id)
  assert response['status'] == 2006
def test_tax_when_success():
  Proxy()
  game = GameFactory()
  player = PlayerFactory(game=game, position=1)
  card = CardFactory(position=1)
  property = PropertyFactory(player=player, game=game, card=card)
  Proxy().load(full=True)
  response = WebsocketService().tax(player.game_id, player.user_id)
  assert response['status'] == 1000
Пример #20
0
def test_player_on_go_to_jail_position_sets_next_player_move_to_two():
    Proxy()
    player = PlayerFactory(position=16, move=2, order=0)
    player2 = PlayerFactory(move=0, order=1, game=player.game)
    Proxy().load()
    dice = MockDice(2)
    player, status = PositionService(dice).move_player(game_id=player.game_id,
                                                       user_id=player.user_id)
    assert PlayerProvider().next_player(player.id).move == 2
Пример #21
0
def test_add_game_sets_proper_players_amount():
    # GIVEN
    Proxy()
    user = UserFactory()
    Proxy().load(full=True)
    # WHEN
    new_game, _ = GameService().add_game(host_id=user.id, players_amount=5)
    # THEN
    assert new_game.players_amount == 5
Пример #22
0
def test_card_provider_returns_no_card():
    # GIVEN
    Proxy()
    card = CardFactory()
    Proxy().load(full=True)
    # WHEN
    provided_card = CardProvider().get_card_with_position(0)
    # THEN
    assert provided_card == None
Пример #23
0
def test_property_provider_returns_if_property_with_card_id_not_exist():
    # GIVEN
    Proxy()
    game = GameFactory()
    property = PropertyFactory(game_id=game.id, card_id=1)
    Proxy().load()
    # WHEN
    if_exist = PropertyProvider().check_if_exist(game_id=game.id, card_id=2)
    # THEN
    assert if_exist == False
Пример #24
0
def test_join_player_creates_new_player():
    # GIVEN
    Proxy()
    game = GameFactory()
    user = UserFactory()
    Proxy().load(full=True)
    # WHEN
    GameService().join_player(game_id=game.id, user_id=user.id)
    # THEN
    assert len(PlayerProvider().get_game_players(game.id)) == 1
def test_buy_building_when_player_is_not_owner():
    # GIVEN
    Proxy()
    player = PlayerFactory(balance=5000, position=3, move=1)
    card = CardFactory(position=3)
    property = PropertyFactory(card=card, game=player.game, deposited=False)
    Proxy().load(full=True)
    [property,
     status] = BuildingService().buy_building(player.game_id, player.user_id)
    assert status == 2004
Пример #26
0
def test_get_game_returns_proper_player():
    # GIVEN
    Proxy()
    user = UserFactory()
    game = GameFactory()
    Proxy().load(full=True)
    # WHEN
    get_game = GameService().get_game(game.id)
    # THEN
    assert get_game == (game, 1000)
def test_create_offer_when_success():
  Proxy()
  user = UserFactory()
  game = GameFactory()
  player = PlayerFactory(user=user, game=game, move=1)
  card = CardFactory(position=5)
  user_property = PropertyFactory(card=card, player=player, game=game)
  Proxy().load(full=True)
  response = WebsocketService().create_offer(player.game_id, player.user_id, card_id=card.id, price=5000)
  assert response['status'] == 1000
Пример #28
0
def test_skip_turn_sets_player_move_to_zero():
    # GIVEN
    Proxy()
    player = PlayerFactory(move=1)
    player = PlayerFactory(move=0, game_id=player.game_id, order=1)
    Proxy().load(full=True)
    # WHEN
    GameService().skip_turn(game_id=player.game_id, user_id=player.user_id)
    # THEN
    assert PlayerProvider().get_player_with_id(player.id).move == 0
Пример #29
0
def test_property_provider_returns_valid_property():
    # GIVEN
    Proxy()
    player = PlayerFactory()
    property = PropertyFactory(player=player, game_id=player.game_id)
    Proxy().load()
    # WHEN
    provided_properties = PropertyProvider().get_player_properties(
        game_id=player.game_id, player_id=player.id)
    # THEN
    assert provided_properties[0] == property
Пример #30
0
def test_is_property_taken_returns_false():
    # GIVEN
    Proxy()
    game = GameFactory()
    card = CardFactory()
    Proxy().load()
    # WHEN
    is_taken = PropertyProvider().is_property_taken(game_id=game.id,
                                                    card_id=card.id)
    # THEN
    assert is_taken == False