def test_market_unformed_market_list(): market_list = MarketList() market_name1 = 'test_market1' market_name2 = 'test_market2' buyer_participant = MarketParticipant(BUYER, 'agent_id1') market_list.make_reservation(market_name1, buyer_participant) seller_participant = MarketParticipant(SELLER, 'agent_id2') market_list.make_reservation(market_name2, seller_participant) assert market_list.market_count() == 2 unformed_markets = market_list.unformed_market_list() assert len(unformed_markets) > 0
def test_market_participants_market_formed_one_buyer_one_seller(): market_list = MarketList() market_name = 'test_market' buyer_participant = MarketParticipant(BUYER, 'agent_id1') market_list.make_reservation(market_name, buyer_participant) seller_participant = MarketParticipant(SELLER, 'agent_id2') market_list.make_reservation(market_name, seller_participant) assert market_list.market_count() == 1 assert market_list.has_market_formed(market_name) == True unformed_markets = market_list.unformed_market_list() assert len(unformed_markets) == 0
def test_market_participants_market_bad_seller_argument(): market_list = MarketList() market_name = 'test_market' with pytest.raises(ValueError) as error_info: bad_participant = MarketParticipant('bob is cool', 'agent_id') market_list.make_reservation(market_name, bad_participant) assert 'bob is cool' in error_info.value.args[0]
def test_default_config(volttron_instance): """ Test the default configuration file included with the agent """ publish_agent = volttron_instance.build_agent(identity="test_agent") gevent.sleep(1) config_path = os.path.join(get_services_core("MarketServiceAgent"), "config") with open(config_path, "r") as config_file: config_json = json.load(config_file) assert isinstance(config_json, dict) volttron_instance.install_agent( agent_dir=get_services_core("MarketServiceAgent"), config_file=config_json, start=True, vip_identity="health_test") assert publish_agent.vip.rpc.call( "health_test", "health.get_status").get(timeout=10).get('status') == STATUS_GOOD # perform basic sanity check market_name = 'test_market' buyer_participant = MarketParticipant(BUYER, 'agent_id1') publish_agent.vip.rpc.call("health_test", "make_reservation", market_name, buyer_participant.buyer_seller)
def test_market_state_create_has_formed_true(): market_name = 'test_market' market = build_test_machine(market_name, BUYER) participant = MarketParticipant(SELLER, 'agent_id2') market.make_reservation(participant) assert market.has_market_formed()
def build_test_machine(market_name='test_market', buyer_seller=BUYER): participant = MarketParticipant(buyer_seller, 'agent_id') publisher = Publisher() market = Market(market_name, participant, publisher.publish) return market
def test_market_participants_market_not_formed_one_buyer(): market_list = MarketList() market_name = 'test_market' buyer_participant = MarketParticipant(BUYER, 'agent_id') market_list.make_reservation(market_name, buyer_participant) assert market_list.has_market_formed(market_name) == False
def test_market_participants_has_market(): market_list = MarketList() market_name = 'test_market' seller_participant = MarketParticipant(SELLER, 'agent_id') market_list.make_reservation(market_name, seller_participant) assert market_list.has_market(market_name) == True
def accept_offer(self, buyer_seller, identity, market_name, offer): _log.info("Offer on Market: {} {} made by {} was accepted.".format(market_name, buyer_seller, identity)) participant = MarketParticipant(buyer_seller, identity) curve = PolyLineFactory.fromTupples(offer) self.market_list.make_offer(market_name, participant, curve)
def accept_reservation(self, buyer_seller, identity, market_name): _log.info("Reservation on Market: {} {} made by {} was accepted.".format(market_name, buyer_seller, identity)) participant = MarketParticipant(buyer_seller, identity) self.market_list.make_reservation(market_name, participant)
def test_market_participants_market_not_formed_one_seller(): market_list = MarketList() market_name = 'test_market' seller_participant = MarketParticipant(SELLER, 'agent_id') market_list.make_reservation(market_name, seller_participant) assert market_list.has_market_formed(market_name) is False