<s> from __future__ import absolute_import <EOL> import json <EOL> import responses <EOL> import pytest <EOL> from freight import checks <EOL> from freight . exceptions import CheckFailed , CheckPending <EOL> from freight . testutils import TestCase <EOL> class GitHubCheckBase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . check = checks . get ( '<STR_LIT>' ) <EOL> self . user = self . create_user ( ) <EOL> self . repo = self . create_repo ( ) <EOL> self . app = self . create_app ( repository = self . repo ) <EOL> class GitHubContextCheckTest ( GitHubCheckBase ) : <EOL> @ responses . activate <EOL> def test_not_passing ( self ) : <EOL> body = json . dumps ( [ <EOL> { <EOL> "<STR_LIT:state>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> ] ) <EOL> responses . add ( responses . GET , '<STR_LIT>' , <EOL> body = body ) <EOL> config = { '<STR_LIT>' : [ '<STR_LIT>' ] , '<STR_LIT>' : '<STR_LIT>' } <EOL> with pytest . raises ( CheckFailed ) : <EOL> self . check . check ( self . app , '<STR_LIT>' , config ) <EOL> @ responses . activate <EOL> def test_not_finished ( self ) : <EOL> body = json . dumps ( [ <EOL> { <EOL> "<STR_LIT:state>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> ] ) <EOL> responses . add ( responses . GET , '<STR_LIT>' , <EOL> body = body ) <EOL> config = { '<STR_LIT>' : [ '<STR_LIT>' ] , '<STR_LIT>' : '<STR_LIT>' } <EOL> with pytest . raises ( CheckPending ) : <EOL> self . check . check ( self . app , '<STR_LIT>' , config ) <EOL> @ responses . activate <EOL> def test_missing_required_context ( self ) : <EOL> body = json . dumps ( [ <EOL> { <EOL> "<STR_LIT:state>" : "<STR_LIT:success>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> ] ) <EOL> responses . add ( responses . GET , '<STR_LIT>' , <EOL> body = body ) <EOL> config = { '<STR_LIT>' : [ '<STR_LIT>' ] , '<STR_LIT>' : '<STR_LIT>' } <EOL> with pytest . raises ( CheckFailed ) : <EOL> self . check . check ( self . app , '<STR_LIT>' , config ) <EOL> @ responses . activate <EOL> def test_success ( self ) : <EOL> body = json . dumps ( [ <EOL> { <EOL> "<STR_LIT:state>" : "<STR_LIT:success>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> ] ) <EOL> responses . add ( responses . GET , '<STR_LIT>' , <EOL> body = body ) <EOL> config = { '<STR_LIT>' : [ '<STR_LIT>' ] , '<STR_LIT>' : '<STR_LIT>' } <EOL> self . check . check ( self . app , '<STR_LIT>' , config ) <EOL> @ responses . activate <EOL> def test_no_contexts_with_none_defined ( self ) : <EOL> body = json . dumps ( [ ] ) <EOL> responses . add ( responses . GET , '<STR_LIT>' , <EOL> body = body ) <EOL> config = { '<STR_LIT>' : '<STR_LIT>' } <EOL> with pytest . raises ( CheckFailed ) : <EOL> self . check . check ( self . app , '<STR_LIT>' , config ) <EOL> @ responses . activate <EOL> def test_any_failing_context_with_none_define ( self ) : <EOL> body = json . dumps ( [ <EOL> { <EOL> "<STR_LIT:state>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> ] ) <EOL> responses . add ( responses . GET , '<STR_LIT>' , <EOL> body = body ) <EOL> config = { '<STR_LIT>' : '<STR_LIT>' } <EOL> with pytest . raises ( CheckFailed ) : <EOL> self . check . check ( self . app , '<STR_LIT>' , config ) </s>
