@@ -56,6 +56,37 @@ def base_get_test(self, resource, method='name', uid_str=True):
5656 self .assertEqual (response_upper .id , '1' )
5757
5858
59+ def base_get_subresource_test (self , resource , subresource_name , subresource_list ):
60+ """
61+ Base get subresource test for 'get' methods of V2Client
62+
63+ Parameters
64+ ----------
65+ self: TestV2ClientMethods
66+ TestV2ClientMethods instance (self)
67+ resource: str
68+ Resource to be tested
69+ subresource_name: str
70+ Subresource name
71+ subresource_list: list(tuple)
72+ List of tuples of key and value
73+ """
74+ mock_subresource = mock_data [:- 1 ] + ', "%s": [{' % subresource_name
75+ for subresource in subresource_list :
76+ mock_subresource += '"%s": "%s", ' % (subresource [0 ], subresource [1 ])
77+ mock_subresource = mock_subresource [:- 2 ] + '}]}'
78+
79+ with requests_mock .mock () as mock :
80+ mock .get ('%s/%s/1' % (base_url , resource ), text = mock_subresource )
81+ response = getattr (self .client , 'get_%s' % resource .replace ('-' , '_' ))(1 )[0 ]
82+
83+ for sub_name , sub_value in subresource_list :
84+ # response.subresource_name[0].sub_name
85+ self .assertEqual (
86+ getattr (getattr (response , subresource_name )[0 ], sub_name ),
87+ sub_value )
88+
89+
5990def base_repr_test (self , resource ):
6091 """
6192 Base __repr__ test for 'get' methods of V2Client
@@ -199,6 +230,9 @@ class TestV2Client(unittest.TestCase):
199230 def test_wrong_cache_parameter (self ):
200231 self .assertRaises (ValueError , pokepy .V2Client , 'incorrect_cache_parameter' )
201232
233+ def test_wrong_cache_location_parameter_type (self ):
234+ self .assertRaises (TypeError , pokepy .V2Client , 'in_disk' , 1 )
235+
202236 def test_custom_cache_directory (self ):
203237 pokepy_folder = 'pokepy_cache' + str (random .randint (10000 , 99999 )) # random folder name
204238 cache_dir = appdirs .user_cache_dir (pokepy_folder , False , opinion = False )
@@ -512,6 +546,154 @@ def test_get_type_int(self):
512546 def test_get_language_int (self ):
513547 base_get_test (self , 'language' , uid_str = False )
514548
549+ # subresource
550+
551+ def test_get_berry_subresource (self ):
552+ base_get_subresource_test (self , 'berry' , 'firmness' , [('name' , 'test' )])
553+
554+ def test_get_berry_firmness_subresource (self ):
555+ base_get_subresource_test (self , 'berry-firmness' , 'berries' , [('name' , 'test' )])
556+
557+ def test_get_berry_flavor_subresource (self ):
558+ base_get_subresource_test (self , 'berry-flavor' , 'contest_type' , [('name' , 'test' )])
559+
560+ def test_get_contest_type_tsubresource (self ):
561+ base_get_subresource_test (self , 'contest-type' , 'berry_flavor' , [('name' , 'test' )])
562+
563+ def test_get_contest_effect_subresource (self ):
564+ base_get_subresource_test (self , 'contest-effect' , 'effect_entries' , [('effect' , 'test' )])
565+
566+ def test_get_super_contest_effect_ssubresource (self ):
567+ base_get_subresource_test (self , 'super-contest-effect' , 'moves' , [('name' , 'test' )])
568+
569+ def test_get_encounter_method_subresource (self ):
570+ base_get_subresource_test (self , 'encounter-method' , 'names' , [('name' , 'test' )])
571+
572+ def test_get_encounter_condition_subresource (self ):
573+ base_get_subresource_test (self , 'encounter-condition' , 'names' , [('name' , 'test' )])
574+
575+ def test_get_encounter_condition_value_subresource (self ):
576+ base_get_subresource_test (self , 'encounter-condition-value' , 'condition' ,
577+ [('name' , 'test' )])
578+
579+ def test_get_evolution_chain_subresource (self ):
580+ base_get_subresource_test (self , 'evolution-chain' , 'baby_trigger_item' , [('name' , 'test' )])
581+
582+ def test_get_evolution_trigger_subresource (self ):
583+ base_get_subresource_test (self , 'evolution-trigger' , 'names' , [('name' , 'test' )])
584+
585+ def test_get_generation_subresource (self ):
586+ base_get_subresource_test (self , 'generation' , 'abilities' , [('name' , 'test' )])
587+
588+ def test_get_pokedex_subresource (self ):
589+ base_get_subresource_test (self , 'pokedex' , 'names' , [('name' , 'test' )])
590+
591+ def test_get_version_subresource (self ):
592+ base_get_subresource_test (self , 'version' , 'names' , [('name' , 'test' )])
593+
594+ def test_get_version_group_subresource (self ):
595+ base_get_subresource_test (self , 'version-group' , 'generation' , [('name' , 'test' )])
596+
597+ def test_get_item_subresource (self ):
598+ base_get_subresource_test (self , 'item' , 'fling_effect' , [('name' , 'test' )])
599+
600+ def test_get_item_attribute_subresource (self ):
601+ base_get_subresource_test (self , 'item-attribute' , 'items' , [('name' , 'test' )])
602+
603+ def test_get_item_category_subresource (self ):
604+ base_get_subresource_test (self , 'item-category' , 'items' , [('name' , 'test' )])
605+
606+ def test_get_item_fling_effect_subresource (self ):
607+ base_get_subresource_test (self , 'item-fling-effect' , 'items' , [('name' , 'test' )])
608+
609+ def test_get_item_pocket_subresource (self ):
610+ base_get_subresource_test (self , 'item-pocket' , 'categories' , [('name' , 'test' )])
611+
612+ def test_get_machine_subresource (self ):
613+ base_get_subresource_test (self , 'machine' , 'item' , [('name' , 'test' )])
614+
615+ def test_get_move_subresource (self ):
616+ base_get_subresource_test (self , 'move' , 'contest_type' , [('name' , 'test' )])
617+
618+ def test_get_move_ailment_subresource (self ):
619+ base_get_subresource_test (self , 'move-ailment' , 'moves' , [('name' , 'test' )])
620+
621+ def test_get_move_battle_style_subresource (self ):
622+ base_get_subresource_test (self , 'move-battle-style' , 'names' , [('name' , 'test' )])
623+
624+ def test_get_move_category_subresource (self ):
625+ base_get_subresource_test (self , 'move-category' , 'moves' , [('name' , 'test' )])
626+
627+ def test_get_move_damage_class_subresource (self ):
628+ base_get_subresource_test (self , 'move-damage-class' , 'moves' , [('name' , 'test' )])
629+
630+ def test_get_move_learn_method_subresource (self ):
631+ base_get_subresource_test (self , 'move-learn-method' , 'names' , [('name' , 'test' )])
632+
633+ def test_get_move_target_subresource (self ):
634+ base_get_subresource_test (self , 'move-target' , 'moves' , [('name' , 'test' )])
635+
636+ def test_get_location_subresource (self ):
637+ base_get_subresource_test (self , 'location' , 'region' , [('name' , 'test' )])
638+
639+ def test_get_location_area_subresource (self ):
640+ base_get_subresource_test (self , 'location-area' , 'location' , [('name' , 'test' )])
641+
642+ def test_get_pal_park_area_subresource (self ):
643+ base_get_subresource_test (self , 'pal-park-area' , 'names' , [('name' , 'test' )])
644+
645+ def test_get_region_subresource (self ):
646+ base_get_subresource_test (self , 'region' , 'locations' , [('name' , 'test' )])
647+
648+ def test_get_ability_subresource (self ):
649+ base_get_subresource_test (self , 'ability' , 'generation' , [('name' , 'test' )])
650+
651+ def test_get_characteristic_subresource (self ):
652+ base_get_subresource_test (self , 'characteristic' , 'descriptions' ,
653+ [('description' , 'test' )])
654+
655+ def test_get_egg_group_subresource (self ):
656+ base_get_subresource_test (self , 'egg-group' , 'names' , [('name' , 'test' )])
657+
658+ def test_get_gender_subresource (self ):
659+ base_get_subresource_test (self , 'gender' , 'required_for_evolution' , [('name' , 'test' )])
660+
661+ def test_get_growth_rate_subresource (self ):
662+ base_get_subresource_test (self , 'growth-rate' , 'pokemon_species' , [('name' , 'test' )])
663+
664+ def test_get_nature_subresource (self ):
665+ base_get_subresource_test (self , 'nature' , 'decreased_stat' , [('name' , 'test' )])
666+
667+ def test_get_pokeathlon_stat_subresource (self ):
668+ base_get_subresource_test (self , 'pokeathlon-stat' , 'names' , [('name' , 'test' )])
669+
670+ def test_get_pokemon_subresource (self ):
671+ base_get_subresource_test (self , 'pokemon' , 'forms' , [('name' , 'test' )])
672+
673+ def test_get_pokemon_color_subresource (self ):
674+ base_get_subresource_test (self , 'pokemon-color' , 'names' , [('name' , 'test' )])
675+
676+ def test_get_pokemon_form_subresource (self ):
677+ base_get_subresource_test (self , 'pokemon-form' , 'pokemon' , [('name' , 'test' )])
678+
679+ def test_get_pokemon_habitat_subresource (self ):
680+ base_get_subresource_test (self , 'pokemon-habitat' , 'names' , [('name' , 'test' )])
681+
682+ def test_get_pokemon_shape_subresource (self ):
683+ base_get_subresource_test (self , 'pokemon-shape' , 'names' , [('name' , 'test' )])
684+
685+ def test_get_pokemon_species_subresource (self ):
686+ base_get_subresource_test (self , 'pokemon-species' , 'growth_rate' , [('name' , 'test' )])
687+
688+ def test_get_stat_subresource (self ):
689+ base_get_subresource_test (self , 'stat' , 'move_damage_class' , [('name' , 'test' )])
690+
691+ def test_get_type_subresource (self ):
692+ base_get_subresource_test (self , 'type' , 'generation' , [('name' , 'test' )])
693+
694+ def test_get_language_subresource (self ):
695+ base_get_subresource_test (self , 'language' , 'names' , [('name' , 'test' )])
696+
515697 # __repr__
516698
517699 def test_api_resource_subresource_repr (self ):
0 commit comments