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_update_balance(): Proxy() player = PlayerFactory() Proxy().load() old_balance = player.balance player.update_balance(100) assert old_balance != player.balance
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_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
def test_player_provider_returns_valid_player_when_there_are_more_players(): # GIVEN player1 = PlayerFactory() player2 = PlayerFactory(game_id=player1.game_id, order=1) player3 = PlayerFactory(game_id=player1.game_id, order=2) # WHEN provided_player = PlayerProvider().get_player(user_id=player1.user_id, game_id=player1.game_id) # THEN assert provided_player == player1
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
def test_accept_offer_when_success(): Proxy() user = UserFactory() game = GameFactory() player = PlayerFactory(user=user, game=game, balance=6000) card = CardFactory(position=5) old_owner = PlayerFactory(game=game, balance=1000) user_property = PropertyFactory(card=card, game=game, player=old_owner, selling_price=5000) Proxy().load(full=True) response = WebsocketService().accept_offer(player.game_id, player.user_id, card_id=card.id) assert response['status'] == 1000
def test_property_provider_returns_valid_property_when_there_are_more_players( ): # GIVEN Proxy() player = PlayerFactory() player2 = PlayerFactory(game_id=player.game_id, order=1) property = PropertyFactory(player=player, game_id=player.game_id) property2 = PropertyFactory(player=player, game_id=player2.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
def test_tax_when_success(): Proxy() game = GameFactory() init_balance = 1000 cost = 100 player = PlayerFactory(game=game, position=1, balance=init_balance) player2 = PlayerFactory(game=game, balance=init_balance) charge = ChargeFactory(zero_apartments=cost) card = CardFactory(position=1, charge=charge) property = PropertyFactory(player=player2, game=game, card=card, buildings=0) Proxy().load(full=True) response = WebsocketService().tax(player.game_id, player.user_id) assert PlayerProvider().get_player_with_id(player.id).balance == init_balance-cost assert PlayerProvider().get_player_with_id(player2.id).balance == init_balance+cost
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
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_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
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
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
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
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_player_provider_returns_valid_player(): # GIVEN player = PlayerFactory() # WHEN provided_player = PlayerProvider().get_player(user_id=player.user_id, game_id=player.game_id) # THEN assert provided_player == player
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_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
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
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
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)
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
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
def test_accept_offer_when_valid(): # GIVEN Proxy() user = UserFactory() # WHEN game = GameFactory() player = PlayerFactory(user=user, game=game, move=1, balance=6000) card = CardFactory(position=5) old_owner = PlayerFactory(game=game, balance=1000) user_property = PropertyFactory(card=card, game=game, player=old_owner, selling_price=5000) Proxy().load(full=True) [[new_owner, old_owner], status] = TradingService().accept_offer(game.id, user.id, card.id) old_owner_new_balance = old_owner.balance # THEN assert new_owner.balance == 1000 assert old_owner_new_balance == 6000
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
def test_cancel_offer_when_success(): # GIVEN Proxy() user = UserFactory() # WHEN game = GameFactory() player = PlayerFactory(user=user, game=game) card = CardFactory(position=5) user_property = PropertyFactory(card=card, player=player, game=game, selling_price=5000) Proxy().load(full=True) response = WebsocketService().cancel_offer(player.game_id, player.user_id, card_id=card.id) assert response['status'] == 1000
def test_deposit_when_valid(): # GIVEN Proxy() game = GameFactory() card = CardFactory(position=1) player = PlayerFactory(game_id=game.id, move=1) user_property = PropertyFactory(player=player, card=card, game=game, deposited=False) Proxy().load(full=True) # WHEN response = WebsocketService().deposit(user_id=player.user.id, game_id=game.id, card_id=card.id) # THEN assert response['status'] == 1000
def test_is_property_taken_returns_true(): # GIVEN Proxy() game = GameFactory() card = CardFactory() player = PlayerFactory(game_id=game.id) property = PropertyFactory(player=player, game_id=game.id, card_id=card.id) Proxy().load() # WHEN is_taken = PropertyProvider().is_property_taken(game_id=game.id, card_id=card.id) # THEN assert is_taken == True