diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index f8794e80..50c0d436 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -1028,6 +1028,11 @@ def changedetection_app(config=None, datastore_o=None): @login_required def api_delete(): uuid = request.args.get('uuid') + + if uuid != 'all' and not uuid in datastore.data['watching'].keys(): + flash('The watch by UUID {} does not exist.'.format(uuid), 'error') + return redirect(url_for('index')) + # More for testing, possible to return the first/only if uuid == 'first': uuid = list(datastore.data['watching'].keys()).pop() diff --git a/changedetectionio/model/Watch.py b/changedetectionio/model/Watch.py index b148f584..c0313868 100644 --- a/changedetectionio/model/Watch.py +++ b/changedetectionio/model/Watch.py @@ -22,7 +22,8 @@ class model(dict): 'newest_history_key': 0, 'title': None, 'previous_md5': False, - 'uuid': str(uuid_builder.uuid4()), +# UUID not needed, should be generated only as a key +# 'uuid': 'headers': {}, # Extra headers to send 'body': None, 'method': 'GET', diff --git a/changedetectionio/store.py b/changedetectionio/store.py index bb4bab11..c95c172c 100644 --- a/changedetectionio/store.py +++ b/changedetectionio/store.py @@ -38,7 +38,8 @@ class ChangeDetectionStore: self.__data = App.model() # Base definition for all watchers - self.generic_definition = Watch.model() + # deepcopy part of #569 - not sure why its needed exactly + self.generic_definition = deepcopy(Watch.model()) if path.isfile('changedetectionio/source.txt'): with open('changedetectionio/source.txt') as f: @@ -231,7 +232,7 @@ class ChangeDetectionStore: del self.data['watching'][uuid] - self.needs_write = True + self.needs_write_urgent = True # Clone a watch by UUID def clone(self, uuid): @@ -330,10 +331,13 @@ class ChangeDetectionStore: with self.lock: # @todo use a common generic version of this new_uuid = str(uuid_builder.uuid4()) - new_watch = Watch.model({ + # #Re 569 + # Not sure why deepcopy was needed here, sometimes new watches would appear to already have 'history' set + # I assumed this would instantiate a new object but somehow an existing dict was getting used + new_watch = deepcopy(Watch.model({ 'url': url, 'tag': tag - }) + })) for k in ['uuid', 'history', 'last_checked', 'last_changed', 'newest_history_key', 'previous_md5', 'viewed']: diff --git a/changedetectionio/tests/test_notification.py b/changedetectionio/tests/test_notification.py index 5cd2d0c7..178a152b 100644 --- a/changedetectionio/tests/test_notification.py +++ b/changedetectionio/tests/test_notification.py @@ -156,7 +156,7 @@ def test_check_notification(client, live_server): # cleanup for the next client.get( - url_for("api_delete", uuid="first"), + url_for("api_delete", uuid="all"), follow_redirects=True ) @@ -172,8 +172,7 @@ def test_notification_validation(client, live_server): data={"url": test_url, "tag": 'nice one'}, follow_redirects=True ) - with open("xxx.bin", "wb") as f: - f.write(res.data) + assert b"Watch added" in res.data # Re #360 some validation @@ -209,6 +208,6 @@ def test_notification_validation(client, live_server): # cleanup for the next client.get( - url_for("api_delete", uuid="first"), + url_for("api_delete", uuid="all"), follow_redirects=True )