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_property_change_owner_method(): user1 = UserFactory() game = GameFactory(host=user1) old_owner = valid_player(user=user1, game=game) new_owner = valid_player(game=game) player_property = valid_property(player=old_owner, selling_price=300) player_property.change_owner(new_owner, old_owner) assert player_property.player_id == new_owner.id assert old_owner.balance == 800 assert new_owner.balance == 200
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
def test_set_player_defeated_changes_active_to_false(): # GIVEN Proxy() user = UserFactory() game = GameFactory() Proxy().load(full=True) player, _ = GameService().join_player(game_id=game.id, user_id=user.id) # WHEN GameService().set_player_defeated(user_id=user.id, game_id=game.id) # THEN assert PlayerProvider().get_player_with_id(player.id).active == False
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
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_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_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_property_provider_returns_if_property_with_card_id_exist(): # GIVEN Proxy() game = GameFactory() card = CardFactory() property = PropertyFactory(game_id=game.id, card_id=card.id) Proxy().load() # WHEN if_exist = PropertyProvider().check_if_exist(game_id=game.id, card_id=card.id) # THEN assert if_exist == True
def test_join_player_does_not_create_new_player_if_board_is_full(): # GIVEN Proxy() game = GameFactory() for i in range(4): user = UserFactory() Proxy().load(full=True) GameService().join_player(game_id=game.id, user_id=user.id) # WHEN GameService().join_player(game_id=game.id, user_id=user.id) # THEN assert len(PlayerProvider().get_game_players(game.id)) == 4
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
def test_get_not_possible_to_buy_card(): # GIVEN Proxy() game = GameFactory() card = CardFactory(position=1) user = UserFactory() player = PlayerFactory(game_id=game.id, user_id=user.id, position=0) Proxy().load(full=True) # WHEN get_card = CardService().get_available_card_to_buy(game_id=game.id, user_id=user.id) # THEN assert get_card == (None, 2005)
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_get_already_owned_card_to_buy(): # GIVEN Proxy() game = GameFactory() card = CardFactory(position=99) property = PropertyFactory(game_id=game.id, card_id=card.id) user = UserFactory() player = PlayerFactory(game_id=game.id, user_id=user.id, position=99) Proxy().load(full=True) # WHEN get_card = CardService().get_available_card_to_buy(game_id=game.id, user_id=user.id) # THEN assert get_card == (None, 2006)
def test_repurchase_when_not_owner(): # GIVEN Proxy() game = GameFactory() card = CardFactory(position=1) player = PlayerFactory(game_id=game.id, move=1) user_property = PropertyFactory(card=card, game=game, deposited=False) Proxy().load(full=True) # WHEN deposit_property, status = DepositService().repurchase( user_id=player.user.id, game_id=game.id, card_id=card.id) # THEN assert deposit_property == None assert status == 2004
def test_cancel_offer_when_already_not_for_sale(): # GIVEN Proxy() user = UserFactory() # WHEN 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) [prop, status] = TradingService().cancel_offer(game.id, user.id, card.id) # THEN assert prop == None assert status == 2013
def test_accept_offer_when_not_for_sale(): # GIVEN Proxy() user = UserFactory() # WHEN game = GameFactory() player = PlayerFactory(user=user, game=game, move=1, balance=4000) card = CardFactory(position=5) user_property = PropertyFactory(card=card, game=game, selling_price=0) Proxy().load(full=True) [new_owner, status] = TradingService().accept_offer(game.id, user.id, card.id) # THEN assert new_owner == None assert status == 2013
def test_deposit_when_already_deposited(): # 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) Proxy().load(full=True) # WHEN deposit_property, status = DepositService().deposit(user_id=player.user.id, game_id=game.id, card_id=card.id) # THEN assert deposit_property == None assert status == 2016
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) user_property = PropertyFactory(card=card, game=game) Proxy().load(full=True) [new_owner, status] = TradingService().accept_offer(game.id, user.id, card.id, 5000) # THEN assert new_owner == player assert status == 1000
def test_create_offer_when_property_is_not_present(): # GIVEN Proxy() user = UserFactory() # WHEN game = GameFactory() player = PlayerFactory(user=user, game=game, move=1) card = CardFactory(position=5) user_property = PropertyFactory(card=card) Proxy().load(full=True) [prop, status] = TradingService().create_offer(game.id, user.id, card.id, 5000) # THEN assert prop == None assert status == 2007
def test_cancel_offer_when_valid(): # GIVEN Proxy() user = UserFactory() # WHEN game = GameFactory() player = PlayerFactory(user=user, game=game, move=1) card = CardFactory(position=5) user_property = PropertyFactory(card=card, player=player, game=game, selling_price=5000) Proxy().load(full=True) [prop, status] = TradingService().cancel_offer(game.id, user.id, card.id) # THEN assert prop.selling_price == 0 assert status == 1000
def test_cancel_offer_when_user_is_not_owner(): # GIVEN Proxy() user = UserFactory() # WHEN game = GameFactory() player = PlayerFactory(user=user, game=game, move=1) card = CardFactory(position=5) user_property = PropertyFactory(card=card, game=game, selling_price=4000) Proxy().load(full=True) [prop, status] = TradingService().cancel_offer(game.id, user.id, card.id) # THEN property_price = PropertyProvider().get_property_with_id( user_property.id).selling_price assert property_price == 4000 assert prop == None 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_repurchase_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=True) Proxy().load(full=True) # WHEN deposit_property, status = DepositService().repurchase( user_id=player.user.id, game_id=game.id, card_id=card.id) # THEN new_balance = PlayerProvider().get_player_with_id(player.id).balance new_property = PropertyProvider().get_property_with_id(user_property.id) assert new_property == user_property assert status == 1000 assert new_property.deposited == False assert new_balance == (player.balance - card.deposit_value)
def valid_player(active=True, balance=500, move=0, position=0, game=None, user=None): if user == None: valid_user = UserFactory() else: valid_user = user if game == None: valid_game = GameFactory(active=True) else: valid_game = game return PlayerFactory(game=valid_game, user=valid_user, active=active, balance=balance, move=move, position=position)