Fixing a few more easy lint wins

pull/11/head
Leigh Morresi 4 years ago
parent 22c7a1a88d
commit e200cd3289

@ -374,7 +374,7 @@ def changedetection_app(config=None, datastore_o=None):
# @todo check thread is running and skip # @todo check thread is running and skip
if uuid: if uuid:
if not uuid in running_uuids: if uuid not in running_uuids:
update_q.put(uuid) update_q.put(uuid)
i = 1 i = 1
@ -383,13 +383,13 @@ def changedetection_app(config=None, datastore_o=None):
for watch_uuid, watch in datastore.data['watching'].items(): for watch_uuid, watch in datastore.data['watching'].items():
if (tag != None and tag in watch['tag']): if (tag != None and tag in watch['tag']):
i += 1 i += 1
if not watch_uuid in running_uuids: if watch_uuid not in running_uuids:
update_q.put(watch_uuid) update_q.put(watch_uuid)
else: else:
# No tag, no uuid, add everything. # No tag, no uuid, add everything.
for watch_uuid, watch in datastore.data['watching'].items(): for watch_uuid, watch in datastore.data['watching'].items():
i += 1 i += 1
if not watch_uuid in running_uuids: if watch_uuid not in running_uuids:
update_q.put(watch_uuid) update_q.put(watch_uuid)
messages.append({'class': 'ok', 'message': "{} watches are rechecking.".format(i)}) messages.append({'class': 'ok', 'message': "{} watches are rechecking.".format(i)})
@ -443,9 +443,6 @@ class Worker(threading.Thread):
# A change was detected # A change was detected
datastore.save_history_text(uuid=uuid, contents=contents, result_obj=result) datastore.save_history_text(uuid=uuid, contents=contents, result_obj=result)
else:
# No change
x = 1
self.current_uuid = None # Done self.current_uuid = None # Done
self.q.task_done() self.q.task_done()

@ -1,9 +1,7 @@
import time import time
import sys
print ("Sleep loop, you should run your script from the console") print ("Sleep loop, you should run your script from the console")
while True: while True:
# Wait for 5 seconds # Wait for 5 seconds
time.sleep(2)
time.sleep(2)

@ -48,7 +48,6 @@ class perform_site_check():
stripped_text_from_html = get_text(r.text) stripped_text_from_html = get_text(r.text)
# Usually from networkIO/requests level # Usually from networkIO/requests level
except (requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout) as e: except (requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout) as e:
update_obj["last_error"] = str(e) update_obj["last_error"] = str(e)

@ -1,9 +1,8 @@
import json import json
import uuid as uuid_builder import uuid as uuid_builder
import validators
import os.path import os.path
from os import path from os import path
from threading import Lock, Thread from threading import Lock
from copy import deepcopy from copy import deepcopy

@ -3,6 +3,7 @@
import pytest import pytest
from backend import changedetection_app from backend import changedetection_app
from backend import store from backend import store
import os
# https://github.com/pallets/flask/blob/1.1.2/examples/tutorial/tests/test_auth.py # https://github.com/pallets/flask/blob/1.1.2/examples/tutorial/tests/test_auth.py
@ -19,37 +20,24 @@ def app(request):
datastore_path = "./test-datastore" datastore_path = "./test-datastore"
import os
try: try:
os.mkdir(datastore_path) os.mkdir(datastore_path)
except FileExistsError: except FileExistsError:
pass pass
try: try:
os.unlink("{}/url-watches.json".format(datastore_path)) os.unlink("{}/url-watches.json".format(datastore_path))
except FileNotFoundError: except FileNotFoundError:
pass pass
app_config = {'datastore_path': datastore_path} app_config = {'datastore_path': datastore_path}
datastore = store.ChangeDetectionStore(datastore_path=app_config['datastore_path'], include_default_watches=False) datastore = store.ChangeDetectionStore(datastore_path=app_config['datastore_path'], include_default_watches=False)
app = changedetection_app(app_config, datastore) app = changedetection_app(app_config, datastore)
# Establish an application context before running the tests.
#ctx = _app.app_context()
#ctx.push()
def teardown(): def teardown():
datastore.stop_thread = True datastore.stop_thread = True
app.config['STOP_THREADS']= True app.config['STOP_THREADS'] = True
request.addfinalizer(teardown) request.addfinalizer(teardown)
return app
#@pytest.fixture(scope='session')
#def client(app):
# with app.test_client() as client:
# yield client
return app

@ -1,12 +1,11 @@
#!/usr/bin/python3 #!/usr/bin/python3
import time import time
import pytest
from flask import url_for from flask import url_for
from urllib.request import urlopen from urllib.request import urlopen
def set_original_response():
def set_original_response():
test_return_data = """<html> test_return_data = """<html>
<body> <body>
Some initial text</br> Some initial text</br>
@ -42,7 +41,6 @@ def test_check_basic_change_detection_functionality(client, live_server):
sleep_time_for_fetch_thread = 3 sleep_time_for_fetch_thread = 3
@live_server.app.route('/test-endpoint') @live_server.app.route('/test-endpoint')
def test_endpoint(): def test_endpoint():
# Tried using a global var here but didn't seem to work, so reading from a file instead. # Tried using a global var here but didn't seem to work, so reading from a file instead.
with open("test-datastore/output.txt", "r") as f: with open("test-datastore/output.txt", "r") as f:
@ -76,8 +74,7 @@ def test_check_basic_change_detection_functionality(client, live_server):
assert b'unviewed' not in res.data assert b'unviewed' not in res.data
##################### #####################
# Make a change # Make a change
set_modified_response() set_modified_response()
@ -85,7 +82,6 @@ def test_check_basic_change_detection_functionality(client, live_server):
res = urlopen(url_for('test_endpoint', _external=True)) res = urlopen(url_for('test_endpoint', _external=True))
assert b'which has this one new line' in res.read() assert b'which has this one new line' in res.read()
# Force recheck # Force recheck
res = client.get(url_for("api_watch_checknow"), follow_redirects=True) res = client.get(url_for("api_watch_checknow"), follow_redirects=True)
assert b'1 watches are rechecking.' in res.data assert b'1 watches are rechecking.' in res.data
@ -95,4 +91,3 @@ def test_check_basic_change_detection_functionality(client, live_server):
# Now something should be ready, indicated by having a 'unviewed' class # Now something should be ready, indicated by having a 'unviewed' class
res = client.get(url_for("index")) res = client.get(url_for("index"))
assert b'unviewed' in res.data assert b'unviewed' in res.data

Loading…
Cancel
Save