def test_ranked_sites_dict_disabled(): db = MaigretDatabase() db.update_site(MaigretSite('1', {'disabled': True})) db.update_site(MaigretSite('2', {})) assert len(db.ranked_sites_dict()) == 2 assert len(db.ranked_sites_dict(disabled=False)) == 1
def test_ranked_sites_dict(): db = MaigretDatabase() db.update_site(MaigretSite('3', {'alexaRank': 1000, 'engine': 'ucoz'})) db.update_site(MaigretSite('1', {'alexaRank': 2, 'tags': ['forum']})) db.update_site(MaigretSite('2', { 'alexaRank': 10, 'tags': ['ru', 'forum'] })) # sorting assert list(db.ranked_sites_dict().keys()) == ['1', '2', '3'] assert list(db.ranked_sites_dict(top=2).keys()) == ['1', '2'] assert list(db.ranked_sites_dict(reverse=True, top=2).keys()) == ['3', '2'] # filtering by tags assert list(db.ranked_sites_dict(tags=['ru'], top=2).keys()) == ['2'] assert list(db.ranked_sites_dict(tags=['forum']).keys()) == ['1', '2'] # filtering by engine assert list(db.ranked_sites_dict(tags=['ucoz']).keys()) == ['3'] # disjunction assert list(db.ranked_sites_dict(names=['2'], tags=['forum']).keys()) == ['2'] assert list(db.ranked_sites_dict(names=['2'], tags=['ucoz']).keys()) == [] assert list(db.ranked_sites_dict(names=['4'], tags=['ru']).keys()) == [] # reverse assert list(db.ranked_sites_dict(reverse=True).keys()) == ['3', '2', '1']
def test_ranked_sites_dict_id_type(): db = MaigretDatabase() db.update_site(MaigretSite('1', {})) db.update_site(MaigretSite('2', {'type': 'username'})) db.update_site(MaigretSite('3', {'type': 'gaia_id'})) assert len(db.ranked_sites_dict()) == 2 assert len(db.ranked_sites_dict(id_type='username')) == 2 assert len(db.ranked_sites_dict(id_type='gaia_id')) == 1
def test_ranked_sites_dict_names(): db = MaigretDatabase() db.update_site(MaigretSite('3', {'alexaRank': 30})) db.update_site(MaigretSite('1', {'alexaRank': 2})) db.update_site(MaigretSite('2', {'alexaRank': 10})) # filtering by names assert list(db.ranked_sites_dict(names=['1', '2']).keys()) == ['1', '2'] assert list(db.ranked_sites_dict(names=['2', '3']).keys()) == ['2', '3']
def test_get_url_template(): site = MaigretSite( "test", { "urlMain": "https://ya.ru/", "url": "{urlMain}{urlSubpath}/members/?username={username}", }, ) assert ( site.get_url_template() == "{urlMain}{urlSubpath}/members/?username={username} (no engine)" ) site = MaigretSite( "test", { "urlMain": "https://ya.ru/", "url": "https://{username}.ya.ru", }, ) assert site.get_url_template() == "SUBDOMAIN"