diff --git a/pagure/api/project.py b/pagure/api/project.py index 11571b6..50d9625 100644 --- a/pagure/api/project.py +++ b/pagure/api/project.py @@ -672,44 +672,57 @@ def api_new_project(): Input ^^^^^ - +------------------+---------+--------------+---------------------------+ - | Key | Type | Optionality | Description | - +==================+=========+==============+===========================+ - | ``name`` | string | Mandatory | | The name of the new | - | | | | project. | - +------------------+---------+--------------+---------------------------+ - | ``description`` | string | Mandatory | | A short description of | - | | | | the new project. | - +------------------+---------+--------------+---------------------------+ - | ``namespace`` | string | Optional | | The namespace of the | - | | | | project to fork. | - +------------------+---------+--------------+---------------------------+ - | ``url`` | string | Optional | | An url providing more | - | | | | information about the | - | | | | project. | - +------------------+---------+--------------+---------------------------+ - | ``avatar_email`` | string | Optional | | An email address for the| - | | | | avatar of the project. | - +------------------+---------+--------------+---------------------------+ - | ``create_readme``| boolean | Optional | | A boolean to specify if | - | | | | there should be a readme| - | | | | added to the project on | - | | | | creation. | - +------------------+---------+--------------+---------------------------+ - | ``private`` | boolean | Optional | | A boolean to specify if | - | | | | the project to create | - | | | | is private. | - | | | | Note: not all pagure | - | | | | instance support private| - | | | | projects, confirm this | - | | | | with your administrators| - +------------------+---------+--------------+---------------------------+ - | ``wait`` | boolean | Optional | | A boolean to specify if | - | | | | this API call should | - | | | | return a taskid or if it| - | | | | should wait for the task| - | | | | to finish. | - +------------------+---------+--------------+---------------------------+ + +----------------------------+---------+--------------+---------------------------+ + | Key | Type | Optionality | Description | + +============================+=========+==============+===========================+ + | ``name`` | string | Mandatory | | The name of the new | + | | | | project. | + +----------------------------+---------+--------------+---------------------------+ + | ``description`` | string | Mandatory | | A short description of | + | | | | the new project. | + +----------------------------+---------+--------------+---------------------------+ + | ``namespace`` | string | Optional | | The namespace of the | + | | | | project to fork. | + +----------------------------+---------+--------------+---------------------------+ + | ``url`` | string | Optional | | An url providing more | + | | | | information about the | + | | | | project. | + +----------------------------+---------+--------------+---------------------------+ + | ``avatar_email`` | string | Optional | | An email address for the| + | | | | avatar of the project. | + +----------------------------+---------+--------------+---------------------------+ + | ``create_readme`` | boolean | Optional | | A boolean to specify if | + | | | | there should be a readme| + | | | | added to the project on | + | | | | creation. | + +----------------------------+---------+--------------+---------------------------+ + | ``private`` | boolean | Optional | | A boolean to specify if | + | | | | the project to create | + | | | | is private. | + | | | | Note: not all pagure | + | | | | instance support private| + | | | | projects, confirm this | + | | | | with your administrators| + +----------------------------+---------+--------------+---------------------------+ + | ``ignore_existing_repos`` | boolean | Optional | | Only available to admins| + | | | | this option allows them | + | | | | to make project creation| + | | | | pass even if there is | + | | | | already a coresopnding | + | | | | git repository on disk | + +----------------------------+---------+--------------+---------------------------+ + | ``repospanner_region`` | boolean | Optional | | Only available to admins| + | | | | this option allows them | + | | | | to override the default | + | | | | respoSpanner region | + | | | | configured | + +----------------------------+---------+--------------+---------------------------+ + | ``wait`` | boolean | Optional | | A boolean to specify if | + | | | | this API call should | + | | | | return a taskid or if it| + | | | | should wait for the task| + | | | | to finish. | + +----------------------------+---------+--------------+---------------------------+ Sample response ^^^^^^^^^^^^^^^ @@ -727,7 +740,7 @@ def api_new_project(): 'message': 'Project creation queued' } - """ + """ # noqa user = pagure.lib.search_user( flask.g.session, username=flask.g.fas_user.username ) diff --git a/tests/test_pagure_flask_api_project.py b/tests/test_pagure_flask_api_project.py index 8911795..5528850 100644 --- a/tests/test_pagure_flask_api_project.py +++ b/tests/test_pagure_flask_api_project.py @@ -2107,6 +2107,59 @@ class PagureFlaskApiProjecttests(tests.Modeltests): {'message': 'Project "test_42" created'} ) + @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.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')) + item = pagure.lib.model.Token( + id='aaabbbcccddd', + user_id=1, + project_id=None, + expiration=datetime.datetime.utcnow() + datetime.timedelta(days=10) + ) + self.session.add(item) + self.session.commit() + tests.create_tokens_acl(self.session) + + headers = {'Authorization': 'token aaabbbcccddd'} + + user = tests.FakeUser(username='pingou') + with tests.user_set(self.app.application, user): + input_data = { + 'name': 'test', + 'description': 'Project #1', + } + + # Valid request + output = self.app.post( + '/api/0/new/', data=input_data, headers=headers) + self.assertEqual(output.status_code, 400) + data = json.loads(output.get_data(as_text=True)) + self.assertDictEqual( + data, + { + 'error': 'The main repo test.git already exists', + 'error_code': 'ENOCODE' + } + ) + + input_data['ignore_existing_repos'] = 'y' + # Valid request + output = self.app.post( + '/api/0/new/', data=input_data, headers=headers) + self.assertEqual(output.status_code, 200) + data = json.loads(output.get_data(as_text=True)) + self.assertDictEqual( + data, + {'message': 'Project "test" created'} + ) + @patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True}) def test_api_new_project_private(self): """ Test the api_new_project method of the flask api to create @@ -3727,6 +3780,5 @@ class PagureFlaskApiProjectModifyAclTests(tests.Modeltests): {u'admin': [], u'commit': [], u'ticket': []} ) - if __name__ == '__main__': unittest.main(verbosity=2)