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_branch_new_case(self): """ Should make a branch with a pipeline if it doesn't already exist """ # set up new_deployment_pipeline_patcher = patch( 'factories.new_deployment_pipeline') mock_new_deployment_pipeline = new_deployment_pipeline_patcher.start() 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 = (199,) # run SUT branch_id = idem_make_branch('mock-branch-name', 1) # confirm that reasonable sql was executed self.mock_get_cur.return_value.execute.assert_any_call( "SELECT branch_id FROM branch " + \ "WHERE branch_name=%s AND feature_id=%s", ('mock-branch-name', 1), ) self.mock_get_cur.return_value.execute.assert_any_call( "INSERT INTO branch (branch_name, feature_id) " + \ "VALUES (%s, %s) " + \ "RETURNING branch_id", ('mock-branch-name', 1), ) self.mock_get_cur.return_value.execute.assert_any_call( "INSERT INTO config (key_value_pairs) " + \ "VALUES (%s) " + \ "RETURNING config_id", ('',), ) self.mock_get_cur.return_value.execute.assert_any_call( "INSERT INTO environment\n" + \ "(settings, infrastructure_backend, environment_name)\n" + \ "VALUES (%s, %s, %s)\n" + \ "RETURNING environment_id", ('', 'mockdib', 'qa-sandbox'), ) self.mock_get_cur.return_value.execute.assert_any_call( "INSERT INTO deployment_pipeline " + \ "(branch_id, config_id, environment_id, automatic) " \ "VALUES (%s, %s, %s, %s) " + \ "RETURNING deployment_pipeline_id", (199, 199, 199, True), ) # confirm that we got back a good id self.assertEqual(type(branch_id), type(0)) # make sure we closed the cursor self.assertEqual(self.mock_get_cur.return_value.close.call_count, 4)
def test_idem_make_branch_existing_case(self): """ Should return the existing iteration id """ # 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 branch_id = idem_make_branch('mock-branch-name', 1) # 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(branch_id, 10) # make sure we closed the cursor self.mock_get_cur.return_value.close.assert_called_once_with()