def test_init_task__named_plan(self): project_config = create_project_config() project_config.config["project"]["git"]["repo_url"] = "EXISTING_REPO" expected_plans = { "install": { "title": "Test Install", "slug": "install", "tier": "primary", "steps": { 1: { "flow": "install_prod" } }, } } project_config.config["plans"] = expected_plans project_config.keychain.set_service( "metadeploy", ServiceConfig({ "url": "https://metadeploy", "token": "TOKEN" })) task_config = TaskConfig( {"options": { "tag": "release/1.0", "plan": "install" }}) task = Publish(project_config, task_config) task._init_task() self.assertEqual(expected_plans, task.plan_configs)
def test_find_or_create_version__commit(self): responses.add( "GET", "https://metadeploy/versions?product=abcdef&label=abcdef", json={"data": [{"url": "http://EXISTING_VERSION"}]}, ) project_config = create_project_config() project_config.config["project"]["git"]["repo_url"] = "EXISTING_REPO" project_config.config["plans"] = { "install": { "title": "Test Install", "slug": "install", "tier": "primary", "steps": {1: {"flow": "install_prod"}}, } } project_config.keychain.set_service( "metadeploy", ServiceConfig({"url": "https://metadeploy", "token": "TOKEN"}) ) task_config = TaskConfig({"options": {"commit": "abcdef"}}) task = Publish(project_config, task_config) task._init_task() version = task._find_or_create_version( {"url": "http://EXISTING_PRODUCT", "id": "abcdef"} ) self.assertEqual("http://EXISTING_VERSION", version["url"])
def test_find_or_create_version__already_exists(self): responses.add( "GET", "https://metadeploy/versions?product=abcdef&label=1.0", json={"data": [{ "url": "http://EXISTING_VERSION" }]}, ) project_config = create_project_config() project_config.keychain.set_service( "metadeploy", ServiceConfig({ "url": "https://metadeploy", "token": "TOKEN" })) task_config = TaskConfig({ "options": { "flow": "install_prod", "product_id": "abcdef", "tag": "release/1.0", "title": "Test Product", "slug": "test", "tier": "primary", } }) task = Publish(project_config, task_config) task._init_task() version = task._find_or_create_version() self.assertEqual("http://EXISTING_VERSION", version["url"])
def test_find_or_create_version__already_exists(self): responses.add( "GET", "https://metadeploy/versions?product=abcdef&label=1.0", json={"data": [{"url": "http://EXISTING_VERSION"}]}, ) project_config = create_project_config() project_config.config["project"]["git"]["repo_url"] = "EXISTING_REPO" project_config.config["plans"] = { "install": { "title": "Test Install", "slug": "install", "tier": "primary", "steps": {1: {"flow": "install_prod"}}, } } project_config.keychain.set_service( "metadeploy", ServiceConfig({"url": "https://metadeploy", "token": "TOKEN"}) ) task_config = TaskConfig({"options": {"tag": "release/1.0"}}) task = Publish(project_config, task_config) task._init_task() version = task._find_or_create_version( {"url": "http://EXISTING_PRODUCT", "id": "abcdef"} ) self.assertEqual("http://EXISTING_VERSION", version["url"])
def test_init_task__no_tag_or_commit(self): project_config = create_project_config() project_config.keychain.set_service( "metadeploy", ServiceConfig({"url": "https://metadeploy", "token": "TOKEN"}) ) task_config = TaskConfig({"options": {}}) task = Publish(project_config, task_config) with self.assertRaises(TaskOptionsError): task._init_task()
def test_find_or_create_plan_template__not_found(self): responses.add( "GET", "https://metadeploy/plantemplates?product=abcdef&name=install", json={"data": []}, ) responses.add( "POST", "https://metadeploy/plantemplates", json={"url": "https://NEW_PLANTEMPLATE"}, ) responses.add("POST", "https://metadeploy/planslug", json={"url": "http://NEW_PLANSLUG"}) project_config = create_project_config() project_config.config["project"]["git"]["repo_url"] = "EXISTING_REPO" expected_plans = { "install": { "title": "Test Install", "slug": "install", "tier": "primary", "steps": { 1: { "flow": "install_prod" } }, } } project_config.config["plans"] = expected_plans project_config.keychain.set_service( "metadeploy", ServiceConfig({ "url": "https://metadeploy", "token": "TOKEN" })) task_config = TaskConfig({"options": {"tag": "release/1.0"}}) task = Publish(project_config, task_config) task._init_task() plantemplate = task._find_or_create_plan_template( { "url": "https://EXISTING_PRODUCT", "id": "abcdef" }, "install", {"slug": "install"}, ) self.assertEqual("https://NEW_PLANTEMPLATE", plantemplate["url"])
def test_freeze_steps__skip(self): project_config = create_project_config() project_config.keychain.set_service( "metadeploy", ServiceConfig({"url": "https://metadeploy", "token": "TOKEN"}) ) plan_config = { "title": "Test Install", "slug": "install", "tier": "primary", "steps": {1: {"task": "None"}}, } task_config = TaskConfig({"options": {"tag": "release/1.0"}}) task = Publish(project_config, task_config) task._init_task() steps = task._freeze_steps(project_config, plan_config) assert steps == []
def test_find_product__not_found(self): responses.add( "GET", "https://metadeploy/products?repo_url=EXISTING_REPO", json={"data": []}, ) project_config = create_project_config() project_config.config["project"]["git"]["repo_url"] = "EXISTING_REPO" project_config.keychain.set_service( "metadeploy", ServiceConfig({"url": "https://metadeploy", "token": "TOKEN"}) ) task_config = TaskConfig({"options": {"tag": "release/1.0"}}) task = Publish(project_config, task_config) task._init_task() with self.assertRaises(Exception): task._find_product()
def test_init_task__named_plan(self): project_config = create_project_config() project_config.config["project"]["git"]["repo_url"] = "EXISTING_REPO" expected_plans = { "install": { "title": "Test Install", "slug": "install", "tier": "primary", "steps": {1: {"flow": "install_prod"}}, } } project_config.config["plans"] = expected_plans project_config.keychain.set_service( "metadeploy", ServiceConfig({"url": "https://metadeploy", "token": "TOKEN"}) ) task_config = TaskConfig({"options": {"tag": "release/1.0", "plan": "install"}}) task = Publish(project_config, task_config) task._init_task() self.assertEqual(expected_plans, task.plan_configs)
def test_find_or_create_plan_template__not_found(self): responses.add( "GET", "https://metadeploy/plantemplates?product=abcdef&name=install", json={"data": []}, ) responses.add( "POST", "https://metadeploy/plantemplates", json={"url": "https://NEW_PLANTEMPLATE"}, ) responses.add( "POST", "https://metadeploy/planslug", json={"url": "http://NEW_PLANSLUG"} ) project_config = create_project_config() project_config.config["project"]["git"]["repo_url"] = "EXISTING_REPO" expected_plans = { "install": { "title": "Test Install", "slug": "install", "tier": "primary", "steps": {1: {"flow": "install_prod"}}, } } project_config.config["plans"] = expected_plans project_config.keychain.set_service( "metadeploy", ServiceConfig({"url": "https://metadeploy", "token": "TOKEN"}) ) task_config = TaskConfig({"options": {"tag": "release/1.0"}}) task = Publish(project_config, task_config) task._init_task() plantemplate = task._find_or_create_plan_template( {"url": "https://EXISTING_PRODUCT", "id": "abcdef"}, "install", {"slug": "install"}, ) self.assertEqual("https://NEW_PLANTEMPLATE", plantemplate["url"])