<s> import unittest <EOL> from mock import MagicMock , patch <EOL> from nose . plugins . skip import SkipTest <EOL> from tests . checks . common import load_check <EOL> CONFIG = { <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> } <EOL> ] <EOL> } <EOL> def get_mock_first_build ( url , * args , ** kwargs ) : <EOL> mock_resp = MagicMock ( ) <EOL> if '<STR_LIT>' in url : <EOL> json = { "<STR_LIT:count>" : <NUM_LIT:0> , "<STR_LIT>" : "<STR_LIT>" } <EOL> else : <EOL> json = { "<STR_LIT:count>" : <NUM_LIT:1> , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : [ { "<STR_LIT:id>" : <NUM_LIT:1> , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT:1>" , "<STR_LIT:status>" : "<STR_LIT>" , "<STR_LIT:state>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ] } <EOL> mock_resp . json . return_value = json <EOL> return mock_resp <EOL> def get_mock_one_more_build ( url , * args , ** kwargs ) : <EOL> mock_resp = MagicMock ( ) <EOL> json = { } <EOL> if '<STR_LIT>' in url : <EOL> json = { "<STR_LIT:count>" : <NUM_LIT:1> , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : [ { "<STR_LIT:id>" : <NUM_LIT:2> , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT:2>" , "<STR_LIT:status>" : "<STR_LIT>" , "<STR_LIT:state>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ] } <EOL> elif '<STR_LIT>' in url : <EOL> json = { "<STR_LIT:count>" : <NUM_LIT:0> , "<STR_LIT>" : "<STR_LIT>" } <EOL> mock_resp . json . return_value = json <EOL> return mock_resp <EOL> class TeamCityCheckTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_build_event ( self ) : <EOL> raise SkipTest ( "<STR_LIT>" ) <EOL> agent_config = { <EOL> '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> check = load_check ( '<STR_LIT>' , CONFIG , agent_config ) <EOL> with patch ( '<STR_LIT>' , get_mock_first_build ) : <EOL> check . check ( check . instances [ <NUM_LIT:0> ] ) <EOL> metrics = check . get_metrics ( ) <EOL> self . assertEquals ( len ( metrics ) , <NUM_LIT:0> ) <EOL> events = check . get_events ( ) <EOL> self . assertEquals ( len ( events ) , <NUM_LIT:0> ) <EOL> with patch ( '<STR_LIT>' , get_mock_one_more_build ) : <EOL> check . check ( check . instances [ <NUM_LIT:0> ] ) <EOL> events = check . get_events ( ) <EOL> self . assertEquals ( len ( events ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( events [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEquals ( events [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEquals ( events [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEquals ( events [ <NUM_LIT:0> ] [ '<STR_LIT:host>' ] , "<STR_LIT>" ) <EOL> with patch ( '<STR_LIT>' , get_mock_one_more_build ) : <EOL> check . check ( check . instances [ <NUM_LIT:0> ] ) <EOL> events = check . get_events ( ) <EOL> self . assertEquals ( len ( events ) , <NUM_LIT:0> ) </s>
