def test_idem_release_automatic_pipelines(self): """ When an image is built, it's released in relevant automatic pipelines When an iteration's image is built, herd-service releases that image in all of that iteration's branch's automatic pipelines. branch -> iteration ----------> release |-----> deployment pipeline <----| """ # run SUT result = idem_release_in_automatic_pipelines(123) # confirm that the insert sql was executed once # SQL can do this whole operation so we should have it handle it. self.mock_get_cur.return_value.execute.asert_called_once_with( "INSERT INTO release (iteration_id, deployment_pipeline_id)\n" + \ " SELECT iteration_id, deployment_pipeline_id\n" + \ " FROM iteration\n" + \ " JOIN branch USING (branch_id)\n" + \ " JOIN deployment_pipeline USING (branch_id)\n" + \ " WHERE iteration_id = %s", (123,), ) # confirm we closed the cursor self.mock_get_cur.return_value.close.assert_called_once_with() # the uniqueness constraint in the database is keeping us # from inserting the same release twice. To ensure that this # is idempotent I'm just confirming that it can be called # again without blowing up and that it returns the same # thing it did before. self.assertEqual(idem_release_in_automatic_pipelines(123), result)
def handle_build(commit_hash, image_name): """ ensure the api represents that the image was built from the commit The iteration gets it's build name updated and releases are created for the branch's automatic pipelines. The branch's automatic pipelines are run. """ print("handling build ({}, {})".format(commit_hash, image_name,)) iteration = get_iteration(commit_hash=commit_hash) set_iteration(iteration['iteration_id'], {'image_name': image_name}) releases = idem_release_in_automatic_pipelines(iteration['iteration_id']) print("running releases {}".format(releases)) run(releases) return {'iteration_id': iteration['iteration_id']}