@@ -793,6 +793,10 @@ def changedetection_app(config=None, datastore_o=None):
|
|||||||
@login_required
|
@login_required
|
||||||
def api_clone():
|
def api_clone():
|
||||||
uuid = request.args.get('uuid')
|
uuid = request.args.get('uuid')
|
||||||
|
# More for testing, possible to return the first/only
|
||||||
|
if uuid == 'first':
|
||||||
|
uuid = list(datastore.data['watching'].keys()).pop()
|
||||||
|
|
||||||
new_uuid = datastore.clone(uuid)
|
new_uuid = datastore.clone(uuid)
|
||||||
update_q.put(new_uuid)
|
update_q.put(new_uuid)
|
||||||
flash('Cloned.')
|
flash('Cloned.')
|
||||||
|
|||||||
@@ -260,7 +260,8 @@ class ChangeDetectionStore:
|
|||||||
def clone(self, uuid):
|
def clone(self, uuid):
|
||||||
url = self.data['watching'][uuid]['url']
|
url = self.data['watching'][uuid]['url']
|
||||||
tag = self.data['watching'][uuid]['tag']
|
tag = self.data['watching'][uuid]['tag']
|
||||||
new_uuid = self.add_watch(url=url, tag=tag)
|
extras = self.data['watching'][uuid]
|
||||||
|
new_uuid = self.add_watch(url=url, tag=tag, extras=extras)
|
||||||
return new_uuid
|
return new_uuid
|
||||||
|
|
||||||
def url_exists(self, url):
|
def url_exists(self, url):
|
||||||
@@ -318,17 +319,27 @@ class ChangeDetectionStore:
|
|||||||
self.needs_write = True
|
self.needs_write = True
|
||||||
return changes_removed
|
return changes_removed
|
||||||
|
|
||||||
def add_watch(self, url, tag):
|
def add_watch(self, url, tag, extras=None):
|
||||||
|
if extras is None:
|
||||||
|
extras = {}
|
||||||
|
|
||||||
with self.lock:
|
with self.lock:
|
||||||
# @todo use a common generic version of this
|
# @todo use a common generic version of this
|
||||||
new_uuid = str(uuid_builder.uuid4())
|
new_uuid = str(uuid_builder.uuid4())
|
||||||
_blank = deepcopy(self.generic_definition)
|
_blank = deepcopy(self.generic_definition)
|
||||||
_blank.update({
|
_blank.update({
|
||||||
'url': url,
|
'url': url,
|
||||||
'tag': tag,
|
'tag': tag
|
||||||
'uuid': new_uuid
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Incase these are copied across, assume it's a reference and deepcopy()
|
||||||
|
apply_extras = deepcopy(extras)
|
||||||
|
for k in ['uuid', 'history', 'last_checked', 'last_changed', 'newest_history_key', 'previous_md5', 'viewed']:
|
||||||
|
if k in apply_extras:
|
||||||
|
del apply_extras[k]
|
||||||
|
|
||||||
|
_blank.update(apply_extras)
|
||||||
|
|
||||||
self.data['watching'][new_uuid] = _blank
|
self.data['watching'][new_uuid] = _blank
|
||||||
|
|
||||||
# Get the directory ready
|
# Get the directory ready
|
||||||
|
|||||||
30
changedetectionio/tests/test_clone.py
Normal file
30
changedetectionio/tests/test_clone.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import time
|
||||||
|
from flask import url_for
|
||||||
|
from . util import live_server_setup
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_trigger_functionality(client, live_server):
|
||||||
|
|
||||||
|
live_server_setup(live_server)
|
||||||
|
|
||||||
|
# Give the endpoint time to spin up
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
# Add our URL to the import page
|
||||||
|
res = client.post(
|
||||||
|
url_for("import_page"),
|
||||||
|
data={"urls": "https://changedetection.io"},
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
|
assert b"1 Imported" in res.data
|
||||||
|
|
||||||
|
|
||||||
|
res = client.get(
|
||||||
|
url_for("api_clone", uuid="first"),
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
|
|
||||||
|
assert b"Cloned." in res.data
|
||||||
Reference in New Issue
Block a user