Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/161 - Add duplicate() method to Project (#161) #163

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading