From 2a0516ac5bbabaf0f92c6e93b00aa7c60dde0c05 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 03 2020 17:15:32 +0000 Subject: Move all the test testing creating new projects to their own class This will make it easier to test only this use-case as well as re-using code if needed. Signed-off-by: Pierre-Yves Chibon --- diff --git a/tests/test_pagure_flask_ui_app.py b/tests/test_pagure_flask_ui_app.py index c2b7700..790b0cb 100644 --- a/tests/test_pagure_flask_ui_app.py +++ b/tests/test_pagure_flask_ui_app.py @@ -180,193 +180,269 @@ class PagureFlaskApptests(tests.Modeltests): output_text, ) - @patch.dict("pagure.config.config", {"ENABLE_UI_NEW_PROJECTS": False}) - def test_new_project_when_turned_off_in_the_ui(self): - """ Test the new_project endpoint when new project creation is - not allowed in the UI of this pagure instance. """ + @patch.dict( + "pagure.config.config", + { + "PAGURE_ADMIN_USERS": ["pingou"], + "ALLOW_ADMIN_IGNORE_EXISTING_REPOS": True, + }, + ) + def test_adopt_repos(self): + """ Test the new_project endpoint with existing git repo. """ + # Before + projects = pagure.lib.query.search_projects(self.session) + self.assertEqual(len(projects), 0) + tests.create_projects_git(os.path.join(self.path, "repos"), bare=True) + tests.add_content_git_repo( + os.path.join(self.path, "repos", "test.git") + ) - user = tests.FakeUser(username="foo") + user = tests.FakeUser(username="pingou") with tests.user_set(self.app.application, user): - output = self.app.get("/new/") - self.assertEqual(output.status_code, 404) - - data = {"description": "Project #1", "name": "project-1"} + data = { + "csrf_token": self.get_csrf(), + "name": "test", + "description": "Project #1", + } output = self.app.post("/new/", data=data, follow_redirects=True) - self.assertEqual(output.status_code, 404) - - @patch.dict("pagure.config.config", {"ENABLE_UI_NEW_PROJECTS": False}) - def test_new_project_button_when_turned_off_in_the_ui_no_project(self): - """ Test the index endpoint when new project creation is - not allowed in the UI of this pagure instance. """ + self.assertEqual(output.status_code, 200) + output_text = output.get_data(as_text=True) + self.assertIn("The main repo test.git already exists", output_text) - user = tests.FakeUser(username="foo") - with tests.user_set(self.app.application, user): - output = self.app.get("/", follow_redirects=True) + data["ignore_existing_repos"] = "y" + output = self.app.post("/new/", data=data, follow_redirects=True) self.assertEqual(output.status_code, 200) output_text = output.get_data(as_text=True) - self.assertIn( - '

My Projects

', - output_text, - ) - # master template - self.assertNotIn( - '