Beispiel #1
0
def test_balancing_market_negative_offer_trade(market=BalancingMarket(time_slot=now())):  # NOQA
    offer = market.balancing_offer(20, -10, 'A', 'A')

    now = DateTime.now(tz=TIME_ZONE)
    trade = market.accept_offer(offer, 'B', time=now, energy=-10)
    assert trade
    assert trade == market.trades[0]
    assert trade.id
    assert trade.time == now
    assert trade.offer is offer
    assert trade.seller == 'A'
    assert trade.buyer == 'B'
Beispiel #2
0
def test_balancing_market_negative_offer_trade(market=BalancingMarket(
    bc=NonBlockchainInterface(str(uuid4())), time_slot=now())):  # NOQA
    offer = market.balancing_offer(20, -10, "A", "A")

    now = DateTime.now(tz=TIME_ZONE)
    trade = market.accept_offer(offer, "B", time=now, energy=-10)
    assert trade
    assert trade == market.trades[0]
    assert trade.id
    assert trade.time == now
    assert trade.offer_bid is offer
    assert trade.seller == "A"
    assert trade.buyer == "B"
Beispiel #3
0
def test_device_registry(market=BalancingMarket()):
    with pytest.raises(DeviceNotInRegistryError):
        market.balancing_offer(10, 10, 'noone')
Beispiel #4
0
    bid, offer = matched[0]
    assert bid.id == 'bid_id3'
    assert bid.price == 12
    assert bid.energy == 10
    assert offer == list(market.offers.values())[0]


def test_device_registry(market=BalancingMarket()):
    with pytest.raises(DeviceNotInRegistryError):
        market.balancing_offer(10, 10, 'noone')


@pytest.mark.parametrize(
    "market, offer",
    [(OneSidedMarket(time_slot=DateTime.now()), "offer"),
     (BalancingMarket(time_slot=DateTime.now()), "balancing_offer")])
def test_market_offer(market, offer):
    DeviceRegistry.REGISTRY = device_registry_dict
    ConstSettings.BalancingSettings.ENABLE_BALANCING_MARKET = True
    e_offer = getattr(market, offer)(10, 20, 'someone', 'someone')
    assert market.offers[e_offer.id] == e_offer
    assert e_offer.energy == 20
    assert e_offer.price == 10
    assert e_offer.seller == 'someone'
    assert len(e_offer.id) == 36


def test_market_bid(market: TwoSidedPayAsBid):
    bid = market.bid(1, 2, 'bidder', 'seller', 'bidder')
    assert market.bids[bid.id] == bid
    assert bid.price == 1
Beispiel #5
0
    DeviceRegistry.REGISTRY = {}


@pytest.fixture
def market():
    return TwoSidedMarket(time_slot=now())


def test_device_registry(market=BalancingMarket()):
    with pytest.raises(DeviceNotInRegistryError):
        market.balancing_offer(10, 10, "noone")


@pytest.mark.parametrize("market, offer", [
    (OneSidedMarket(bc=NonBlockchainInterface(str(uuid4())), time_slot=now()), "offer"),
    (BalancingMarket(bc=NonBlockchainInterface(str(uuid4())), time_slot=now()), "balancing_offer")
])
def test_market_offer(market, offer):
    ConstSettings.BalancingSettings.ENABLE_BALANCING_MARKET = True
    e_offer = getattr(market, offer)(10, 20, "someone", "someone")
    assert market.offers[e_offer.id] == e_offer
    assert e_offer.energy == 20
    assert e_offer.price == 10
    assert e_offer.seller == "someone"
    assert len(e_offer.id) == 36


def test_market_offer_invalid(market: OneSidedMarket):
    with pytest.raises(InvalidOffer):
        market.offer(10, -1, "someone", "someone")
Beispiel #6
0
    assert len(matched) == 1
    bid, offer = matched[0]
    assert bid.id == 'bid_id3'
    assert bid.price == 12
    assert bid.energy == 10
    assert offer == list(market.offers.values())[0]


def test_device_registry(market=BalancingMarket()):
    with pytest.raises(DeviceNotInRegistryError):
        market.balancing_offer(10, 10, 'noone')


@pytest.mark.parametrize("market, offer", [
    (OneSidedMarket(time_slot=now()), "offer"),
    (BalancingMarket(time_slot=now()), "balancing_offer")
])
def test_market_offer(market, offer):
    DeviceRegistry.REGISTRY = device_registry_dict
    ConstSettings.BalancingSettings.ENABLE_BALANCING_MARKET = True
    e_offer = getattr(market, offer)(10, 20, 'someone', 'someone')
    assert market.offers[e_offer.id] == e_offer
    assert e_offer.energy == 20
    assert e_offer.price == 10
    assert e_offer.seller == 'someone'
    assert len(e_offer.id) == 36


def test_market_bid(market: TwoSidedPayAsBid):
    bid = market.bid(1, 2, 'bidder', 'seller', 'bidder')
    assert market.bids[bid.id] == bid
Beispiel #7
0
        ConstSettings.BalancingSettings.ENABLE_BALANCING_MARKET = True


@pytest.yield_fixture
def market():
    return TwoSidedPayAsBid(area=FakeArea("FakeArea"))


def test_device_registry(market=BalancingMarket()):
    with pytest.raises(DeviceNotInRegistryError):
        market.balancing_offer(10, 10, 'noone')


@pytest.mark.parametrize("market, offer", [
    (OneSidedMarket(), "offer"),
    (BalancingMarket(), "balancing_offer")
])
def test_market_offer(market, offer):
    e_offer = getattr(market, offer)(10, 20, 'someone')
    assert market.offers[e_offer.id] == e_offer
    assert e_offer.energy == 20
    assert e_offer.price == 10
    assert e_offer.seller == 'someone'
    assert len(e_offer.id) == 36


def test_market_bid(market: TwoSidedPayAsBid):
    bid = market.bid(1, 2, 'bidder', 'seller')
    assert market.bids[bid.id] == bid
    assert bid.price == 1
    assert bid.energy == 2
Beispiel #8
0
    bid, offer = matched[0]
    assert bid.id == 'bid_id3'
    assert bid.price == 12
    assert bid.energy == 10
    assert offer == list(market.offers.values())[0]


def test_device_registry(market=BalancingMarket(area=FakeArea("FakeArea"))):
    with pytest.raises(DeviceNotInRegistryError):
        market.balancing_offer(10, 10, 'noone')


@pytest.mark.parametrize(
    "market, offer",
    [(OneSidedMarket(area=FakeArea("FakeArea", transfer_fee_pct=0)), "offer"),
     (BalancingMarket(area=FakeArea("FakeArea", transfer_fee_pct=0)),
      "balancing_offer")])
def test_market_offer(market, offer):
    e_offer = getattr(market, offer)(10, 20, 'someone')
    assert market.offers[e_offer.id] == e_offer
    assert e_offer.energy == 20
    assert e_offer.price == 10
    assert e_offer.seller == 'someone'
    assert len(e_offer.id) == 36


def test_market_bid(market: TwoSidedPayAsBid):
    bid = market.bid(1, 2, 'bidder', 'seller')
    assert market.bids[bid.id] == bid
    assert bid.price == 1
    assert bid.energy == 2