1
+ from graphene .test import Client # type: ignore
2
+ import pytest
3
+
4
+ from cities_light .models import Country , Region , SubRegion , City
5
+ from cities_light .tests .graphql .schema import schema
6
+ from cities_light .tests .models import Person
7
+
8
+ @pytest .fixture
9
+ def country_fixture ():
10
+ return Country .objects .create (name = 'France' )
11
+ @pytest .fixture
12
+ def region_fixture (country_fixture ):
13
+ return Region .objects .create (name = 'Normandy' , country = country_fixture )
14
+ @pytest .fixture
15
+ def subregion_fixture (country_fixture , region_fixture ):
16
+ return SubRegion .objects .create (name = 'Upper Normandy' , country = country_fixture , region = region_fixture )
17
+ @pytest .fixture
18
+ def city_fixture (country_fixture , region_fixture , subregion_fixture ):
19
+ return City .objects .create (name = 'Caen' , country = country_fixture , region = region_fixture , subregion = subregion_fixture )
20
+ def test_country_type (db , country_fixture ):
21
+ Person .objects .create (name = "Skippy" , country = country_fixture )
22
+ client = Client (schema )
23
+ executed = client .execute ("""{ people { name, country {name} } }""" )
24
+ returned_person = executed ["data" ]["people" ][0 ]
25
+ assert returned_person == {"name" : "Skippy" , "country" : {"name" : "France" }}
26
+
27
+ def test_region_type (db , country_fixture , region_fixture ):
28
+ Person .objects .create (name = "Skippy" , country = country_fixture , region = region_fixture )
29
+ client = Client (schema )
30
+ executed = client .execute ("""{ people { name, region {name, country{ name}} } }""" )
31
+ returned_person = executed ["data" ]["people" ][0 ]
32
+ assert returned_person == {"name" : "Skippy" , "region" : {"name" : "Normandy" , 'country' : {'name' : 'France' },}}
33
+
34
+ def test_subregion_type (db , country_fixture , subregion_fixture ):
35
+ Person .objects .create (name = "Skippy" , country = country_fixture , subregion = subregion_fixture )
36
+ client = Client (schema )
37
+ executed = client .execute ("""{ people { name, subregion {name, region{name}, country{ name}} } }""" )
38
+ returned_person = executed ["data" ]["people" ][0 ]
39
+ assert returned_person == {"name" : "Skippy" , "subregion" : {"name" : "Upper Normandy" , 'region' : {'name' : 'Normandy' }, 'country' : {'name' : 'France' },}}
40
+
41
+ def test_city_type (db , country_fixture , city_fixture ):
42
+ Person .objects .create (name = "Skippy" , country = country_fixture , city = city_fixture )
43
+ client = Client (schema )
44
+ executed = client .execute ("""{ people { name, city{name, subregion {name, region{name}, country{ name}} } }}""" )
45
+ returned_person = executed ["data" ]["people" ][0 ]
46
+ assert returned_person == {"name" : "Skippy" , "city" : {"name" : "Caen" , 'subregion' : {'name' : 'Upper Normandy' ,
47
+ 'region' : {'name' : 'Normandy' },
48
+ 'country' : {'name' : 'France' },}}}
0 commit comments