def handle_branch_commit(repo_name, feature_name, branch_name, commit_hash): """ Ensure the api represents and associates the appropriate objects repo_name represented as a service and associated with, feature_name represented as a feature and associated with, branch_name represented as a branch and associated with, commit_hash represented as a integration """ print( "handling branch commit ({}, {}, {}, {})".format( repo_name, feature_name, branch_name, commit_hash, ) ) service_id = idem_make_service(repo_name) feature_id = idem_make_feature(feature_name, service_id) branch_id = idem_make_branch(branch_name, feature_id) iteration_id = idem_make_iteration(commit_hash, branch_id) return {'iteration_id': iteration_id}
def test_idem_make_service_existing_case(self): """ Should return the existing id if it already exists """ # set up mock_rowcount = PropertyMock(return_value=1) type(self.mock_get_cur.return_value).rowcount = mock_rowcount self.mock_get_cur.return_value.fetchone.return_value = (10,) # run SUT service_id = idem_make_service('mock-service-name') # confirm we only called execute once (to get existing) self.assertEqual(self.mock_get_cur.return_value.execute.call_count, 1) # and ended up with the corect id self.assertEqual(service_id, 10) # make sure we closed the cursor self.mock_get_cur.return_value.close.assert_called_once_with()
def test_idem_make_service_new_case(self): """ Should make a service if it doesnt already exist """ # set up mock_rowcount = PropertyMock(return_value=0) type(self.mock_get_cur.return_value).rowcount = mock_rowcount self.mock_get_cur.return_value.fetchone.return_value = (1,) # run SUT service_id = idem_make_service('mock-service-name') # confirm that reasonable sql was executed only once self.mock_get_cur.return_value.execute.assert_any_call( "INSERT INTO service (service_name) " + \ "VALUES (%s) RETURNING service_id", ('mock-service-name',), ) # confirm that we got an id back self.assertEqual(type(service_id), type(0)) self.assertEqual(self.mock_get_cur.return_value.execute.call_count, 2) # make sure we closed the cursor self.mock_get_cur.return_value.close.assert_called_once_with()