Beispiel #1
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        Lookup._clear()
        Lookup(network="unittests",
               sports_folder=os.path.join(
                   os.path.dirname(os.path.realpath(__file__)),
                   "bookiesports"),
               peerplays_instance=ppy)
        self.lookup = LookupSport("AmericanFootball")
class Testcases(unittest.TestCase):
    def setUp(self):
        self.lookup.clear_proposal_buffer()
        self.lookup.clear_direct_buffer()

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.lookup = LookupSport("AmericanFootball")
        self.lookup.set_approving_account("init0")

    def test_search_pending_props(self):
        # As defined in bookiesports
        self.assertEqual(self.lookup.id, "1.16.0")

        # Proposal creation
        self.lookup.propose_new()

        props = Lookup.proposal_buffer.json()
        self.assertIsInstance(props, list)
        self.assertIsInstance(props[1], dict)
        self.assertEqual(props[0], 22)
        proposed_op = props[1]["proposed_ops"][0]["op"]
        self.assertEqual(proposed_op[0],
                         operations[self.lookup.operation_create])

        # The id as defined in the yaml file has priority
        self.assertEqual(self.lookup.id, "1.16.0")

        # Let's remove the id from the yaml file to load from chain
        self.lookup.pop("id", None)
        self.assertEqual(self.lookup.id, "1.16.0")

        # Let's also remove the id from chain to look into proposal buffer
        def mockedClass(m, *args, **kwargs):
            return False

        with mock.patch("bookied_sync.sport.LookupSport.find_id",
                        new=mockedClass):
            self.lookup.pop("id", None)
            self.assertEqual(self.lookup.id, "0.0.0")

    def test_approve_proposal_instead(self):
        logging.info("Creating ....")
        self.lookup.update()
        # this is supposed to be an update of the proposal 1.10.1
        tx = self.lookup.direct_buffer
        self.assertEqual(tx["operations"][0][0], 23)
        self.assertEqual(
            tx["operations"][0][1]["proposal"],
            "1.10.1",
        )
        self.assertIn("1.2.7",
                      tx["operations"][0][1]["active_approvals_to_add"])
Beispiel #3
0
    def __init__(self,
                 message,
                 lookup_instance,
                 config,
                 clear_caches=True,
                 **kwargs):
        self.message = message
        self.lookup = lookup_instance
        self.config = config

        # Obtain data for unique key
        # The "id" contains everything we need to identify an individual event
        # which itself contains at least the sport, and the teams

        # Get the id (internally used only)
        self.id = message.get("id")

        # Incident Storage
        if "storage" in kwargs and kwargs["storage"]:
            self.storage = kwargs["storage"]
        else:
            self.storage = factory.get_incident_storage(
                kwargs.get("mongodb", None), purge=kwargs.get("purge", False))

        # Normalize incident
        self.normalizer = IncidentsNormalizer(
            chain=lookup_instance._network_name)
        self.normalize(message)

        # Let's clear the caches for Proposals and events
        # We need to do so because of the internal pypeerplays cache.
        # The cache reduces the API calls to the backend and thus latency.
        # However, to be sure the event hasn't been created since before the
        # cache has expired, we force a refresh from the blockchain.
        if clear_caches:
            Events.clear_cache()
            Proposals.clear_cache()

        # Try obtain the sport
        self.sport = LookupSport(self.id.get("sport"))

        # Given the sport, try to obtain the league (event group)
        self.eventgroup = LookupEventGroup(self.sport,
                                           self.id.get("event_group_name"))

        self.event = None  # Will be filled in after receiving a trigger

        # Get Teams from query
        self.teams = [self.id.get("home"), self.id.get("away")]

        # Get start time from query
        self.start_time = parse(self.id.get("start_time", ""))
Beispiel #4
0
class Testcases(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        Lookup._clear()
        Lookup(network="unittests",
               sports_folder=os.path.join(
                   os.path.dirname(os.path.realpath(__file__)),
                   "bookiesports"),
               peerplays_instance=ppy)
        self.lookup = LookupSport("AmericanFootball")

    def test_update(self):
        self.lookup.blockchain.unlock(UNLOCK)
        self.lookup.set_proposing_account("init0")
        self.lookup.set_approving_account("init1")
        self.lookup.clear_proposal_buffer(1 * 60)
        self.lookup.update()
        reply = self.lookup.broadcast()
        for x in reply:
            pprint(dict(x))
        print([x.get_proposal_id() for x in reply])
Beispiel #5
0
    def __init__(self, message, lookup_instance, config, **kwargs):
        self.message = message
        self.lookup = lookup_instance
        self.config = config

        # Obtain data for unique key
        # The "id" contains everything we need to identify an individual event
        # which itself contains at least the sport, and the teams

        # Get the id (internally used only)
        self.id = message.get("id")

        # Incident Storage
        if "storage" in kwargs and kwargs["storage"]:
            self.storage = kwargs["storage"]
        else:
            self.storage = factory.get_incident_storage(
                kwargs.get("mongodb", None), purge=kwargs.get("purge", False))

        # Normalize incident
        self.normalizer = IncidentsNormalizer(
            chain=lookup_instance._network_name)
        self.normalize(message)

        # Try obtain the sport
        self.sport = LookupSport(self.id.get("sport"))

        # Given the sport, try to obtain the league (event group)
        self.eventgroup = LookupEventGroup(self.sport,
                                           self.id.get("event_group_name"))

        self.event = None  # Will be filled in after receiving a trigger

        # Get Teams from query
        self.teams = [self.id.get("home"), self.id.get("away")]

        # Get start time from query
        self.start_time = parse(self.id.get("start_time", ""))
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.lookup = LookupSport("AmericanFootball")
     self.lookup.set_approving_account("init0")
Beispiel #7
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     fixture_data()
     self.lookup = LookupSport("Basketball")
Beispiel #8
0
class Testcases(unittest.TestCase):

    def setUp(self):
        fixture_data()

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        fixture_data()
        self.lookup = LookupSport("Basketball")

    def test_test_operation_equal(self):
        self.assertTrue(self.lookup.test_operation_equal(test_operation_dict))

        with self.assertRaises(ValueError):
            self.assertTrue(self.lookup.test_operation_equal({}))

    def test_find_id(self):
        self.assertEqual(self.lookup.find_id(), sport_id)

    def test_is_synced(self):
        self.lookup["id"] = sport_id
        self.assertTrue(self.lookup.is_synced())

    def test_propose_new(self):
        from peerplaysbase.operationids import operations
        self.lookup.clear_proposal_buffer()
        tx = self.lookup.propose_new()
        tx = tx.json()
        self.assertIsInstance(tx, dict)
        self.assertIn("operations", tx)
        self.assertIn("ref_block_num", tx)
        self.assertEqual(tx["operations"][0][0], 22)
        self.assertEqual(
            tx["operations"][0][1]["proposed_ops"][0]["op"][0],
            operations[self.lookup.operation_create]
        )

    def test_propose_update(self):
        from peerplaysbase.operationids import operations

        self.lookup["id"] = sport_id
        self.lookup.clear_proposal_buffer()
        tx = self.lookup.propose_update()
        tx = tx.json()
        self.assertIsInstance(tx, dict)
        self.assertIn("operations", tx)
        self.assertIn("ref_block_num", tx)
        self.assertEqual(tx["operations"][0][0], 22)
        self.assertEqual(
            tx["operations"][0][1]["proposed_ops"][0]["op"][0],
            operations[self.lookup.operation_update]
        )

    def test_approve_proposal(self):
        # We need an approver account
        self.lookup.set_approving_account("init0")

        # We need to delete id else, bos-sync will not try to create
        self.lookup["id"] = None
        self.lookup.clear_proposal_buffer()
        tx = self.lookup.propose_new()
        tx = tx.json()
        propops = tx["operations"][0][1]["proposed_ops"][0]["op"]
        Proposals.cache["1.2.1"] = [{
            'available_active_approvals': [],
            'available_key_approvals': [],
            'available_owner_approvals': [],
            'expiration_time': '2018-05-17T15:20:25',
            'id': '1.10.2413',
            'proposed_transaction': {'expiration': '2018-05-17T15:17:48',
                                     'extensions': [],
                                     'operations': [propops],
                                     'ref_block_num': 0,
                                     'ref_block_prefix': 0},
            'proposer': '1.2.8',
            'required_active_approvals': ['1.2.1'],
            'required_owner_approvals': []
        }]
        # import logging
        # logging.basicConfig(level=logging.DEBUG)
        pending_propos = list(self.lookup.has_pending_new())
        self.assertIn(
            pending_propos[0]["pid"],
            self.lookup.approval_map
        )
        self.assertFalse(self.lookup.is_synced())
        self.assertEqual(len(pending_propos), 1)
        self.assertEqual(pending_propos[0]["pid"], "1.10.2413")
        self.lookup.approve(**pending_propos[0])
        self.assertNotIn(
            pending_propos[0]["pid"],
            self.lookup.approval_map
        )
 def test_find_sport(self):
     self.assertEqual(LookupSport("Bsktbll")["identifier"], "Basketball")
     self.assertEqual(LookupSport("BASKETBALL")["identifier"], "Basketball")
     self.assertEqual(LookupSport("askba")["identifier"], "Basketball")
     with self.assertRaises(ObjectNotFoundInLookup):
         LookupSport("NONEXISTING")
 def setUp(self):
     fixture_data()
     self.lookup = LookupSport("Basketball")
class Testcases(unittest.TestCase):
    def setUp(self):
        fixture_data()
        self.lookup = LookupSport("Basketball")

    def test_find_sport(self):
        self.assertEqual(LookupSport("Bsktbll")["identifier"], "Basketball")
        self.assertEqual(LookupSport("BASKETBALL")["identifier"], "Basketball")
        self.assertEqual(LookupSport("askba")["identifier"], "Basketball")
        with self.assertRaises(ObjectNotFoundInLookup):
            LookupSport("NONEXISTING")

    def test_eventgroups(self):
        for i in self.lookup.eventgroups:
            self.assertTrue(isinstance(i, LookupEventGroup))

    def test_rules(self):
        for i in self.lookup.rules:
            self.assertTrue(isinstance(i, LookupRule))

    def test_participants(self):
        for i in self.lookup.participants:
            self.assertTrue(isinstance(i, LookupParticipants))

    def test_test_operation_equal(self):
        self.assertTrue(self.lookup.test_operation_equal(test_operation_dict))

        with self.assertRaises(ValueError):
            self.assertTrue(self.lookup.test_operation_equal({}))

    def test_find_id(self):
        self.assertEqual(self.lookup.find_id(), sport_id)

    def test_is_synced(self):
        self.lookup["id"] = sport_id
        self.assertTrue(self.lookup.is_synced())

    def test_propose_new(self):
        from peerplaysbase.operationids import operations

        self.lookup.clear_proposal_buffer()
        tx = self.lookup.propose_new()
        tx = tx.json()
        self.assertIsInstance(tx, dict)
        self.assertIn("operations", tx)
        self.assertIn("ref_block_num", tx)
        self.assertEqual(tx["operations"][0][0], 22)
        self.assertEqual(
            tx["operations"][0][1]["proposed_ops"][0]["op"][0],
            operations[self.lookup.operation_create],
        )

    def test_propose_update(self):
        from peerplaysbase.operationids import operations

        self.lookup["id"] = sport_id
        self.lookup.clear_proposal_buffer()
        tx = self.lookup.propose_update()
        tx = tx.json()
        self.assertIsInstance(tx, dict)
        self.assertIn("operations", tx)
        self.assertIn("ref_block_num", tx)
        self.assertEqual(tx["operations"][0][0], 22)
        self.assertEqual(
            tx["operations"][0][1]["proposed_ops"][0]["op"][0],
            operations[self.lookup.operation_update],
        )

    def test_approve_proposal(self):
        # We need an approver account
        self.lookup.set_approving_account("init0")

        # We need to delete id else, bos-sync will not try to create
        self.lookup["id"] = None
        self.lookup.clear_proposal_buffer()
        tx = self.lookup.propose_new()
        tx = tx.json()
        propops = tx["operations"][0][1]["proposed_ops"][0]["op"]
        Proposals._import(
            [
                {
                    "available_active_approvals": [],
                    "available_key_approvals": [],
                    "available_owner_approvals": [],
                    "expiration_time": "2018-05-17T15:20:25",
                    "id": "1.10.2413",
                    "proposed_transaction": {
                        "expiration": "2018-05-17T15:17:48",
                        "extensions": [],
                        "operations": [propops],
                        "ref_block_num": 0,
                        "ref_block_prefix": 0,
                    },
                    "proposer": "1.2.8",
                    "required_active_approvals": ["1.2.1"],
                    "required_owner_approvals": [],
                }
            ],
            "1.2.1",
        )
        # import logging
        # logging.basicConfig(level=logging.DEBUG)
        pending_propos = list(self.lookup.has_pending_update(require_witness=False))
        self.assertTrue(len(pending_propos) > 0)
        self.assertIn(pending_propos[0]["pid"], self.lookup.approval_map)
        self.assertFalse(self.lookup.is_synced())
        self.assertEqual(len(pending_propos), 1)
        self.assertEqual(pending_propos[0]["pid"], "1.10.2413")
        self.lookup.approve(**pending_propos[0])
        self.assertNotIn(pending_propos[0]["pid"], self.lookup.approval_map)