def test_Event_init(self): with self.assertRaises(exceptions.EventDoesNotExistException): Event("1.{}.99999999999".format(Event.type_id)) def get_object(self, *args, **kwargs): return { "id": "1.{}.0".format(Event.type_id), "event_group_id": "1.{}.0".format(EventGroup.type_id) } with mock.patch("peerplaysapi.node.PeerPlaysNodeRPC.get_object", new=get_object): event = Event("1.{}.0".format(Event.type_id)) self.assertIsInstance(event.eventgroup, EventGroup)
def bmgs(ctx, event): """ [bookie] List betting market groups for an event :param str event: Event id """ eg = Event(event, peerplays_instance=ctx.peerplays) click.echo(pretty_print(eg.bettingmarketgroups, ctx=ctx))
def cancel_event(ctx, eventids): for eventid in eventids: Event(eventid) ctx.blockchain.event_update_status( eventid, "canceled", ) click.echo(ctx.broadcast())
def is_synced(self): """ Test if data on chain matches lookup """ if "id" in self and self["id"]: event = Event(self["id"]) if self.test_operation_equal(event): return True return False
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 __init__( self, teams, eventgroup_identifier, # not actually required, FIXME cleanup sport_identifier, # not actually required, FIXME cleanup season={}, start_time=None, id=None, extra_data={}, **kwargs): Lookup.__init__(self) # First try to load the data from the blockchain if id is present if id and len(id.split(".")) == 3: dict.update(self, dict(Event(id))) # Also store all the stuff in kwargs dict.__init__(self, extra_data) dict.update( self, { "teams": teams, "eventgroup_identifier": eventgroup_identifier, "sport_identifier": sport_identifier, "season": season, "start_time": start_time, "id": id, }, ) # Define "id" if not present self["id"] = self.get("id", None) if not len(self["teams"]) == 2: raise ValueError("Only matches with two players are allowed! " "Here: {}".format(str(self["teams"]))) self.parent = self.eventgroup self.identifier = "{}/{}/{}".format(self.parent["name"]["en"], teams[0], teams[1]) if start_time and not isinstance(self["start_time"], datetime): raise ValueError( "'start_time' must be instance of datetime.datetime()") else: # remove offset self["start_time"] = self["start_time"].replace(tzinfo=None) if not isinstance(self["season"], dict): raise ValueError("'season' must be (language) dictionary") if not self.test_teams_valid(): raise ValueError("Team names not known: {}".format( str(self["teams"]))) # Initialize name key dict.update(self, dict(name=dList2Dict(self.names)))
def getBettingMarketGroups(event_id): bmgs = Event(event_id, peerplays_instance=ppy) # TODO add pagination return bmgs.bettingmarketgroups
def getEvent(event_id): return Event(event_id, peerplays_instance=ppy)
def getEvent(self, eventId): try: return Event(eventId, peerplays_instance=self.get_node()) except Exception as ex: raise NodeException("Event could not be loaded: {}".format( self._get_exception_message(ex)))
def is_synced(self): """ Test if data on chain matches lookup """ event = Event(self["event"]["id"]) if event["status"] == self["status"]: return True