<s> import json <EOL> from click . testing import CliRunner <EOL> import responses <EOL> from mapboxcli . scripts . cli import main_group <EOL> @ responses . activate <EOL> def test_cli_geocode_fwd ( ) : <EOL> responses . add ( <EOL> responses . GET , <EOL> '<STR_LIT>' , <EOL> match_querystring = True , <EOL> body = '<STR_LIT>' , status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( <EOL> main_group , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> catch_exceptions = False ) <EOL> print ( result . output ) <EOL> print ( result . exception ) <EOL> print ( result . exc_info ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> assert result . output == '<STR_LIT>' <EOL> @ responses . activate <EOL> def test_cli_geocode_fwd_env_token ( ) : <EOL> responses . add ( <EOL> responses . GET , <EOL> '<STR_LIT>' , <EOL> match_querystring = True , <EOL> body = '<STR_LIT>' , status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( <EOL> main_group , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> env = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> assert result . output == '<STR_LIT>' <EOL> @ responses . activate <EOL> def test_cli_geocode_reverse ( ) : <EOL> lon , lat = - <NUM_LIT> , <NUM_LIT> <EOL> body = json . dumps ( { "<STR_LIT>" : [ lon , lat ] } ) <EOL> responses . add ( <EOL> responses . GET , <EOL> '<STR_LIT>' . format ( lon , lat ) , <EOL> match_querystring = True , <EOL> body = body , <EOL> status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( <EOL> main_group , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> input = '<STR_LIT>' . format ( lon , lat ) ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> assert result . output . strip ( ) == body <EOL> @ responses . activate <EOL> def test_cli_geocode_reverse_env_token ( ) : <EOL> lon , lat = - <NUM_LIT> , <NUM_LIT> <EOL> body = json . dumps ( { "<STR_LIT>" : [ lon , lat ] } ) <EOL> responses . add ( <EOL> responses . GET , <EOL> '<STR_LIT>' . format ( lon , lat ) , <EOL> match_querystring = True , <EOL> body = body , <EOL> status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( <EOL> main_group , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> input = '<STR_LIT>' . format ( lon , lat ) , <EOL> env = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> assert result . output . strip ( ) == body <EOL> @ responses . activate <EOL> def test_cli_geocode_unauthorized ( ) : <EOL> responses . add ( <EOL> responses . GET , <EOL> '<STR_LIT>' , <EOL> body = '<STR_LIT>' , status = <NUM_LIT> , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( main_group , [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> assert result . exit_code == <NUM_LIT:1> <EOL> assert result . output == '<STR_LIT>' <EOL> @ responses . activate <EOL> def test_cli_geocode_rev_unauthorized ( ) : <EOL> lon , lat = - <NUM_LIT> , <NUM_LIT> <EOL> responses . add ( <EOL> responses . GET , <EOL> '<STR_LIT>' . format ( lon , lat ) , <EOL> body = '<STR_LIT>' , status = <NUM_LIT> , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( <EOL> main_group , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> input = '<STR_LIT>' . format ( lon , lat ) ) <EOL> assert result . exit_code == <NUM_LIT:1> <EOL> assert result . output == '<STR_LIT>' <EOL> @ responses . activate <EOL> def test_cli_geocode_fwd_headers ( ) : <EOL> responses . add ( <EOL> responses . GET , <EOL> '<STR_LIT>' , <EOL> body = '<STR_LIT>' , status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( <EOL> main_group , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> assert result . output . startswith ( '<STR_LIT:Content-Type>' ) <EOL> @ responses . activate <EOL> def test_cli_geocode_rev_headers ( ) : <EOL> lon , lat = - <NUM_LIT> , <NUM_LIT> <EOL> body = json . dumps ( { "<STR_LIT>" : [ lon , lat ] } ) <EOL> responses . add ( <EOL> responses . GET , <EOL> '<STR_LIT>' . format ( lon , lat ) , <EOL> body = body , <EOL> status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( <EOL> main_group , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> input = '<STR_LIT>' . format ( lon , lat ) ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> assert result . output . startswith ( '<STR_LIT:Content-Type>' ) <EOL> def test_cli_geocode_bad_place ( ) : <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( <EOL> main_group , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> input = '<STR_LIT>' ) <EOL> assert result . exit_code == <NUM_LIT:2> <EOL> lon , lat = - <NUM_LIT> , <NUM_LIT> <EOL> result = runner . invoke ( <EOL> main_group , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> input = '<STR_LIT>' . format ( lon , lat ) ) <EOL> assert result . exit_code == <NUM_LIT:2> <EOL> def test_cli_geocode_bad_dataset ( ) : <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( <EOL> main_group , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> input = '<STR_LIT>' ) <EOL> assert result . exit_code == <NUM_LIT:2> <EOL> assert "<STR_LIT>" in result . output <EOL> def test_cli_geocode_invalid_country ( ) : <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( <EOL> main_group , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> input = '<STR_LIT>' ) <EOL> assert result . exit_code == <NUM_LIT:2> <EOL> assert "<STR_LIT>" in result . output </s>
