Exemplo n.º 1
0
    async def test_read_offer__make_transaction__missing_all_request_or(
        self,
        worldmapc_xena_model: CharacterModel,
        worldmapc_arthur_model: CharacterModel,
        worldmapc_web_app: TestClient,
        worldmapc_kernel: Kernel,
        xena_permanent_or_offer: OfferDocument,
    ) -> None:
        xena = worldmapc_xena_model
        arthur = worldmapc_arthur_model
        kernel = worldmapc_kernel
        web = worldmapc_web_app
        offer = xena_permanent_or_offer

        # ensure xena have all offered items
        kernel.resource_lib.add_resource_to("WOOD", 0.5, character_id=xena.id)
        jacket = create_stuff(kernel, "LEATHER_JACKET")
        kernel.stuff_lib.set_carried_by(jacket.id, character_id=xena.id)

        resp = await web.post(
            f"/business/{arthur.id}/see-offer/{offer.character_id}/{offer.id}/deal"
        )
        assert 200 == resp.status
        descr = description_serializer.load(await resp.json())

        item_labels = [i.label or i.text for i in descr.items]
        assert "Vous ne possédez pas ce qu'il faut pour faire ce marché" in item_labels
Exemplo n.º 2
0
    async def test_edit_offer__test_owner_have_display(
        self,
        worldmapc_xena_model: CharacterModel,
        worldmapc_arthur_model: CharacterModel,
        worldmapc_web_app: TestClient,
        worldmapc_kernel: Kernel,
        xena_permanent_and_offer: OfferDocument,
    ) -> None:
        xena = worldmapc_xena_model
        kernel = worldmapc_kernel
        web = worldmapc_web_app

        await self._assert_edit_offer(
            kernel,
            web,
            xena,
            offer_id=1,
            offer_item_names=[
                "(X) Bois (0.5 mètre cubes)", "(X) Veste de cuir (1)"
            ],
            request_operand_str=ALL_OF_THEM,
            offer_operand_str=ALL_OF_THEM,
            open_=True,
        )
        # add one to offer owner
        kernel.resource_lib.add_resource_to("WOOD", 0.5, character_id=xena.id)

        await self._assert_edit_offer(
            kernel,
            web,
            xena,
            offer_id=1,
            offer_item_names=[
                "Bois (0.5 mètre cubes)", "(X) Veste de cuir (1)"
            ],
            request_operand_str=ALL_OF_THEM,
            offer_operand_str=ALL_OF_THEM,
            open_=True,
        )

        # add one to offer owner
        jacket = create_stuff(kernel, "LEATHER_JACKET")
        kernel.stuff_lib.set_carried_by(jacket.id, character_id=xena.id)

        await self._assert_edit_offer(
            kernel,
            web,
            xena,
            offer_id=1,
            request_item_names=["Bois (0.5 mètre cubes)", "Veste de cuir (1)"],
            request_operand_str=ALL_OF_THEM,
            offer_operand_str=ALL_OF_THEM,
            open_=True,
        )
Exemplo n.º 3
0
    def test_eat__ok__eat_stuff(self, worldmapc_kernel: Kernel,
                                turn_lib: TurnLib,
                                xena: CharacterDocument) -> None:
        kernel = worldmapc_kernel

        apple = create_stuff(kernel, "APPLE")
        kernel.stuff_lib.set_carried_by(apple.id, xena.id)

        with unittest.mock.patch(
                "rolling.server.effect.EffectManager.enable_effect"
        ) as fake_enable_effect:
            turn_lib.execute_turn()

        assert not kernel.stuff_lib.have_stuff_count(character_id=xena.id,
                                                     stuff_id="APPLE")
        assert fake_enable_effect.called
        assert fake_enable_effect.call_args_list[0][0][
            1].id == "HUNGRY_SATISFIED"
Exemplo n.º 4
0
    async def test_create_with_character_transaction(
        self,
        worldmapc_xena_model: CharacterModel,
        worldmapc_arthur_model: CharacterModel,
        worldmapc_web_app: TestClient,
        worldmapc_kernel: Kernel,
        initial_universe_state: UniverseStateDocument,
    ) -> None:
        """+ conteur main page + vue depuis target + blinker"""
        xena = worldmapc_xena_model
        arthur = worldmapc_arthur_model
        kernel = worldmapc_kernel
        web = worldmapc_web_app

        assert (await web.post(
            f"/business/{xena.id}/offers-create?with_character_id={arthur.id}",
            json={"title": "My offer"},
        )).status == 200
        assert (await web.post(
            f"/business/{xena.id}/offers/{1}/add-item"
            f"?position=REQUEST&value=Plastic bottle (unité)&quantity=1"
        )).status == 200
        assert (await web.post(
            f"/business/{xena.id}/offers/{1}/add-item"
            f"?position=OFFER&value=Vin rouge (litres)&quantity=1.5"
        )).status == 200
        assert (
            await
            web.post(f"/business/{xena.id}/offers/{1}?open=1")).status == 200

        await self._assert_edit_offer(
            kernel,
            web,
            character=xena,
            offer_id=1,
            request_operand_str=ONE_OF_THEM,
            offer_operand_str=ONE_OF_THEM,
            request_item_names=["Plastic bottle (1)"],
            offer_item_names=["(X) Vin rouge (1.5 litres)"],
            open_=True,
        )

        await self._assert_read_offer(
            kernel,
            web,
            owner=xena,
            character=arthur,
            offer_id=1,
            request_operand_str=ONE_OF_THEM,
            offer_operand_str=ONE_OF_THEM,
            have_not_item_names=["Plastic bottle (1)"],
            offer_item_names=["(!) Vin rouge (1.5 litres)"],
            can_make_deal=False,
        )

        # Give all necessary
        kernel.resource_lib.add_resource_to("RED_WINE",
                                            1.5,
                                            character_id=xena.id)
        bottle = create_stuff(kernel, "PLASTIC_BOTTLE_1L")
        kernel.stuff_lib.set_carried_by(bottle.id, character_id=arthur.id)

        assert kernel.resource_lib.have_resource(xena.id, "RED_WINE", 1.5)
        assert not kernel.stuff_lib.have_stuff_count(xena.id,
                                                     "PLASTIC_BOTTLE_1L")

        assert not kernel.resource_lib.have_resource(arthur.id, "RED_WINE",
                                                     1.5)
        assert kernel.stuff_lib.have_stuff_count(arthur.id,
                                                 "PLASTIC_BOTTLE_1L")

        await self._assert_read_offer(
            kernel,
            web,
            owner=xena,
            character=arthur,
            offer_id=1,
            request_operand_str=ONE_OF_THEM,
            offer_operand_str=ONE_OF_THEM,
            have_item_names=["Plastic bottle (1)"],
            offer_item_names=["Vin rouge (1.5 litres)"],
            can_make_deal=True,
        )

        # xena main page
        resp: ClientResponse = await web.post(f"/business/{xena.id}")
        assert 200 == resp.status
        descr = description_serializer.load(await resp.json())
        item_labels = [i.label for i in descr.items]

        assert "Voir les transactions en attente (1 en cours)" in item_labels

        # arthur main page
        resp: ClientResponse = await web.post(f"/business/{arthur.id}")
        assert 200 == resp.status
        descr = description_serializer.load(await resp.json())
        item_labels = [i.label for i in descr.items]

        assert "*Voir les transactions en attente (1 en cours)" in item_labels

        resp = await web.post(
            f"/business/{arthur.id}/see-offer/{xena.id}/{1}/deal")
        assert 200 == resp.status
        descr = description_serializer.load(await resp.json())

        item_labels = [i.label or i.text for i in descr.items]
        item_by_label = {i.label: i for i in descr.items}

        deal_str = "Faire ce marché et donner Plastic bottle (1)"
        assert deal_str in item_labels
        go_url = item_by_label[deal_str].form_action

        resp = await web.post(go_url)
        assert 200 == resp.status
        descr = description_serializer.load(await resp.json())

        item_labels = [i.label or i.text for i in descr.items]
        item_by_label = {i.label: i for i in descr.items}

        deal_str = "Faire ce marché et obtenir Vin rouge (1.5 litres)"
        assert deal_str in item_labels
        go_url = item_by_label[deal_str].form_action

        assert (await web.post(go_url)).status == 200

        assert not kernel.resource_lib.have_resource(xena.id, "RED_WINE", 1.5)
        assert kernel.stuff_lib.have_stuff_count(xena.id, "PLASTIC_BOTTLE_1L")

        assert kernel.resource_lib.have_resource(arthur.id, "RED_WINE", 1.5)
        assert not kernel.stuff_lib.have_stuff_count(arthur.id,
                                                     "PLASTIC_BOTTLE_1L")

        # xena main page
        resp: ClientResponse = await web.post(f"/business/{xena.id}")
        assert 200 == resp.status
        descr = description_serializer.load(await resp.json())
        item_labels = [i.label for i in descr.items]

        assert "Voir les transactions en attente (0 en cours)" in item_labels

        # arthur main page
        resp: ClientResponse = await web.post(f"/business/{arthur.id}")
        assert 200 == resp.status
        descr = description_serializer.load(await resp.json())
        item_labels = [i.label for i in descr.items]

        assert "Voir les transactions en attente (0 en cours)" in item_labels
Exemplo n.º 5
0
    async def test_read_offer__make_transaction__request_or(
        self,
        worldmapc_xena_model: CharacterModel,
        worldmapc_arthur_model: CharacterModel,
        worldmapc_web_app: TestClient,
        worldmapc_kernel: Kernel,
        xena_permanent_or_offer: OfferDocument,
        initial_universe_state: UniverseStateDocument,
    ) -> None:
        xena = worldmapc_xena_model
        arthur = worldmapc_arthur_model
        kernel = worldmapc_kernel
        web = worldmapc_web_app
        offer = xena_permanent_or_offer

        # ensure xena have one of offered items
        kernel.resource_lib.add_resource_to("WOOD", 0.5, character_id=xena.id)

        # Give all necessary to arthur
        kernel.resource_lib.add_resource_to("RED_WINE",
                                            1.5,
                                            character_id=arthur.id)
        haxe = create_stuff(kernel, "STONE_HAXE")
        kernel.stuff_lib.set_carried_by(haxe.id, character_id=arthur.id)

        assert kernel.resource_lib.have_resource(xena.id, "WOOD", 0.5)
        assert not kernel.resource_lib.have_resource(xena.id, "RED_WINE", 1.5)
        assert not kernel.stuff_lib.have_stuff_count(xena.id, "STONE_HAXE")

        assert not kernel.resource_lib.have_resource(arthur.id, "WOOD", 0.5)
        assert kernel.resource_lib.have_resource(arthur.id, "RED_WINE", 1.5)
        assert kernel.stuff_lib.have_stuff_count(arthur.id, "STONE_HAXE")

        resp = await web.post(
            f"/business/{arthur.id}/see-offer/{offer.character_id}/{offer.id}/deal"
        )
        assert 200 == resp.status
        descr = description_serializer.load(await resp.json())

        item_labels = [i.label or i.text for i in descr.items]
        item_by_label = {i.label: i for i in descr.items}
        give_wine_str = "Faire ce marché et donner Vin rouge (1.5 litres)"
        assert give_wine_str in item_labels
        assert "Faire ce marché et donner Hache de pierre (1)" in item_labels

        give_wine_url = item_by_label[give_wine_str].form_action
        resp = await web.post(give_wine_url)
        assert 200 == resp.status
        descr = description_serializer.load(await resp.json())

        item_labels = [i.label or i.text for i in descr.items]
        item_by_label = {i.label: i for i in descr.items}
        take_wood_str = "Faire ce marché et obtenir Bois (0.5 mètre cubes)"
        assert take_wood_str in item_labels
        assert "Faire ce marché et obtenir Veste de cuir (1)" not in item_labels

        # Give jacket to xena to permit take it
        jacket = create_stuff(kernel, "LEATHER_JACKET")
        kernel.stuff_lib.set_carried_by(jacket.id, character_id=xena.id)
        resp = await web.post(give_wine_url)
        assert 200 == resp.status
        descr = description_serializer.load(await resp.json())

        item_labels = [i.label or i.text for i in descr.items]
        item_by_label = {i.label: i for i in descr.items}
        take_wood_str = "Faire ce marché et obtenir Bois (0.5 mètre cubes)"
        assert take_wood_str in item_labels
        assert "Faire ce marché et obtenir Veste de cuir (1)" in item_labels

        take_wood_url = item_by_label[take_wood_str].form_action
        resp = await web.post(take_wood_url)
        assert 200 == resp.status

        assert not kernel.resource_lib.have_resource(xena.id, "WOOD", 0.5)
        assert kernel.resource_lib.have_resource(xena.id, "RED_WINE", 1.5)
        assert not kernel.stuff_lib.have_stuff_count(xena.id, "STONE_HAXE")

        assert kernel.resource_lib.have_resource(arthur.id, "WOOD", 0.5)
        assert not kernel.resource_lib.have_resource(arthur.id, "RED_WINE",
                                                     1.5)
        assert kernel.stuff_lib.have_stuff_count(arthur.id, "STONE_HAXE")
Exemplo n.º 6
0
    async def test_read_offer__make_transaction__request_and(
        self,
        worldmapc_xena_model: CharacterModel,
        worldmapc_arthur_model: CharacterModel,
        worldmapc_web_app: TestClient,
        worldmapc_kernel: Kernel,
        xena_permanent_and_offer: OfferDocument,
        initial_universe_state: UniverseStateDocument,
    ) -> None:
        xena = worldmapc_xena_model
        arthur = worldmapc_arthur_model
        kernel = worldmapc_kernel
        web = worldmapc_web_app
        offer = xena_permanent_and_offer

        # Give all necessary to arthur
        kernel.resource_lib.add_resource_to("RED_WINE",
                                            2.0,
                                            character_id=arthur.id)
        haxe = create_stuff(kernel, "STONE_HAXE")
        kernel.stuff_lib.set_carried_by(haxe.id, character_id=arthur.id)

        # ensure xena have all offered items
        kernel.resource_lib.add_resource_to("WOOD", 0.5, character_id=xena.id)
        jacket = create_stuff(kernel, "LEATHER_JACKET")
        kernel.stuff_lib.set_carried_by(jacket.id, character_id=xena.id)

        assert kernel.resource_lib.have_resource(xena.id, "WOOD", 0.5)
        assert kernel.stuff_lib.have_stuff_count(xena.id, "LEATHER_JACKET")
        assert not kernel.resource_lib.have_resource(xena.id, "RED_WINE", 1.5)
        assert not kernel.stuff_lib.have_stuff_count(xena.id, "STONE_HAXE")

        assert not kernel.resource_lib.have_resource(arthur.id, "WOOD", 0.5)
        assert not kernel.stuff_lib.have_stuff_count(arthur.id,
                                                     "LEATHER_JACKET")
        assert kernel.resource_lib.have_resource(arthur.id, "RED_WINE", 1.5)
        assert kernel.stuff_lib.have_stuff_count(arthur.id, "STONE_HAXE")

        resp = await web.post(
            f"/business/{arthur.id}/see-offer/{offer.character_id}/{offer.id}/deal"
        )
        assert 200 == resp.status
        descr = description_serializer.load(await resp.json())

        item_labels = [i.label or i.text for i in descr.items]
        assert "Je confirme vouloir faire ce marché" in item_labels

        # Do the deal
        resp = await web.post(
            f"/business/{arthur.id}/see-offer/{offer.character_id}/{offer.id}/deal?confirm=1"
        )
        assert 200 == resp.status
        descr = description_serializer.load(await resp.json())

        item_labels = [i.label or i.text for i in descr.items]
        assert "Marché effectué" in item_labels

        assert not kernel.resource_lib.have_resource(xena.id, "WOOD", 0.5)
        assert not kernel.stuff_lib.have_stuff_count(xena.id, "LEATHER_JACKET")
        assert kernel.resource_lib.have_resource(xena.id, "RED_WINE", 1.5)
        assert kernel.stuff_lib.have_stuff_count(xena.id, "STONE_HAXE")

        assert kernel.resource_lib.have_resource(arthur.id, "WOOD", 0.5)
        assert kernel.stuff_lib.have_stuff_count(arthur.id, "LEATHER_JACKET")
        assert not kernel.resource_lib.have_resource(arthur.id, "RED_WINE",
                                                     1.5)
        assert not kernel.stuff_lib.have_stuff_count(arthur.id, "STONE_HAXE")
Exemplo n.º 7
0
    async def test_read_offer__have_some_required_items__or(
        self,
        worldmapc_xena_model: CharacterModel,
        worldmapc_arthur_model: CharacterModel,
        worldmapc_web_app: TestClient,
        worldmapc_kernel: Kernel,
        xena_permanent_or_offer: OfferDocument,
    ) -> None:
        xena = worldmapc_xena_model
        arthur = worldmapc_arthur_model
        kernel = worldmapc_kernel
        web = worldmapc_web_app
        offer = xena_permanent_or_offer

        # ensure xena have all offered items
        kernel.resource_lib.add_resource_to("WOOD", 0.5, character_id=xena.id)
        jacket = create_stuff(kernel, "LEATHER_JACKET")
        kernel.stuff_lib.set_carried_by(jacket.id, character_id=xena.id)

        await self._assert_read_offer(
            kernel,
            web,
            xena,
            arthur,
            offer_id=offer.id,
            request_operand_str=ONE_OF_THEM,
            offer_operand_str=ONE_OF_THEM,
            have_not_item_names=[
                "Vin rouge (1.5 litres)", "Hache de pierre (1)"
            ],
            offer_item_names=["Bois (0.5 mètre cubes)", "Veste de cuir (1)"],
            can_make_deal=False,
        )

        kernel.resource_lib.add_resource_to("RED_WINE",
                                            2.0,
                                            character_id=arthur.id)

        await self._assert_read_offer(
            kernel,
            web,
            xena,
            arthur,
            offer_id=offer.id,
            request_operand_str=ONE_OF_THEM,
            offer_operand_str=ONE_OF_THEM,
            have_not_item_names=["Hache de pierre (1)"],
            have_item_names=["Vin rouge (1.5 litres)"],
            can_make_deal=True,
        )

        haxe = create_stuff(kernel, "STONE_HAXE")
        kernel.stuff_lib.set_carried_by(haxe.id, character_id=arthur.id)

        await self._assert_read_offer(
            kernel,
            web,
            xena,
            arthur,
            offer_id=offer.id,
            request_operand_str=ONE_OF_THEM,
            offer_operand_str=ONE_OF_THEM,
            have_item_names=["Vin rouge (1.5 litres)", "Hache de pierre (1)"],
            can_make_deal=True,
        )