<s> try : <EOL> from urllib . parse import urlparse <EOL> except : <EOL> from urlparse import urlparse <EOL> import pytest <EOL> import responses <EOL> from sparkpost import SparkPost <EOL> from sparkpost import Templates <EOL> from sparkpost . exceptions import SparkPostAPIException <EOL> def test_translate_keys_with_id ( ) : <EOL> t = Templates ( '<STR_LIT>' , '<STR_LIT:key>' ) <EOL> results = t . _translate_keys ( id = '<STR_LIT>' ) <EOL> assert results [ '<STR_LIT:id>' ] == '<STR_LIT>' <EOL> @ responses . activate <EOL> def test_success_create ( ) : <EOL> responses . add ( <EOL> responses . POST , <EOL> '<STR_LIT>' , <EOL> status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = '<STR_LIT>' <EOL> ) <EOL> sp = SparkPost ( '<STR_LIT>' ) <EOL> results = sp . templates . create ( ) <EOL> assert results == '<STR_LIT>' <EOL> @ responses . activate <EOL> def test_fail_create ( ) : <EOL> responses . add ( <EOL> responses . POST , <EOL> '<STR_LIT>' , <EOL> status = <NUM_LIT> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = """<STR_LIT>""" <EOL> ) <EOL> with pytest . raises ( SparkPostAPIException ) : <EOL> sp = SparkPost ( '<STR_LIT>' ) <EOL> sp . templates . create ( ) <EOL> @ responses . activate <EOL> def test_success_update ( ) : <EOL> responses . add ( <EOL> responses . PUT , <EOL> '<STR_LIT>' , <EOL> status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = '<STR_LIT>' <EOL> ) <EOL> sp = SparkPost ( '<STR_LIT>' ) <EOL> results = sp . templates . update ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> assert results == '<STR_LIT>' <EOL> @ responses . activate <EOL> def test_fail_update ( ) : <EOL> responses . add ( <EOL> responses . PUT , <EOL> '<STR_LIT>' , <EOL> status = <NUM_LIT> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = """<STR_LIT>""" <EOL> ) <EOL> with pytest . raises ( SparkPostAPIException ) : <EOL> sp = SparkPost ( '<STR_LIT>' ) <EOL> sp . templates . update ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> @ responses . activate <EOL> def test_success_delete ( ) : <EOL> responses . add ( <EOL> responses . DELETE , <EOL> '<STR_LIT>' , <EOL> status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = '<STR_LIT>' <EOL> ) <EOL> sp = SparkPost ( '<STR_LIT>' ) <EOL> results = sp . templates . delete ( '<STR_LIT>' ) <EOL> assert results == '<STR_LIT>' <EOL> @ responses . activate <EOL> def test_fail_delete ( ) : <EOL> responses . add ( <EOL> responses . DELETE , <EOL> '<STR_LIT>' , <EOL> status = <NUM_LIT> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = """<STR_LIT>""" <EOL> ) <EOL> with pytest . raises ( SparkPostAPIException ) : <EOL> sp = SparkPost ( '<STR_LIT>' ) <EOL> sp . templates . delete ( '<STR_LIT>' ) <EOL> @ responses . activate <EOL> def test_success_get ( ) : <EOL> responses . add ( <EOL> responses . GET , <EOL> '<STR_LIT>' , <EOL> status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = '<STR_LIT>' <EOL> ) <EOL> sp = SparkPost ( '<STR_LIT>' ) <EOL> results = sp . templates . get ( '<STR_LIT>' ) <EOL> assert results == { } <EOL> @ responses . activate <EOL> def test_success_get_with_is_draft ( ) : <EOL> responses . add ( <EOL> responses . GET , <EOL> '<STR_LIT>' , <EOL> match_querystring = True , <EOL> status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = '<STR_LIT>' <EOL> ) <EOL> sp = SparkPost ( '<STR_LIT>' ) <EOL> results = sp . templates . get ( '<STR_LIT>' , True ) <EOL> assert results == { } <EOL> @ responses . activate <EOL> def test_fail_get ( ) : <EOL> responses . add ( <EOL> responses . GET , <EOL> '<STR_LIT>' , <EOL> status = <NUM_LIT> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = """<STR_LIT>""" <EOL> ) <EOL> with pytest . raises ( SparkPostAPIException ) : <EOL> sp = SparkPost ( '<STR_LIT>' ) <EOL> sp . templates . get ( '<STR_LIT>' ) <EOL> @ responses . activate <EOL> def test_success_list ( ) : <EOL> responses . add ( <EOL> responses . GET , <EOL> '<STR_LIT>' , <EOL> status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = '<STR_LIT>' <EOL> ) <EOL> sp = SparkPost ( '<STR_LIT>' ) <EOL> response = sp . templates . list ( ) <EOL> assert response == [ ] <EOL> @ responses . activate <EOL> def test_success_preview ( ) : <EOL> responses . add ( <EOL> responses . POST , <EOL> '<STR_LIT>' , <EOL> status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = '<STR_LIT>' <EOL> ) <EOL> sp = SparkPost ( '<STR_LIT>' ) <EOL> results = sp . templates . preview ( '<STR_LIT>' , { } ) <EOL> assert responses . calls [ <NUM_LIT:0> ] . request . body == '<STR_LIT>' <EOL> assert results == { } <EOL> @ responses . activate <EOL> def test_success_preview_with_draft ( ) : <EOL> responses . add ( <EOL> responses . POST , <EOL> '<STR_LIT>' , <EOL> match_querystring = True , <EOL> status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = '<STR_LIT>' <EOL> ) <EOL> sp = SparkPost ( '<STR_LIT>' ) <EOL> results = sp . templates . preview ( '<STR_LIT>' , { } , True ) <EOL> parsed = urlparse ( responses . calls [ <NUM_LIT:0> ] . request . url ) <EOL> assert parsed . query == '<STR_LIT>' <EOL> assert results == { } <EOL> @ responses . activate <EOL> def test_fail_preview ( ) : <EOL> responses . add ( <EOL> responses . POST , <EOL> '<STR_LIT>' , <EOL> status = <NUM_LIT> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = """<STR_LIT>""" <EOL> ) <EOL> with pytest . raises ( SparkPostAPIException ) : <EOL> sp = SparkPost ( '<STR_LIT>' ) <EOL> sp . templates . preview ( '<STR_LIT>' , { } ) </s>
