Skip to content

Commit

Permalink
Add duplicate() method to Project (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
psybers committed Dec 24, 2023
1 parent 380660e commit df5c3ab
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions changes/161.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a duplicate() method to Project.
12 changes: 12 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ Create a project
new_project = api.projects.create('TEST PROJECT', 'TESTING API')
******************************************************
Duplicate an existing project
******************************************************

If you have a project, you can duplicate it (duplicates most of the settings,
but not the user stories or tasks)

.. code:: python
old_project = api.projects.get_by_slug('nephila')
new_project = old_project.duplicate('TEST PROJECT', 'TESTING API')
******************************************************
Create a new user story
******************************************************
Expand Down
14 changes: 14 additions & 0 deletions taiga/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,20 @@ def list_tags(self):
response = self.requester.get("/{}/{}/tags_colors".format(self.endpoint, self.id))
return response.json()

def duplicate(self, name, description, is_private=False, users=[], **attrs):
"""
Duplicate a :class:`Project`
:param name: name of new :class:`Project`
:param description: description of new :class:`Project`
:param is_private: determines if the project is private or not
:param users: users of the new :class:`Project`
:param attrs: optional attributes for the new :class:`Project`
"""
attrs.update({"name": name, "description": description, "is_private": is_private, "users": users})
response = self.requester.post("/{endpoint}/{id}/duplicate", payload=attrs, endpoint=self.endpoint, id=self.id)
return self.parse(self.requester, response.json())


class Projects(ListResource):
"""
Expand Down
12 changes: 12 additions & 0 deletions tests/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,18 @@ def test_import_project(self, mock_requestmaker_post):
endpoint="importer",
)

@patch("taiga.requestmaker.RequestMaker.post")
def test_duplicate_project(self, mock_requestmaker_post):
rm = RequestMaker("/api/v1", "fakehost", "faketoken")
project = Project(rm, id=1)
project.duplicate("PR 1 1", "PR 1 desc 1")
mock_requestmaker_post.assert_called_with(
"/{endpoint}/{id}/duplicate",
payload={"name": "PR 1 1", "description": "PR 1 desc 1", "is_private": False, "users": []},
endpoint="projects",
id=project.id,
)

@patch("taiga.models.IssueStatuses.create")
def test_add_issue_status(self, mock_new_issue_status):
rm = RequestMaker("/api/v1", "fakehost", "faketoken")
Expand Down

0 comments on commit df5c3ab

Please sign in to comment.