def test_Sport_init(self): with self.assertRaises(exceptions.SportDoesNotExistException): Sport("1.{}.99999999999".format(Sport.type_id)) def get_object(self, *args, **kwargs): return {"id": "1.{}.0".format(Sport.type_id)} with mock.patch("peerplaysapi.node.PeerPlaysNodeRPC.get_object", new=get_object): s = Sport("1.{}.0".format(Sport.type_id)) self.assertIsInstance(s.eventgroups, list)
def eventgroups(ctx, sport): """ [bookie] List event groups for a sport :param str sport: Sports id """ sport = Sport(sport, peerplays_instance=ctx.peerplays) click.echo(pretty_print(sport.eventgroups, ctx=ctx))
def getSportAsList(self, name): try: sport = Sport(name, peerplays_instance=self.get_node()) return [(sport["id"], sport["name"][0][1])] except Exception as ex: raise NodeException("EventGroups could not be loaded: {}".format( self._get_exception_message(ex)))
def is_synced(self): """ Test if data on chain matches lookup """ if "id" in self and self["id"]: sport = Sport(self["id"]) if self.test_operation_equal(sport): return True return False
def list(ctx, sport): """ [bookie] list the entire thing """ from .ui import maplist2dict from tqdm import tqdm from treelib import Node, Tree tree = Tree() tree.create_node("sports", "root") def formatname(o): if "name" in o: name = o.get("name") elif "description" in o: name = o.get("description") else: name = [] return "{} ({})".format( maplist2dict(name).get("en"), o["id"] ) if sport: sports = [Sport(sport, peerplays_instance=ctx.peerplays)] else: sports = Sports() for sport in tqdm(sports): tree.create_node( formatname(sport), sport["id"], parent="root") for eg in tqdm(sport.eventgroups): tree.create_node( formatname(eg), eg["id"], parent=sport["id"]) for e in tqdm(eg.events): tree.create_node( formatname(e), e["id"], parent=eg["id"]) for bmg in tqdm(e.bettingmarketgroups): tree.create_node( formatname(bmg), bmg["id"], parent=e["id"]) for bm in tqdm(bmg.bettingmarkets): tree.create_node( formatname(bm), bm["id"], parent=bmg["id"]) tree.show()
def getSport(self, name): try: # select sport sport = Sport(name, peerplays_instance=self.get_node()) # create wrappe return wrapper.Sport(**dict(sport)) except Exception as ex: raise NodeException("Sport (id={}) could not be loaded: {}".format( name, self._get_exception_message(ex)))
def fixture_data(): peerplays.clear() BettingMarkets.clear_cache() Rules.clear_cache() BettingMarketGroups.clear_cache() Proposals.clear_cache() Witnesses.clear_cache() Events.clear_cache() EventGroups.clear_cache() Sports.clear_cache() with open(os.path.join(os.path.dirname(__file__), "fixtures.yaml")) as fid: data = yaml.safe_load(fid) [Account(x) for x in data.get("accounts", [])] [Account(x).store(x, "name") for x in data.get("accounts", [])] Witnesses.cache_objects([Witness(x) for x in data.get("witnesses", [])]) Sports.cache_objects([Sport(x) for x in data.get("sports", [])]) EventGroups.cache_objects( [EventGroup(x) for x in data.get("eventgroups", [])]) Events.cache_objects([Event(x) for x in data.get("events", [])]) BettingMarketGroups.cache_objects( [BettingMarketGroup(x) for x in data.get("bettingmarketgroups", [])]) BettingMarkets.cache_objects( [BettingMarket(x) for x in data.get("bettingmarkets", [])]) Rules.cache_objects([Rule(x) for x in data.get("rules", [])]) [Bet(x) for x in data.get("bets", [])] proposals = [] for proposal in data.get("proposals", []): ops = list() for _op in proposal["operations"]: for opName, op in _op.items(): ops.append([operations[opName], op]) # Proposal! proposal_id = proposal["proposal_id"] proposal_data = { "available_active_approvals": [], "available_key_approvals": [], "available_owner_approvals": [], "expiration_time": "2018-05-29T10:23:13", "id": proposal_id, "proposed_transaction": { "expiration": "2018-05-29T10:23:13", "extensions": [], "operations": ops, "ref_block_num": 0, "ref_block_prefix": 0, }, "proposer": "1.2.7", "required_active_approvals": ["1.2.1"], "required_owner_approvals": [], } proposals.append(Proposal(proposal_data)) Proposals.cache_objects(proposals, "1.2.1") Proposals.cache_objects(proposals, "witness-account")
def getEventGroups(sport_id): event_groups = Sport(sport_id, peerplays_instance=ppy) # TODO add pagination return event_groups.eventgroups
def getSport(sport_id): return Sport(sport_id, peerplays_instance=ppy)