API-interface
dgtlmoon 3 years ago
parent 1caff23d2c
commit 37614224e5

@ -1,5 +1,6 @@
from flask_restful import reqparse, abort, Api, Resource
from flask_restful import abort, Resource
from flask import request
# https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
class Watch(Resource):
@ -33,9 +34,6 @@ class Watch(Resource):
self.datastore.delete(uuid)
return '', 204
class WatchHistory(Resource):
def __init__(self, **kwargs):
# datastore is a black box dependency
@ -69,6 +67,7 @@ class WatchSingleHistory(Resource):
self.datastore.delete(uuid)
return '', 204
class CreateWatch(Resource):
def __init__(self, **kwargs):
# datastore is a black box dependency

@ -4,71 +4,20 @@ import time
from flask import url_for
from . util import live_server_setup
def test_setup(live_server):
live_server_setup(live_server)
def set_response_data(test_return_data):
with open("test-datastore/endpoint-content.txt", "w") as f:
f.write(test_return_data)
def test_snapshot_api_detects_change(client, live_server):
test_return_data = "Some initial text"
test_return_data_modified = "Some NEW nice initial text"
sleep_time_for_fetch_thread = 3
set_response_data(test_return_data)
# Give the endpoint time to spin up
time.sleep(1)
def test_api_simple(client, live_server):
live_server_setup(live_server)
# Add our URL to the import page
test_url = url_for('test_endpoint', content_type="text/plain",
_external=True)
res = client.post(
url_for("import_page"),
data={"urls": test_url},
follow_redirects=True
)
assert b"1 Imported" in res.data
# Trigger a check
client.get(url_for("api_watch_checknow"), follow_redirects=True)
# Give the thread time to pick it up
time.sleep(sleep_time_for_fetch_thread)
res = client.get(
url_for("api_snapshot", uuid="first"),
follow_redirects=True
)
assert test_return_data.encode() == res.data
# Make a change
set_response_data(test_return_data_modified)
# Trigger a check
client.get(url_for("api_watch_checknow"), follow_redirects=True)
# Give the thread time to pick it up
time.sleep(sleep_time_for_fetch_thread)
res = client.get(
url_for("api_snapshot", uuid="first"),
url_for("createwatch"),
data={"url": "https://nice.com"},
headers={'content-type': 'application/json'},
follow_redirects=True
)
assert len(res.data) >= 20
assert res.status_code == 201
assert test_return_data_modified.encode() == res.data
def test_snapshot_api_invalid_uuid(client, live_server):
res = client.get(
url_for("api_snapshot", uuid="invalid"),
follow_redirects=True
)
# try invalid url
assert res.status_code == 400
#assert res.status_code == 400

Loading…
Cancel
Save