<filename>test_riot_api_consumer.py
from riot_api_consumer import *
import os

    
@pytest.fixture()
def get_api_key():
    """
    You can use the method below. But for this,
    a file with riot_api.txt name needed be 
    created in the root path.
    with open('riot_api_key.txt', 'r') as key:
        return key.read()
    The file need contain only the api key information.
    """
    return os.environ.get('RIOT_API_KEY')
    
    
@pytest.fixture()
def summoner_Ieko():
    """
    Summoner Name: Ieko
    Region: Brazil
    """
    return {
        'summoner_name': 'Ieko',
        'summoner_region': 'br1',
        }


@pytest.fixture()
def summoner_ilha_nublar():
    """
    Summoner Name: <NAME>
    Region: Brazil
    """
    return {
        'summoner_name': '<NAME>',
        'summoner_region': 'br1',
        'tft_get_matches_by_summoner': [
            'BR1_1882323432',
            'BR1_1775035230',
            'BR1_1770334549',
            'BR1_1770273342',
            'BR1_1769520122'
        ]
    }
    

@pytest.fixture()
def league_id_list():
    """
    List with League IDs
    """
    return [
        'd55538c0-4f00-4eb6-a8ca-8ffe98517751',
        '2dfb0f02-ef1c-4552-ab16-9193748646f5',
        '881301bb-d573-4e3a-87cf-db652f33bc91',
    ]


def test_init_session(get_api_key, summoner_ilha_nublar):
    """
    Testing init session
    Summoner Name: lha Nublar profile.
    """
    api_key = get_api_key
    ilha_nublar = summoner_ilha_nublar
    api = new_api(api_key, ilha_nublar['summoner_region'],
                            ilha_nublar['summoner_name']) 
    assert api.api_session['id'] == '5AtW4neaL009Zy-<KEY>'
    
    
def test_get_summoner_profile(get_api_key, summoner_ilha_nublar):
    """
    Testing the consume of /tft/summoner/v1/summoners/by-account/{encryptedAccountId}
    Summoner Name: <NAME>
    """
    api_key = get_api_key
    ilha_nublar = summoner_ilha_nublar
    api = new_api(api_key, ilha_nublar['summoner_region'], 
                           ilha_nublar['summoner_name'])
    tft = api.TFT.get_summoner_profile()
    assert tft['id'] =='<KEY>'
    
    
def test_get_matches_by_summoner(get_api_key, summoner_ilha_nublar):
    """
    Testing the consume of /tft/match/v1/matches/by-puuid/{puuid}/ids
    Summoner Name: <NAME>
    """
    api_key = get_api_key
    ilha_nublar = summoner_ilha_nublar
    api = new_api(api_key, ilha_nublar['summoner_region'],
                           ilha_nublar['summoner_name'])
    tft = api.TFT.get_matches_by_summoner(20)
    for match in ilha_nublar['tft_get_matches_by_summoner']:
        assert match in tft
        
    
def test_get_match_by_match_id_metadata_participants(get_api_key, summoner_ilha_nublar):
    """
    Testing the consume of /tft/match/v1/matches/{matchId}
    Summoner Name: <NAME>
    """
    api_key = get_api_key
    ilha_nublar = summoner_ilha_nublar
    api = new_api(api_key, ilha_nublar['summoner_region'],
                           ilha_nublar['summoner_name'])
    tft = api.TFT.get_match_by_match_id(ilha_nublar['tft_get_matches_by_summoner'][0])
    assert tft['metadata']['participants'] == [
            "<KEY>",
            "<KEY>",
            "<KEY>",
            "<KEY>",
            "<KEY>",
            "fi570nWOGW6lJC0NaSWDMgTuXvD5Yl138zbO6FxLA0hhPgkp8LmeHALc-I6gIT4pzRW6Q1eFDHElAg",
            "oGymNs7Q9VpVdankY3Cq25C2r-sCPCM5-DN8drSa-MZ-qonpLlAKk1xIIQ_oy9SSmF9P1oUTPdZVug",
            "lPRGWj6euSdVWOKLMtPFWt4ah8N1SZJCRhRkzrfZmfrqDfllK1lwBQW87iFbc9LbGHtzyw097lMnww"
        ]
    
    
def test_get_match_by_match_id_info_game_datetime(get_api_key, summoner_ilha_nublar):
    """
    Testing the consume of /tft/match/v1/matches/{matchId}
    Summoner Name: <NAME>
    """
    api_key = get_api_key
    ilha_nublar = summoner_ilha_nublar
    api = new_api(api_key, ilha_nublar['summoner_region'],
                           ilha_nublar['summoner_name'])
    tft = api.TFT.get_match_by_match_id(ilha_nublar['tft_get_matches_by_summoner'][0])
    assert tft['info']['game_datetime'] == 1584585338593
    

def test_get_challenger_league(get_api_key):
    """
    Testing the consume of /tft/league/v1/challenger
    """
    api_key = get_api_key
    api = new_api(api_key)
    tft = api.TFT.get_challenger_league()
    assert tft['tier'] == 'CHALLENGER'
    assert tft['queue'] == 'RANKED_TFT'
    

def test_get_grandmaster_league(get_api_key):
    """
    Testing the consume of /tft/league/v1/grandmaster
    """
    api_key = get_api_key
    api = new_api(api_key)
    tft = api.TFT.get_grandmaster_league()
    assert tft['tier'] == 'GRANDMASTER'
    assert tft['queue'] == 'RANKED_TFT'
    

def test_get_master_league(get_api_key):
    """
    Testing the consume of /tft/league/v1/master
    """
    api_key = get_api_key
    api = new_api(api_key)
    tft = api.TFT.get_master_league()
    assert tft['tier'] == 'MASTER'
    assert tft['queue'] == 'RANKED_TFT'
    
    
def test_get_player_ranked_status(get_api_key, summoner_Ieko):
    """
    Testing the consume of /tft/league/v1/entries/by-summoner/{encryptedSummonerId}
    Summoner Name: Ieko
    Region: Brazil
    """
    api_key = get_api_key
    leko = summoner_Ieko
    api = new_api(api_key, leko['summoner_region'],
                        leko['summoner_name'])
    tft = api.TFT.get_player_ranked_status()
    assert tft[0]['queueType'] == 'RANKED_TFT'
    assert tft[0]['summonerId'] == 'bbYwQtET_GWwodvvxU3i5DEEXsdF3ujtDWfmMTldpfKG3g'
    

def test_get_leagues_by_ranking(get_api_key):
    """
    Testing the consume of /tft/league/v1/entries/{tier}/{division}
    In this case, you need inform tier:
        DIAMOND, PLATINUM, GOLD, SILVER, BRONZE or IRON
    and division:
        I, II, III, IV
    """
    api_key = get_api_key
    api = new_api(api_key)
    tft = api.TFT.get_leagues_by_ranking('DIAMOND', 'I')
    assert tft[0]['queueType'] == 'RANKED_TFT'
    assert tft[0]['tier'] == 'DIAMOND'
    assert tft[0]['rank'] == 'I'
    

def test_get_league_details_by_league_id(get_api_key, league_id_list):
    """
    Testing the consume of /tft/league/v1/leagues/{leagueId}
    """
    api_key = get_api_key
    api = new_api(api_key)
    league_list = league_id_list
    for league_id in league_list:
        tft = api.TFT.get_league_details_by_league_id(league_id)
        assert tft['leagueId'] == league_id