Exemplo n.º 1
0
def test_card_provider_returns_valid_card_when_there_are_more_cards():
    # GIVEN
    Proxy()
    card = CardFactory()
    card2 = CardFactory(position=2)
    card4 = CardFactory(position=4)
    Proxy().load(full=True)
    # WHEN
    provided_card = CardProvider().get_card_with_position(2)
    # THEN
    assert provided_card == card2
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_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_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
Exemplo n.º 7
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
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_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_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
Exemplo n.º 11
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
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  
Exemplo n.º 13
0
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_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
Exemplo n.º 15
0
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
Exemplo n.º 16
0
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
Exemplo n.º 18
0
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_buy_building_when_buildings_limit_reached():
    # GIVEN
    Proxy()
    player = PlayerFactory(balance=5000, position=3)
    card = CardFactory(position=3)
    property = PropertyFactory(card=card,
                               player=player,
                               game=player.game,
                               buildings=5,
                               deposited=False)
    Proxy().load(full=True)
    [property,
     status] = BuildingService().buy_building(player.game_id, player.user_id)
    assert status == 2014
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_buy_building_when_property_is_deposited():
    # GIVEN
    Proxy()
    player = PlayerFactory(position=3, move=1)
    card = CardFactory(position=3)
    property = PropertyFactory(card=card,
                               player=player,
                               game=player.game,
                               buildings=0,
                               deposited=True)
    Proxy().load(full=True)
    [property,
     status] = BuildingService().buy_building(player.game_id, player.user_id)
    assert status == 2016
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_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_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_buy_building_when_valid_buying_hotel():
    # GIVEN
    Proxy()
    player = PlayerFactory(balance=700, position=3, move=1)
    card = CardFactory(position=3)
    property = PropertyFactory(card=card,
                               player=player,
                               game=player.game,
                               buildings=4,
                               deposited=False)
    Proxy().load(full=True)
    [property,
     status] = BuildingService().buy_building(player.game_id, player.user_id)
    new_balance = PlayerProvider().get_player_with_id(player.id).balance
    updated_property = PropertyProvider().get_property_with_id(property.id)
    assert status == 1000
    assert updated_property.buildings == 5
    assert new_balance == 0
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