Пример #1
0
    async def test_already_created(self):
        lot = helpers.create_sell_lot()

        request = await self.client.post(
            '/place-sell-lot',
            data=market_pb2.PlaceSellLotRequest(
                lots=[protobuf.from_sell_lot(lot)]).SerializeToString())
        await self.check_success(request, market_pb2.PlaceSellLotResponse)

        request = await self.client.post(
            '/place-sell-lot',
            data=market_pb2.PlaceSellLotRequest(
                lots=[protobuf.from_sell_lot(lot)]).SerializeToString())
        await self.check_error(
            request, error='market.apply.sell_lot_for_item_already_created')

        result = await db.sql('SELECT * FROM log_records')

        self.assertEqual(len(result), 1)
Пример #2
0
    async def test_price_below_zero(self):
        lot = helpers.create_sell_lot(price=-1)

        # check that protobuf will rise error
        with self.assertRaises(ValueError):
            await self.client.post(
                '/place-sell-lot',
                data=market_pb2.PlaceSellLotRequest(
                    lots=[protobuf.from_sell_lot(lot)]).SerializeToString())

        result = await db.sql('SELECT * FROM log_records')

        self.assertEqual(len(result), 0)
Пример #3
0
    async def test_too_large_price(self):
        lot = helpers.create_sell_lot(price=2**63)

        request = await self.client.post(
            '/place-sell-lot',
            data=market_pb2.PlaceSellLotRequest(
                lots=[protobuf.from_sell_lot(lot)]).SerializeToString())
        await self.check_error(
            request, error='market.apply.sell_lot_maximum_price_exceeded')

        result = await db.sql('SELECT * FROM log_records')

        self.assertEqual(len(result), 0)
Пример #4
0
def place_sell_lots(lots):

    raw_lots = []

    for lot in lots:
        raw_lots.append(
            market_pb2.Lot(item_type=lot.full_type,
                           item_id=lot.item_id.hex,
                           owner_id=lot.owner_id,
                           price=lot.price))

    tt_api.sync_request(url=conf.payments_settings.TT_PLACE_SELL_LOT_URL,
                        data=market_pb2.PlaceSellLotRequest(lots=raw_lots),
                        AnswerType=market_pb2.PlaceSellLotResponse)
Пример #5
0
    async def test_success(self):
        lot = helpers.create_sell_lot()

        request = await self.client.post(
            '/place-sell-lot',
            data=market_pb2.PlaceSellLotRequest(
                lots=[protobuf.from_sell_lot(lot)]).SerializeToString())
        await self.check_success(request, market_pb2.PlaceSellLotResponse)

        result = await db.sql('SELECT * FROM log_records')

        self.assertEqual(len(result), 1)

        self.assertEqual(result[0]['operation_type'],
                         relations.OPERATION_TYPE.PLACE_SELL_LOT.value)
        self.assertEqual(result[0]['lot_type'], lot.type.value)
        self.assertEqual(result[0]['item_type'], lot.item_type)
        self.assertEqual(result[0]['item'], lot.item_id)
        self.assertEqual(result[0]['owner'], lot.owner_id)
        self.assertEqual(result[0]['price'], lot.price)
        self.assertEqual(result[0]['data'], {})
Пример #6
0
    async def test_success(self):
        lot = helpers.create_sell_lot()
        request = await self.client.post(
            '/place-sell-lot',
            data=market_pb2.PlaceSellLotRequest(
                lots=[protobuf.from_sell_lot(lot)]).SerializeToString())
        data = await self.check_success(request,
                                        market_pb2.PlaceSellLotResponse)

        request = await self.client.post('/close-sell-lot',
                                         data=market_pb2.CloseSellLotRequest(
                                             item_type=lot.item_type,
                                             buyer_id=lot.owner_id + 1,
                                             price=lot.price,
                                             number=1).SerializeToString())
        data = await self.check_success(request,
                                        market_pb2.CloseSellLotResponse)
        self.assertEqual([protobuf.to_sell_lot(x) for x in data.lots], [lot])

        result = await db.sql('SELECT * FROM sell_lots')
        self.assertFalse(result)

        result = await db.sql('SELECT * FROM log_records')
        self.assertEqual(len(result), 2)