Exemple #1
0
def test_get_key_info():
    key_data_1 = {"machine_name": "g1", "human_name": 'G1'}
    key_data_2 = {"machine_name": "g2", "human_name": 'G2'}
    key_data_3 = {"machine_name": "g3", "human_name": 'G3'}
    orders = [
        {
            'product': {
                'category': 'bundle'
            },
            'tpkd_dict': {
                'all_tpks': [key_data_1, key_data_2]
            }
        },
        {
            'product': {
                'category': 'storefront'
            },
            'tpkd_dict': {
                'all_tpks': [key_data_3]
            }
        },
    ]
    assert LibraryResolver._get_key_infos(orders) == [
        KeyInfo(Key(key_data_1), 'bundle'),
        KeyInfo(Key(key_data_2), 'bundle'),
        KeyInfo(Key(key_data_3), 'storefront'),
    ]
def test_key_properties(origin_bundle_order):
    all_tpks = origin_bundle_order['tpkd_dict']['all_tpks']
    for key_data in all_tpks:
        key = Key(key_data)
        key.key_type
        key.key_val
        key.downloads
        key.in_galaxy_format()
Exemple #3
0
 def _get_keys(orders: list, show_revealed_keys: bool) -> List[KeyGame]:
     keys = []
     for details in orders:
         for tpks in details['tpkd_dict']['all_tpks']:
             key = Key(tpks)
             try:
                 key.in_galaxy_format()  # minimal validation
             except Exception as e:
                 logger.warning(f"Error while parsing tpks {repr(e)}: {tpks}", extra={'tpks': tpks})
             else:
                 if key.key_val is None or show_revealed_keys:
                     keys.extend(key.key_games)
     return keys
Exemple #4
0
 def _get_key_infos(orders: list) -> List[KeyInfo]:
     keys = []
     for details in orders:
         for tpks in details['tpkd_dict']['all_tpks']:
             key = Key(tpks)
             try:
                 key.in_galaxy_format()  # minimal validation
                 product_category = details['product']['category']
             except Exception as e:
                 logger.warning(f"Error while parsing tpks {repr(e)}: {tpks}", extra={'tpks': tpks})
                 continue
             else:
                 keys.append(KeyInfo(key, product_category))
     return keys
def test_key_game_human_name_not_changed():
    tpks = {
        'machine_name': 'tor',
        'human_name': 'Tor Steam',
        'key_type_human_name': 'Steam'
    }
    assert KeyGame(Key(tpks), 'tor', 'Tor Steam').human_name == 'Tor Steam'
Exemple #6
0
def get_torchlight(orders_keys):
    for i in orders_keys:
        if i['product']['machine_name'] == 'torchlight_storefront':
            torchlight_order = i
    drm_free = Subproduct(torchlight_order['subproducts'][0])
    key = Key(torchlight_order['tpkd_dict']['all_tpks'][0])
    return torchlight_order, drm_free, key
def test_key_key_games_one_game():
    """Most common case where 1 key == 1 game"""
    key = Key({
        "machine_name": "ww",
        "human_name": "The Witcher",
        "key_type_human_name": "Steam Key"
    })
    assert key.key_games == [KeyGame(key, "ww", "The Witcher (Steam Key)")]
Exemple #8
0
 def __init__(self, id: str, data: dict):
     self.id = id
     self.title = data['title']
     self.display_item_machine_name = data['display_item_machine_name']
     self.tpkds = [Key(tpkd) for tpkd in data.get('tpkds', [])]
     self.delivery_methods: t.List[DeliveryMethod] = [
         DeliveryMethod(m) for m in data['delivery_methods']
     ]
     self.platforms: t.List[HP] = [HP(p) for p in data['platforms']]
Exemple #9
0
def test_is_multigame_key(human_name, category, blacklist, is_multigame):
    """Most common case where 1 key == 1 game"""
    key = Key({
        "machine_name": "mock_machine_name",
        "human_name": human_name,
        "key_type_human_name": "Steam Key"
    })
    assert LibraryResolver._is_multigame_key(key, category,
                                             blacklist) == is_multigame
def test_strip_from_key(sensitive_logger, caplog):
    key_val = "ABCD-EDGH-IJKL"
    data = {
        "machine_name": "dead_space_origin_key",
        "human_name": "Dead Space Origin Key",
        "redeemed_key_val": key_val
    }
    key = Key(data)
    logging.error(key)
    assert key_val not in caplog.text
    assert key.key_val == key_val  # logger doesnt affect actual data
 def _get_keys(orders: list, show_revealed_keys: bool) -> List[Key]:
     keys = []
     for details in orders:
         for tpks in details['tpkd_dict']['all_tpks']:
             try:
                 key = Key(tpks)
             except Exception as e:
                 logging.warning(f"Error while parsing keys {e}: {tpks}")
             else:
                 if key.key_val is None or show_revealed_keys:
                     keys.append(key)
     return keys
def test_key_split_key_games():
    tpks = {
        "machine_name":
        "sega",
        "human_name":
        "Alpha Protocol, Company of Heroes, Rome: Total War, Hell Yeah! Wrath of the Dead Rabbit",
    }
    key = Key(tpks)
    assert key.key_games == [
        KeyGame(key, "sega_0", "Alpha Protocol"),
        KeyGame(key, "sega_1", "Company of Heroes"),
        KeyGame(key, "sega_2", "Rome: Total War"),
        KeyGame(key, "sega_3", "Hell Yeah! Wrath of the Dead Rabbit")
    ]
Exemple #13
0
def test_split_multigame_key():
    tpks = {
        "machine_name":
        "sega",
        "human_name":
        "Alpha Protocol, Company of Heroes, Rome: Total War, Hell Yeah! Wrath of the Dead Rabbit",
    }
    key = Key(tpks)
    assert LibraryResolver._split_multigame_key(key) == [
        KeyGame(key, "sega_0", "Alpha Protocol"),
        KeyGame(key, "sega_1", "Company of Heroes"),
        KeyGame(key, "sega_2", "Rome: Total War"),
        KeyGame(key, "sega_3", "Hell Yeah! Wrath of the Dead Rabbit")
    ]
def test_strip_extra_game_key(sensitive_logger, caplog):
    """Extra arguments are used also by sentry.io"""
    key_val = "ABCD-EDGH-IJKL"
    data = {
        "machine_name": "dead_space_origin_key",
        "human_name": "Dead Space Origin Key",
        "redeemed_key_val": key_val
    }
    key = Key(data)
    logging.error("some text", extra={'game': key})
    for record in caplog.records:
        if hasattr(record, "game"):
            assert record.game.key_val != key_val
            assert record.game._data['redeemed_key_val'] != key_val
    # logger doesnt affect actual data
    assert key._data['redeemed_key_val'] == key_val
    assert key.key_val == key_val
def test_key_key_game_data():
    tpks = {"machine_name": "ww", "human_name": "The Witcher, The Witcher 2"}
    key = Key(tpks)
    assert tpks == KeyGame(key, 'ww', 'sth')._data