diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 65783c1..15a028e 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -363,10 +363,12 @@ def get_project_from_json( user = get_user_from_json(session, jsondata) name = jsondata.get('name') + namespace = jsondata.get('namespace') project_user = None if jsondata.get('parent'): project_user = user.username - project = pagure.lib.get_project(session, name, user=project_user) + project = pagure.lib.get_project( + session, name, user=project_user, namespace=namespace) if not project: parent = None @@ -391,6 +393,7 @@ def get_project_from_json( session, user=user.username, name=name, + namespace=namespace, description=jsondata.get('description'), parent_id=parent.id if parent else None, blacklist=pagure.APP.config.get('BLACKLISTED_PROJECTS', []), @@ -404,7 +407,9 @@ def get_project_from_json( ) session.commit() - project = pagure.lib.get_project(session, name, user=user.username) + project = pagure.lib.get_project( + session, name, user=user.username, namespace=namespace) + tags = jsondata.get('tags', None) if tags: pagure.lib.add_tag_obj( diff --git a/tests/__init__.py b/tests/__init__.py index ad24c94..ab95d7d 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -272,13 +272,24 @@ def create_projects(session): item.close_status = ['Invalid', 'Insufficient data', 'Fixed', 'Duplicate'] session.add(item) + item = pagure.lib.model.Project( + user_id=1, # pingou + name='test3', + description='namespaced test project', + hook_token='aaabbbeee', + namespace='somenamespace', + ) + item.close_status = ['Invalid', 'Insufficient data', 'Fixed', 'Duplicate'] + session.add(item) + session.commit() def create_projects_git(folder, bare=False): """ Create some projects in the database. """ repos = [] - for project in ['test.git', 'test2.git']: + for project in ['test.git', 'test2.git', + os.path.join('somenamespace', 'test3.git')]: repo_path = os.path.join(folder, project) repos.append(repo_path) if not os.path.exists(repo_path): diff --git a/tests/test_pagure_flask_api_issue.py b/tests/test_pagure_flask_api_issue.py index 85f1c72..8be5d27 100644 --- a/tests/test_pagure_flask_api_issue.py +++ b/tests/test_pagure_flask_api_issue.py @@ -712,7 +712,7 @@ class PagureFlaskApiIssuetests(tests.Modeltests): item = pagure.lib.model.Token( id='pingou_foo', user_id=1, - project_id=3, + project_id=4, expiration=datetime.datetime.utcnow() + datetime.timedelta( days=30) ) @@ -932,7 +932,7 @@ class PagureFlaskApiIssuetests(tests.Modeltests): item = pagure.lib.model.Token( id='pingou_foo', user_id=1, - project_id=3, + project_id=4, expiration=datetime.datetime.utcnow() + datetime.timedelta( days=30) ) @@ -991,7 +991,7 @@ class PagureFlaskApiIssuetests(tests.Modeltests): item = pagure.lib.model.Token( id='foo_token2', user_id=2, - project_id=3, + project_id=4, expiration=datetime.datetime.utcnow() + datetime.timedelta(days=30) ) self.session.add(item) @@ -1248,7 +1248,7 @@ class PagureFlaskApiIssuetests(tests.Modeltests): item = pagure.lib.model.Token( id='pingou_foo', user_id=1, - project_id=3, + project_id=4, expiration=datetime.datetime.utcnow() + datetime.timedelta( days=30) ) @@ -1307,7 +1307,7 @@ class PagureFlaskApiIssuetests(tests.Modeltests): item = pagure.lib.model.Token( id='foo_token2', user_id=2, - project_id=3, + project_id=4, expiration=datetime.datetime.utcnow() + datetime.timedelta(days=30) ) self.session.add(item) diff --git a/tests/test_pagure_flask_api_project.py b/tests/test_pagure_flask_api_project.py index 2604813..be97a62 100644 --- a/tests/test_pagure_flask_api_project.py +++ b/tests/test_pagure_flask_api_project.py @@ -178,10 +178,11 @@ class PagureFlaskApiProjecttests(tests.Modeltests): data = json.loads(output.data) data['projects'][0]['date_created'] = "1436527638" data['projects'][1]['date_created'] = "1436527638" + data['projects'][2]['date_created'] = "1436527638" self.assertDictEqual( data, { - "total_projects": 2, + "total_projects": 3, "projects": [ { "close_status": [ @@ -226,6 +227,28 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "fullname": "PY C", "name": "pingou" } + }, + { + "close_status": [ + "Invalid", + "Insufficient data", + "Fixed", + "Duplicate" + ], + "custom_keys": [], + "date_created": "1436527638", + "description": "namespaced test project", + "id": 3, + "milestones": {}, + "name": "test3", + "namespace": "somenamespace", + "parent": None, + "priorities": {}, + "tags": [], + "user": { + "fullname": "PY C", + "name": "pingou" + } } ] } diff --git a/tests/test_pagure_flask_ui_app.py b/tests/test_pagure_flask_ui_app.py index c6abf9b..744dc24 100644 --- a/tests/test_pagure_flask_ui_app.py +++ b/tests/test_pagure_flask_ui_app.py @@ -67,14 +67,14 @@ class PagureFlaskApptests(tests.Modeltests): self.assertEqual(output.status_code, 200) self.assertIn( '

All Projects ' - '2

', output.data) + '3', output.data) # Add a 3rd project with a long description item = pagure.lib.model.Project( user_id=2, # foo name='test3', description='test project #3 with a very long description', - hook_token='aaabbbeee', + hook_token='aaabbbeeefff', ) self.session.add(item) self.session.commit() @@ -113,13 +113,13 @@ class PagureFlaskApptests(tests.Modeltests): output = self.app.get('/') self.assertIn( - 'My Projects 2', + 'My Projects 3', output.data) self.assertIn( 'My Forks 0', output.data) self.assertIn( - 'My Watch List 2', + 'My Watch List 3', output.data) def test_view_users(self): @@ -156,7 +156,7 @@ class PagureFlaskApptests(tests.Modeltests): output = self.app.get('/user/pingou?repopage=abc&forkpage=def') self.assertEqual(output.status_code, 200) self.assertIn( - 'Projects 2', + 'Projects 3', output.data) self.assertIn( 'Forks 0', output.data) diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py index f518ee8..e0087e8 100644 --- a/tests/test_pagure_flask_ui_repo.py +++ b/tests/test_pagure_flask_ui_repo.py @@ -2040,7 +2040,7 @@ index 0000000..fb7093d self.assertEqual(output.status_code, 200) self.assertIn( '
\n My Projects 5', output.data) + 'class="label label-default">6', output.data) self.assertIn( 'Forks 0', output.data) @@ -2132,7 +2132,7 @@ index 0000000..fb7093d self.assertEqual(output.status_code, 200) self.assertIn( '
\n My Projects 5', output.data) + 'class="label label-default">6', output.data) self.assertIn( 'Forks 0', output.data) @@ -2168,7 +2168,7 @@ index 0000000..fb7093d self.assertEqual(output.status_code, 200) self.assertIn( '
\n My Projects 5', output.data) + 'class="label label-default">6', output.data) self.assertIn( 'Forks 1', output.data) @@ -2224,7 +2224,7 @@ index 0000000..fb7093d 'repos from the system', output.data) self.assertIn( '
\n Projects 1', output.data) + 'class="label label-default">2', output.data) self.assertIn( 'Forks 0', output.data) @@ -2247,7 +2247,7 @@ index 0000000..fb7093d 'repos from the system' in output.data) self.assertIn( '
\n Projects 1', output.data) + 'class="label label-default">2', output.data) self.assertIn( 'Forks 0', output.data) @@ -2292,7 +2292,7 @@ index 0000000..fb7093d self.assertEqual(output.status_code, 200) self.assertIn( '
\n My Projects 2', output.data) + 'class="label label-default">3', output.data) self.assertIn( 'Forks 0', output.data) @@ -2384,7 +2384,7 @@ index 0000000..fb7093d self.assertEqual(output.status_code, 200) self.assertIn( '
\n My Projects 2', output.data) + 'class="label label-default">3', output.data) self.assertIn( 'Forks 0', output.data) @@ -2393,7 +2393,7 @@ index 0000000..fb7093d self.assertEqual(output.status_code, 200) self.assertIn( '
\n Projects 1', output.data) + 'class="label label-default">2', output.data) self.assertIn( 'Forks 0', output.data) @@ -2426,7 +2426,7 @@ index 0000000..fb7093d self.assertEqual(output.status_code, 200) self.assertIn( '
\n My Projects 1', output.data) + 'class="label label-default">2', output.data) self.assertIn( 'Forks 1', output.data) @@ -2436,7 +2436,7 @@ index 0000000..fb7093d self.assertEqual(output.status_code, 200) self.assertIn( '
\n Projects 1', output.data) + 'class="label label-default">2', output.data) self.assertIn( 'Forks 0', output.data) diff --git a/tests/test_pagure_lib.py b/tests/test_pagure_lib.py index 9f1fc36..e26a565 100644 --- a/tests/test_pagure_lib.py +++ b/tests/test_pagure_lib.py @@ -970,7 +970,7 @@ class PagureLibtests(tests.Modeltests): tests.create_projects(self.session) projects = pagure.lib.search_projects(self.session) - self.assertEqual(len(projects), 2) + self.assertEqual(len(projects), 3) self.assertEqual(projects[0].id, 1) self.assertEqual(projects[1].id, 2) @@ -978,12 +978,12 @@ class PagureLibtests(tests.Modeltests): self.assertEqual(len(projects), 0) projects = pagure.lib.search_projects(self.session, username='pingou') - self.assertEqual(len(projects), 2) + self.assertEqual(len(projects), 3) self.assertEqual(projects[0].id, 1) self.assertEqual(projects[1].id, 2) projects = pagure.lib.search_projects(self.session, start=1) - self.assertEqual(len(projects), 1) + self.assertEqual(len(projects), 2) self.assertEqual(projects[0].id, 2) projects = pagure.lib.search_projects(self.session, limit=1) @@ -991,7 +991,7 @@ class PagureLibtests(tests.Modeltests): self.assertEqual(projects[0].id, 1) projects = pagure.lib.search_projects(self.session, count=True) - self.assertEqual(projects, 2) + self.assertEqual(projects, 3) def test_search_project_forked(self): """ Test the search_project for forked projects in pagure.lib. """ @@ -1022,7 +1022,7 @@ class PagureLibtests(tests.Modeltests): projects = pagure.lib.search_projects(self.session, fork=True) self.assertEqual(len(projects), 2) projects = pagure.lib.search_projects(self.session, fork=False) - self.assertEqual(len(projects), 2) + self.assertEqual(len(projects), 3) def test_get_tags_of_project(self): """ Test the get_tags_of_project of pagure.lib. """ @@ -1581,7 +1581,7 @@ class PagureLibtests(tests.Modeltests): prs = pagure.lib.search_pull_requests( session=self.session, - project_id_from=3 + project_id_from=4 ) self.assertEqual(len(prs), 1) @@ -1988,13 +1988,13 @@ class PagureLibtests(tests.Modeltests): projects = pagure.lib.search_projects(self.session) for proj in projects: - self.assertIn(proj.hook_token, ['aaabbbccc', 'aaabbbddd']) + self.assertIn(proj.hook_token, ['aaabbbccc', 'aaabbbddd', 'aaabbbeee']) pagure.lib.generate_hook_token(self.session) projects = pagure.lib.search_projects(self.session) for proj in projects: - self.assertNotIn(proj.hook_token, ['aaabbbccc', 'aaabbbddd']) + self.assertNotIn(proj.hook_token, ['aaabbbccc', 'aaabbbddd', 'aaabbbeee']) @patch('pagure.lib.notify.send_email') def test_pull_request_score(self, mockemail): @@ -2664,7 +2664,7 @@ class PagureLibtests(tests.Modeltests): user='pingou', ) watch_list = [obj.name for obj in watch_list_objs] - self.assertEqual(watch_list, ['test', 'test2']) + self.assertEqual(watch_list, ['test', 'test2', 'test3']) # He isn't in the db, thus not watching anything user.username = 'vivek' diff --git a/tests/test_pagure_lib_git.py b/tests/test_pagure_lib_git.py index 2005554..f963777 100644 --- a/tests/test_pagure_lib_git.py +++ b/tests/test_pagure_lib_git.py @@ -116,6 +116,20 @@ repo tickets/test2 repo requests/test2 RW+ = pingou +repo somenamespace/test3 + R = @all + RW+ = pingou + +repo docs/somenamespace/test3 + R = @all + RW+ = pingou + +repo tickets/somenamespace/test3 + RW+ = pingou + +repo requests/somenamespace/test3 + RW+ = pingou + repo forks/pingou/test3 R = @all RW+ = pingou @@ -258,6 +272,20 @@ repo tickets/test2 repo requests/test2 RW+ = pingou +repo somenamespace/test3 + R = @all + RW+ = pingou + +repo docs/somenamespace/test3 + R = @all + RW+ = pingou + +repo tickets/somenamespace/test3 + RW+ = pingou + +repo requests/somenamespace/test3 + RW+ = pingou + repo forks/pingou/test2 R = @all RW+ = pingou @@ -973,10 +1001,14 @@ index 0000000..60f7480 tests.create_projects_git(os.path.join(self.path, 'repos')) repo = pagure.lib.get_project(self.session, 'test') + namespaced_repo = pagure.lib.get_project( + self.session, 'test3', namespace='somenamespace') # Before self.assertEqual(len(repo.requests), 0) self.assertEqual(repo.requests, []) + self.assertEqual(len(namespaced_repo.requests), 0) + self.assertEqual(namespaced_repo.requests, []) data = { "status": True, @@ -1262,6 +1294,116 @@ index 0000000..60f7480 self.assertEqual(repo.requests[1].title, 'test request #2') self.assertEqual(len(repo.requests[1].comments), 0) + data = { + "status": True, + "uid": "d4182a2ac2d541d884742d3037c26e58", + "project": { + "parent": None, + "name": "test3", + "custom_keys": [], + "namespace": "somenamespace", + "date_created": "1426500194", + "tags": [], + "user": { + "fullname": "Pierre-YvesChibon", + "name": "pingou", + "default_email": "pingou@fedoraproject.org", + "emails": [ + "pingou@fedoraproject.org" + ] + }, + "settings": { + "issue_tracker": True, + "project_documentation": True, + "pull_requests": True, + }, + "id": 3, + "description": "namespaced test project" + }, + "commit_stop": "eface8e13bc2a08a3fb22af9a72a8c90e36b8b89", + "user": { + "fullname": "Pierre-YvesChibon", + "name": "pingou", + "default_email": "pingou@fedoraproject.org", + "emails": ["pingou@fedoraproject.org"] + }, + "id": 5, + "comments": [], + "branch_from": "master", + "title": "test request to namespaced repo", + "commit_start": "788efeaaf86bde8618f594a8181abb402e1dd904", + "repo_from": { + "parent": { + "parent": None, + "name": "test", + "custom_keys": [], + "date_created": "1426500194", + "tags": [], + "user": { + "fullname": "Pierre-YvesChibon", + "name": "pingou", + "default_email": "pingou@fedoraproject.org", + "emails": [ + "pingou@fedoraproject.org" + ] + }, + "settings": { + "issue_tracker": True, + "project_documentation": True, + "pull_requests": True, + }, + "id": 1, + "description": "test project" + }, + "settings": { + "issue_tracker": True, + "project_documentation": True, + "pull_requests": True, + }, + "name": "test", + "date_created": "1426843440", + "custom_keys": [], + "tags": [], + "user": { + "fullname": "fake user", + "name": "fake", + "default_email": "fake@fedoraproject.org", + "emails": [ + "fake@fedoraproject.org" + ] + }, + "project_docs": True, + "id": 6, + "description": "test project" + }, + "branch": "master", + "date_created": "1426843745" + } + pagure.lib.git.update_request_from_git( + self.session, + reponame='test3', + namespace='somenamespace', + username=None, + request_uid='d4182a2ac2d541d884742d3037c26e58', + json_data=data, + gitfolder=self.path, + docfolder=os.path.join(self.path, 'docs'), + ticketfolder=os.path.join(self.path, 'tickets'), + requestfolder=os.path.join(self.path, 'requests') + ) + self.session.commit() + + self.assertEqual(len(namespaced_repo.requests), 1) + self.assertEqual(namespaced_repo.requests[0].id, 5) + self.assertEqual( + namespaced_repo.requests[0].uid, + 'd4182a2ac2d541d884742d3037c26e58' + ) + self.assertEqual( + namespaced_repo.requests[0].title, + 'test request to namespaced repo' + ) + def test_read_git_lines(self): """ Test the read_git_lines method of pagure.lib.git. """ self.test_update_git()