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", } create = CreateTrigger( _message_create_1, lookup_instance=lookup, config=config, storage=self.storage, clear_caches=False, ) event = create.getIncidentEvent() self.assertEqual(str(event.can_open_by), "2018-02-19 00:00:00") self.assertTrue(event.can_open)
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_unnormalize_incident(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": "NBAREGULARSEASON", }, "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", } # Let's insert the valid incident # receive_incident(_message_create_1) # Let's fake a broken one _message_create_2 = deepcopy(_message_create_1) _message_create_2["id"]["event_group_name"] = "Foobar" _message_create_2["unique_string"] += "Foobar" # We insert the broken one manually because it would fail normalization storage.insert_incident(_message_create_2) # ... it fails here with self.assertRaises(NotNormalizableException): CreateTrigger( _message_create_2, lookup_instance=lookup, config=config, storage=self.storage, clear_caches=False, ) # ... and here with self.assertRaises(NotNormalizableException): receive_incident(_message_create_2) # Let's obtain the event event = storage.get_event_by_id(_message_create_2) # The create shoudl have a certain status self.assertEqual(event["create"]["status"]["name"], "not normalizable")
def test_old(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" } create = CreateTrigger( _message_create_1, lookup_instance=lookup, config=config, purge=True, mongodb="mongodbtest", ) with self.assertRaises(exceptions.EventDoesNotExistException): create.getEvent() with self.assertRaises(exceptions.EventCannotOpenException): create.createEvent() with self.assertRaises(exceptions.EventCannotOpenException): create.getIncidentEvent() self.assertEqual(str(create.event.can_open_by), "2022-10-14 00:00:00") self.assertFalse(create.event.can_open) now = int(time.mktime(datetime.utcnow().timetuple())) expiration_time = create.event.can_open_by + timedelta(seconds=(now % 120)) self.assertLessEqual(expiration_time, create.event.can_open_by + timedelta(seconds=120)) self.assertGreaterEqual(expiration_time, create.event.can_open_by)
def test_create(self): # Create incidents _message_create_1 = { "timestamp": "2018-03-12T14:48:11.418371Z", "id": { "sport": "Basketball", "start_time": "2014-10-16T00:00:00Z", "away": "Chicago Bulls", "home": "Detroit Pistons", "event_group_name": "NBA OLD" }, "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" } create = CreateTrigger( _message_create_1, lookup_instance=lookup, config=config, purge=True, mongodb="mongodbtest", ) with self.assertRaises(exceptions.CreateIncidentTooOldException): create.testConditions(_message_create_1.get("arguments"))
def test_unnormalize_incident(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": "NBAREGULARSEASON", }, "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["id"]["event_group_name"] = "Foobar" storage.insert_incident(_message_create_2) with self.assertRaises(NotNormalizableException): create = CreateTrigger( _message_create_2, lookup_instance=lookup, config=config, storage=storage, ) event = storage.get_event_by_id(_message_create_2) self.assertEqual(event["create"]["status"]["name"], "not normalizable")
def test_duplicate_incident(self): _message_duplicate = { "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", } receive_incident(_message_duplicate) CreateTrigger( _message_duplicate, lookup_instance=lookup, config=config, storage=self.storage, clear_caches=False, ) with self.assertRaises( bos_incidents.exceptions.DuplicateIncidentException): receive_incident(_message_duplicate)
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)