def test_incomplete_proposal(self): # Create incidents _message_create_1 = { "timestamp": "2018-03-12T14:48:11.418371Z", "id": { "sport": "Basketball", "start_time": "2022-10-16T00:00:00Z", "away": "Toronto Raptors", "home": "Detroit Pistons", "event_group_name": "NBA Regular Season", }, "provider_info": { "match_id": "1487207", "source_file": "20180310-011131_06d6bc2c-9280-4989-b86c-9f3c9cc716ad.xml", "source": "direct string input", "name": "scorespro", "bitArray": "00000001100", "pushed": "2018-03-10T00:11:31.79Z", }, "unique_string": "2018-03-10t000000z-basketball-nba-regular-season-detroit-pistons-chicago-bulls-create-20172018", "arguments": { "season": "2017/2018" }, "call": "create", } _message_create_2 = deepcopy(_message_create_1) _message_create_2["provider_info"]["name"] += "foobar" _message_create_2["unique_string"] += "foobar" create = CreateTrigger( _message_create_1, lookup_instance=lookup, config=config, storage=self.storage, clear_caches=False, ) with self.assertRaises( bos_incidents.exceptions.EventNotFoundException): create.testConditions(_message_create_1.get("arguments")) receive_incident(_message_create_1) with self.assertRaises(exceptions.InsufficientIncidents): create.trigger(_message_create_1.get("arguments")) receive_incident(_message_create_2) self.assertTrue( create.testConditions(_message_create_1.get("arguments"))) tx = create.trigger(_message_create_1.get("arguments")) ops = tx[0].get("operations") self.assertEqual(len(ops), 1) self.assertEqual(ops[0][0], 23) self.assertEqual(ops[0][1]["proposal"], "1.10.11246") self.assertEqual(ops[0][1]["active_approvals_to_add"][0], "1.2.7")
def test_create(self): # Create incidents _message_create_1 = { "timestamp": "2018-03-12T14:48:11.418371Z", "id": { "sport": "Basketball", "start_time": "2022-10-16T00:00:00Z", "away": "Chicago Bulls", "home": "Detroit Pistons", "event_group_name": "NBA Regular Season" }, "provider_info": { "match_id": "1487207", "source_file": "20180310-011131_06d6bc2c-9280-4989-b86c-9f3c9cc716ad.xml", "source": "direct string input", "name": "scorespro", "bitArray": "00000001100", "pushed": "2018-03-10T00:11:31.79Z" }, "unique_string": "2018-03-10t000000z-basketball-nba-regular-season-detroit-pistons-chicago-bulls-create-20172018", "arguments": { "season": "2017/2018" }, "call": "create" } _message_create_2 = deepcopy(_message_create_1) _message_create_2["provider_info"]["name"] += "foobar" _message_create_2["unique_string"] += "foobar" create = CreateTrigger( _message_create_1, lookup_instance=lookup, config=config, purge=True, mongodb="mongodbtest", ) with self.assertRaises( bos_incidents.exceptions.EventNotFoundException): create.testConditions(_message_create_1.get("arguments")) create.storage.insert_incident(_message_create_1) with self.assertRaises(exceptions.InsufficientIncidents): create.trigger(_message_create_1.get("arguments")) create.storage.insert_incident(_message_create_2) self.assertTrue( create.testConditions(_message_create_1.get("arguments"))) tx = create.trigger(_message_create_1.get("arguments")) self.assertTrue(create.lookup.peerplays.blocking) ops = tx[0].get("operations") self.assertEqual(len(ops), 1) self.assertEqual(ops[0][0], 22) self.assertTrue(len(ops[0][1]["proposed_ops"]) > 1) self.assertTrue(ops[0][1]["proposed_ops"][0]['op'][0], 56) d = create.storage.get_event_by_id(_message_create_1) self.assertEqual(d["create"]["status"]["actions"][0], "proposal") self.assertEqual(d["create"]["status"]["name"], "done")
def test_create(self): # Create incidents _message_create_1 = { "timestamp": "2018-03-12T14:48:11.418371Z", "id": { "sport": "Basketball", "start_time": "2022-10-16T00:00:00Z", "away": "Chicago Bulls", "home": "Detroit Pistons", "event_group_name": "NBA Regular Season" }, "provider_info": { "match_id": "1487207", "source_file": "20180310-011131_06d6bc2c-9280-4989-b86c-9f3c9cc716ad.xml", "source": "direct string input", "name": "scorespro", "bitArray": "00000001100", "pushed": "2018-03-10T00:11:31.79Z" }, "unique_string": "2018-03-10t000000z-basketball-nba-regular-season-detroit-pistons-chicago-bulls-create-20172018", "arguments": { "season": "2017/2018" }, "call": "create" } _message_create_2 = deepcopy(_message_create_1) _message_create_2["provider_info"]["name"] = "foobar" _message_create_2["unique_string"] += "foobar" create = CreateTrigger( _message_create_1, lookup_instance=lookup, config=config, purge=True, mongodb="mongodbtest", ) from bookied import schedule self.mockEvent() with self.assertRaises( bos_incidents.exceptions.EventNotFoundException): create.testConditions(_message_create_1.get("arguments")) create.storage.insert_incident(_message_create_1) with self.assertRaises(exceptions.InsufficientIncidents): create.trigger(_message_create_1.get("arguments")) create.storage.insert_incident(_message_create_2) self.assertTrue( create.testConditions(_message_create_1.get("arguments"))) with self.assertRaises(exceptions.EventCannotOpenException): create.trigger(_message_create_1.get("arguments")) # From here on, we should have a 'postponed' incident in database events = create.storage.get_events_by_call_status( call="create", status_name="postponed", status_expired_before=datetime.utcnow()) events = list(events) self.assertEqual(len(events), 1) """ class MockReturn: id = "foobar" Queue.enqueue = MagicMock(return_value=MockReturn) ret = schedule.check_scheduled(storage=create.storage, func_callback=print) self.assertIn("foobar", ret) self.assertTrue(Queue.enqueue.called) """ self.mockEvent(True) tx = create.trigger(_message_create_1.get("arguments")) ops = tx[0].get("operations") self.assertEqual(len(ops), 1) self.assertEqual(ops[0][0], 22) self.assertTrue(len(ops[0][1]["proposed_ops"]) > 1) self.assertTrue(ops[0][1]["proposed_ops"][0]['op'][0], 56)