<s> import io <EOL> import pytest <EOL> import requests <EOL> from datetime import datetime , timedelta <EOL> from github3 import exceptions , GitHubError <EOL> from github3 . models import GitHubCore <EOL> from unittest import TestCase <EOL> from . import helper <EOL> class MyTestRefreshClass ( GitHubCore ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , example_data , session = None ) : <EOL> super ( MyTestRefreshClass , self ) . __init__ ( example_data , session ) <EOL> self . _api = example_data [ '<STR_LIT:url>' ] <EOL> self . last_modified = example_data [ '<STR_LIT>' ] <EOL> self . etag = example_data [ '<STR_LIT>' ] <EOL> class TestGitHubError ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> response = requests . Response ( ) <EOL> response . status_code = <NUM_LIT> <EOL> message = b'<STR_LIT>' <EOL> response . raw = io . BytesIO ( message ) <EOL> self . instance = GitHubError ( response ) <EOL> def test_message_is_empty ( self ) : <EOL> """<STR_LIT>""" <EOL> response = requests . Response ( ) <EOL> response . status_code = <NUM_LIT> <EOL> response . raw = io . BytesIO ( ) <EOL> error = GitHubError ( response ) <EOL> assert error . message == '<STR_LIT>' <EOL> def test_message ( self ) : <EOL> """<STR_LIT>""" <EOL> assert self . instance . msg == self . instance . message <EOL> def test_str ( self ) : <EOL> """<STR_LIT>""" <EOL> assert str ( self . instance ) == '<STR_LIT>' <EOL> class TestGitHubCore ( helper . UnitHelper ) : <EOL> described_class = MyTestRefreshClass <EOL> last_modified = datetime . now ( ) . strftime ( <EOL> '<STR_LIT>' <EOL> ) <EOL> url = '<STR_LIT>' <EOL> etag = '<STR_LIT>' <EOL> example_data = { <EOL> '<STR_LIT:url>' : url , <EOL> '<STR_LIT>' : last_modified , <EOL> '<STR_LIT>' : etag , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> } <EOL> def test_boolean ( self ) : <EOL> """<STR_LIT>""" <EOL> response = requests . Response ( ) <EOL> response . status_code = <NUM_LIT:200> <EOL> boolean = self . instance . _boolean ( response = response , <EOL> true_code = <NUM_LIT:200> , <EOL> false_code = <NUM_LIT> ) <EOL> assert boolean is True <EOL> def test_boolean_raises_exception ( self ) : <EOL> """<STR_LIT>""" <EOL> response = requests . Response ( ) <EOL> response . status_code = <NUM_LIT> <EOL> with pytest . raises ( exceptions . GitHubError ) : <EOL> self . instance . _boolean ( response = response , <EOL> true_code = <NUM_LIT:200> , <EOL> false_code = <NUM_LIT> ) <EOL> def test_boolean_false_code ( self ) : <EOL> """<STR_LIT>""" <EOL> response = requests . Response ( ) <EOL> response . status_code = <NUM_LIT> <EOL> boolean = self . instance . _boolean ( response = response , <EOL> true_code = <NUM_LIT:200> , <EOL> false_code = <NUM_LIT> ) <EOL> assert boolean is False <EOL> def test_boolean_empty_response ( self ) : <EOL> """<STR_LIT>""" <EOL> boolean = self . instance . _boolean ( response = None , <EOL> true_code = <NUM_LIT:200> , <EOL> false_code = <NUM_LIT> ) <EOL> assert boolean is False <EOL> def test_exposes_attributes ( self ) : <EOL> """<STR_LIT>""" <EOL> assert self . instance . fake_attr == '<STR_LIT:foo>' <EOL> def test_from_json ( self ) : <EOL> """<STR_LIT>""" <EOL> github_core = GitHubCore . from_json ( '<STR_LIT:{}>' ) <EOL> assert isinstance ( github_core , GitHubCore ) <EOL> def test_json ( self ) : <EOL> """<STR_LIT>""" <EOL> response = requests . Response ( ) <EOL> response . headers [ '<STR_LIT>' ] = '<STR_LIT:foo>' <EOL> response . headers [ '<STR_LIT>' ] = '<STR_LIT:bar>' <EOL> response . raw = io . BytesIO ( b'<STR_LIT:{}>' ) <EOL> response . status_code = <NUM_LIT:200> <EOL> json = self . instance . _json ( response , <NUM_LIT:200> ) <EOL> assert json [ '<STR_LIT>' ] == '<STR_LIT:foo>' <EOL> assert json [ '<STR_LIT>' ] == '<STR_LIT:bar>' <EOL> def test_json_status_code_does_not_match ( self ) : <EOL> """<STR_LIT>""" <EOL> response = requests . Response ( ) <EOL> response . status_code = <NUM_LIT> <EOL> json = self . instance . _json ( response , <NUM_LIT:200> ) <EOL> assert json is None <EOL> def test_missingattribute ( self ) : <EOL> """<STR_LIT>""" <EOL> with pytest . raises ( AttributeError ) : <EOL> self . instance . missingattribute <EOL> def test_refresh ( self ) : <EOL> """<STR_LIT>""" <EOL> instance = self . instance . refresh ( ) <EOL> assert isinstance ( instance , MyTestRefreshClass ) <EOL> expected_headers = None <EOL> self . session . get . assert_called_once_with ( <EOL> self . url , <EOL> headers = expected_headers , <EOL> ) <EOL> def test_refresh_custom_headers ( self ) : <EOL> """<STR_LIT>""" <EOL> self . instance . CUSTOM_HEADERS = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> expected_headers = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> self . instance . refresh ( ) <EOL> self . session . get . assert_called_once_with ( <EOL> self . url , <EOL> headers = expected_headers , <EOL> ) <EOL> def test_refresh_last_modified ( self ) : <EOL> """<STR_LIT>""" <EOL> expected_headers = { <EOL> '<STR_LIT>' : self . last_modified <EOL> } <EOL> self . instance . refresh ( conditional = True ) <EOL> self . session . get . assert_called_once_with ( <EOL> self . url , <EOL> headers = expected_headers , <EOL> ) <EOL> def test_refresh_etag ( self ) : <EOL> """<STR_LIT>""" <EOL> self . instance . last_modified = None <EOL> expected_headers = { <EOL> '<STR_LIT>' : self . etag <EOL> } <EOL> self . instance . refresh ( conditional = True ) <EOL> self . session . get . assert_called_once_with ( <EOL> self . url , <EOL> headers = expected_headers , <EOL> ) <EOL> def test_strptime ( self ) : <EOL> """<STR_LIT>""" <EOL> dt = self . instance . _strptime ( '<STR_LIT>' ) <EOL> assert dt . tzname ( ) == '<STR_LIT>' <EOL> assert dt . dst ( ) == timedelta ( <NUM_LIT:0> ) <EOL> assert dt . utcoffset ( ) == timedelta ( <NUM_LIT:0> ) <EOL> def test_strptime_time_str_required ( self ) : <EOL> """<STR_LIT>""" <EOL> assert self . instance . _strptime ( '<STR_LIT>' ) is None </s>
