Skip to content

fix: fixing bugs in clone_task function #217

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

Merged
merged 7 commits into from
Mar 24, 2021
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Bug Fixes
1. [#206](https://github.com/influxdata/influxdb-client-python/pull/207): Use default (system) certificates instead of Mozilla's root certificates (certifi.where())
1. [#217](https://github.com/influxdata/influxdb-client-python/pull/217): Fixed clone_task function

### API
1. [#209](https://github.com/influxdata/influxdb-client-python/pull/209): Allow setting shard-group durations for buckets via API
Expand Down
9 changes: 5 additions & 4 deletions influxdb_client/client/tasks_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ def update_task_request(self, task_id, task_update_request: TaskUpdateRequest) -

def clone_task(self, task: Task) -> Task:
"""Clone a task."""
cloned = Task(name=task.name, org_id=task.org_id, org=task.org, flux=task.flux, status="active")
cloned = Task(id=0, name=task.name, org_id=task.org_id, org=task.org, flux=task.flux, status="active")

created = self.create_task(cloned)
labels = self.get_labels(task)
for label in labels:
self.add_label(label, created.id)
if task.id:
labels = self.get_labels(task.id)
for label in labels.labels:
self.add_label(label.id, created.id)
return created

def get_labels(self, task_id):
Expand Down
20 changes: 19 additions & 1 deletion tests/test_TasksApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def test_create_task_with_offset(self):
def test_create_task_every(self):
task_name = self.generate_name("it_task")
task = self.tasks_api.create_task_every(task_name, TASK_FLUX, "1h", self.organization)
print(task)

self.assertIsNotNone(task)
self.assertGreater(len(task.id), 1)
Expand Down Expand Up @@ -391,3 +390,22 @@ def test_get_run(self):
self.assertIsNotNone(run_by_id)
self.assertEqual(run.id, run_by_id.id)

def test_clone(self):
task = self.tasks_api.create_task_every(self.generate_name("it_task"), TASK_FLUX, "1h", self.organization)
label = self.labels_api.create_label(self.generate_name("it_task"), self.organization.id, {
"color": "green",
"location": "west"
})
self.tasks_api.add_label(label.id, task.id)
cloned = self.tasks_api.clone_task(task)
self.assertNotEqual(task.id, cloned.id)
self.assertEqual(task.flux, cloned.flux)
labels = self.tasks_api.get_labels(cloned.id).labels
self.assertEqual(1, len(labels))
self.assertEqual(label.id, labels[0].id)

def test_clone_new(self):
task = self.tasks_api._create_task(self.generate_name("it_task"), TASK_FLUX, "1h", None, self.organization.id)
cloned = self.tasks_api.clone_task(task)
self.assertNotEqual(task.id, cloned.id)
self.assertEqual(task.flux, cloned.flux)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy