async def arrange(self) -> Sequence[beacons.BeaconBase]: b1 = common.create_beacon() b2 = common.create_beacon(game_name="usf4", waiting_time=6.0, platform_name="pc") b2.user_id = "DUMMY" return [b1, b2]
async def arrange(self) -> Sequence[beacons.BeaconBase]: return [ common.create_beacon(), common.create_beacon(game_name="mk11", waiting_time=6.0, platform_name="ps4") ]
async def arrange(self) -> Sequence[beacons.BeaconBase]: b1 = common.create_beacon() b2 = common.create_beacon(game_name="mk11", waiting_time=6.0, platform_name="ps4") b2._start_datetime = datetime.datetime.now(datetime.timezone.utc) b2._start_datetime -= datetime.timedelta(hours=1) b2.minutes_available = 15 return [b1, b2]
def test_full_equality(self): start_time = datetime.datetime.now(datetime.timezone.utc) \ .replace(microsecond=0) b1 = common.create_beacon(start=start_time) b2 = common.create_beacon(start=start_time) wait_time = beacons.WaitTime.from_minutes(60) b3 = beacons.BeaconBase.with_wait_time(beacon=b2, wait_time=wait_time) actual1 = b1.full_equality(b2) actual2 = b2.full_equality(b3) self.assertTrue(actual1) self.assertFalse(actual2)
def test_beacons_from_items(self): b1, now = common.create_beacon_and_now_datetime() b2 = common.create_beacon(game_name="mk11", waiting_time=6.0, platform_name="pc", start=now) items = [{ "UniqueId": f"1234567890-st-pc-{b1.start_timestamp}", "TypeName": "Beacon", "GameName": "st", "PlatformName": "pc", "GamePlatformCombination": "st-pc", "StartTime": b1.start_timestamp, "EndTime": b1.end_timestamp, "UserId": "1234567890", "Username": "******" }, { "UniqueId": f"1234567890-mk11-pc-{b2.start_timestamp}", "TypeName": "Beacon", "GameName": "mk11", "PlatformName": "pc", "GamePlatformCombination": "mk11-pc", "StartTime": b2.start_timestamp, "EndTime": b2.end_timestamp, "UserId": "1234567890", "Username": "******" }] beacons = beacondb.beacons_from_items(items) actual1 = b1.full_equality(beacons[0]) actual2 = b2.full_equality(beacons[1]) self.assertTrue(actual1 and actual2)
def test_items_from_beacons(self): b1, now = common.create_beacon_and_now_datetime() b2 = common.create_beacon(game_name="mk11", waiting_time=6.0, platform_name="pc", start=now) expected1 = { "UniqueId": f"1234567890-st-pc-{b1.start_timestamp}", "TypeName": "Beacon", "GameName": "st", "PlatformName": "pc", "GamePlatformCombination": "st-pc", "StartTime": b1.start_timestamp, "EndTime": b1.end_timestamp, "UserId": "1234567890", "Username": "******" } expected2 = { "UniqueId": f"1234567890-mk11-pc-{b2.start_timestamp}", "TypeName": "Beacon", "GameName": "mk11", "PlatformName": "pc", "GamePlatformCombination": "mk11-pc", "StartTime": b2.start_timestamp, "EndTime": b2.end_timestamp, "UserId": "1234567890", "Username": "******" } actual = beacondb.items_from_beacons([b1, b2]) self.assertEqual(actual, [expected1, expected2])
def test_create(self): test_cases = [ (([ common.create_beacon("sfv", 1.5, "pc"), common.create_beacon("st", 12.5, "ps4") ], "All SFV"), "`WP Matchmaking\n" "All SFV Beacons\n" "\n" "ЁЯПо SFV Test Dummy Name 1h 29m XPLAY\n" "ЁЯПо ST Test Dummy Name 12h 29m PS4 \n`" ), ] for case, expected in test_cases: with self.subTest(case=case): beacons, title = case actual = matchmaking.GamesList.create(beacons=beacons, title=title) self.assertEqual(expected, actual)
def test_with_wait_time(self): start_time = datetime.datetime.now(datetime.timezone.utc) \ .replace(microsecond=0) beacon = common.create_beacon(start=start_time) minutes = 15 wait_time = beacons.WaitTime.from_minutes(minutes) delta = datetime.timedelta(minutes=minutes) expected_end_timestamp = (start_time + delta).timestamp() actual = beacons.BeaconBase.with_wait_time(beacon, wait_time) self.assertEqual(beacon, actual) # checking equality for non-time attr self.assertEqual(expected_end_timestamp, actual.end_timestamp)
def test_entry(self): test_cases = [ ( common.create_beacon("st", 12.0, "pc"), "ЁЯПо ST Test Dummy Name 11h 59m PC \n" ), ] for case, expected in test_cases: with self.subTest(case=case): sut = matchmaking.GamesList() actual = sut.entry(case) self.assertEqual(expected, actual)
def test_start_timestamp_and_end_timestamp(self): dt = datetime.datetime(2021, 1, 1, 1, 0, 0, tzinfo=datetime.timezone.utc) delta = datetime.timedelta(seconds=3600.0) start_timestamp = dt.timestamp() end_timestamp = (dt + delta).timestamp() beacon = common.create_beacon(start=dt, waiting_time=1.0) start_actual = beacon.start_timestamp end_actual = beacon.end_timestamp self.assertEqual(start_timestamp, start_actual) self.assertEqual(end_timestamp, end_actual)
def test_item_from_beacon(self): beacon = common.create_beacon() expected = { "UniqueId": f"1234567890-st-pc-{beacon.start_timestamp}", "TypeName": "Beacon", "GameName": "st", "PlatformName": "pc", "GamePlatformCombination": "st-pc", "StartTime": beacon.start_timestamp, "EndTime": beacon.end_timestamp, "UserId": "1234567890", "Username": "******" } actual = beacondb._item_from_beacon(beacon) self.assertTrue(actual == expected)
def test_from_dict(self): start_time = datetime.datetime.now(datetime.timezone.utc) expected = common.create_beacon(start=start_time) beacon_dict = { "user_id": expected.user_id, "username": expected.username, "game": beacons.Game.from_str(expected.game_name), "wait_time": beacons.WaitTime.from_float(expected.minutes_available / 60), "platform": beacons.Platform.from_str(expected.platform), "start": expected._start_datetime } beacon = beacons.BeaconBase.from_dict(beacon_dict) actual = expected.full_equality(beacon) self.assertTrue(actual)
def test___eq___compare_user_id_returns_false(self): b1 = common.create_beacon() b2 = beacons.BeaconBase.from_dict({ "user_id": 123456789, "username": "******", "game": beacons.Game.from_str("st"), "wait_time": beacons.WaitTime.from_float(12.0), "platform": beacons.Platform.from_str("pc"), "start": datetime.datetime.fromtimestamp(b1.start_timestamp, datetime.timezone.utc) }) actual = b1 == b2 self.assertFalse(actual)
async def arrange(self) -> beacons.BeaconBase: return common.create_beacon()
def test_list_by_user_id_does_not_throw(self): try: beacon = common.create_beacon() beacondb.DynamoDbQueryParams.list_by_user_id(beacon) except Exception: self.fail("list_by_user_id() raised an exception.")