#NEWLINE# @ mock . patch ( 'changes.listeners.analytics_notifier.post_analytics_data' ) #NEWLINE# def test_failed_build( self , post_fn ) : #NEWLINE# #INDENT# URL = 'https://analytics.example.com/report?source=changes' #NEWLINE# self . _set_config_url ( self ) #NEWLINE# project = self . create_project ( name = 'test' , slug = 'project-slug' ) #NEWLINE# self . assertEquals ( post_fn . call_count , 0 ) #NEWLINE# duration = 1234 #NEWLINE# created = 1424998888 #NEWLINE# started = ( created + 10 ) #NEWLINE# finished = ( started + duration ) #NEWLINE# decided = ( finished + 10 ) #NEWLINE# build = self . create_build ( project , result = Result . failed , target = 'D1' , label = 'Some sweet diff' , duration = duration , tags = [ 'commit' , 'angry' ] , date_created = ts_to_datetime ( created ) , date_started = ts_to_datetime ( started ) , date_finished = ts_to_datetime ( finished ) , date_decided = ts_to_datetime ( decided ) ) #NEWLINE# job = self . create_job ( build = build , result = Result . failed ) #NEWLINE# jobphase = self . create_jobphase ( job ) #NEWLINE# jobstep = self . create_jobstep ( jobphase , status = Status . finished , result = Result . failed ) #NEWLINE# self . create_jobstep ( jobphase , status = Status . finished , result = Result . infra_failed , replacement_id = jobstep . id ) #NEWLINE# db . session . add ( FailureReason ( step_id = jobstep . id , job_id = job . id , build_id = build . id , project_id = project . id , reason = 'missing_tests' ) ) #NEWLINE# db . session . commit ( ) #NEWLINE# self . create_itemstat ( item_id = build . id , name = 'names' , value = 99 ) #NEWLINE# self . create_itemstat ( item_id = build . id , name = 'faces' , value = 0 ) #NEWLINE# with mock . patch ( 'changes.listeners.analytics_notifier._get_phabricator_revision_url' ) as mock_get_phab : #NEWLINE# #INDENT# mock_get_phab . return_value = 'https://example.com/D1' #NEWLINE# with mock . patch ( 'changes.listeners.analytics_notifier._get_build_failure_reasons' ) as mock_get_failures : #NEWLINE# #INDENT# mock_get_failures . return_value = [ 'aborted' , 'missing_tests' ] #NEWLINE# build_finished_handler ( build_id = build . id . hex ) #NEWLINE# #UNINDENT# #UNINDENT# expected_data = { #NEWLINE# #INDENT# 'build_id' : build . id . hex , #NEWLINE# 'number' : 1 , #NEWLINE# 'target' : 'D1' , #NEWLINE# 'project_slug' : 'project-slug' , #NEWLINE# 'result' : 'Failed' , #NEWLINE# 'label' : 'Some sweet diff' , #NEWLINE# 'is_commit' : True , #NEWLINE# 'duration' : 1234 , #NEWLINE# 'jobsteps_replaced' : 1 , #NEWLINE# 'date_created' : created , #NEWLINE# 'date_started' : started , #NEWLINE# 'date_finished' : finished , #NEWLINE# 'date_decided' : decided , #NEWLINE# 'phab_revision_url' : 'https://example.com/D1' , #NEWLINE# 'failure_reasons' : [ 'aborted' , 'missing_tests' ] , #NEWLINE# 'tags' : { #NEWLINE# #INDENT# 'tags' : [ 'angry' , 'commit' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# 'tags_string' : 'angry,commit' , #NEWLINE# 'item_stats' : { #NEWLINE# #INDENT# 'names' : 99 , #NEWLINE# 'faces' : 0 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# post_fn . assert_called_once_with ( URL , [ expected_data ] )