<s> try : <EOL> from urllib import urlencode <EOL> except ImportError : <EOL> from urllib . parse import urlencode <EOL> from pyshorteners import Shortener , Shorteners <EOL> from pyshorteners . exceptions import ShorteningErrorException <EOL> import responses <EOL> import pytest <EOL> s = Shortener ( Shorteners . ISGD ) <EOL> shorten = '<STR_LIT>' <EOL> expanded = '<STR_LIT>' <EOL> @ responses . activate <EOL> def test_isgd_short_method ( ) : <EOL> params = urlencode ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:url>' : expanded , <EOL> } ) <EOL> mock_url = '<STR_LIT>' . format ( s . api_url , params ) <EOL> responses . add ( responses . GET , mock_url , body = shorten , <EOL> match_querystring = True ) <EOL> shorten_result = s . short ( expanded ) <EOL> assert shorten_result == shorten <EOL> assert s . shorten == shorten_result <EOL> assert s . expanded == expanded <EOL> @ responses . activate <EOL> def test_isgd_short_method_bad_response ( ) : <EOL> params = urlencode ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:url>' : expanded , <EOL> } ) <EOL> mock_url = '<STR_LIT>' . format ( s . api_url , params ) <EOL> responses . add ( responses . GET , mock_url , body = shorten , status = <NUM_LIT> , <EOL> match_querystring = True ) <EOL> with pytest . raises ( ShorteningErrorException ) : <EOL> s . short ( expanded ) </s>
