pull/1641/head
parent
72311fb845
commit
52f2c00308
@ -0,0 +1,9 @@
|
|||||||
|
# Groups tags
|
||||||
|
|
||||||
|
## How it works
|
||||||
|
|
||||||
|
Watch has a list() of tag UUID's, which relate to a config under application.settings.tags
|
||||||
|
|
||||||
|
The 'tag' is actually a watch, because they basically will eventually share 90% of the same config.
|
||||||
|
|
||||||
|
So a tag is like an abstract of a watch
|
@ -0,0 +1,131 @@
|
|||||||
|
from flask import Blueprint, request, make_response, render_template, flash, url_for, redirect
|
||||||
|
from changedetectionio.store import ChangeDetectionStore
|
||||||
|
from changedetectionio import login_optionally_required
|
||||||
|
|
||||||
|
|
||||||
|
def construct_blueprint(datastore: ChangeDetectionStore):
|
||||||
|
tags_blueprint = Blueprint('tags', __name__, template_folder="templates")
|
||||||
|
|
||||||
|
@tags_blueprint.route("/list", methods=['GET'])
|
||||||
|
@login_optionally_required
|
||||||
|
def tags_overview_page():
|
||||||
|
from .form import SingleTag
|
||||||
|
add_form = SingleTag(request.form)
|
||||||
|
output = render_template("groups-overview.html",
|
||||||
|
form=add_form,
|
||||||
|
available_tags=datastore.data['settings']['application'].get('tags', {}),
|
||||||
|
)
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
||||||
|
@tags_blueprint.route("/add", methods=['POST'])
|
||||||
|
@login_optionally_required
|
||||||
|
def form_tag_add():
|
||||||
|
from .form import SingleTag
|
||||||
|
add_form = SingleTag(request.form)
|
||||||
|
|
||||||
|
if not add_form.validate():
|
||||||
|
for widget, l in add_form.errors.items():
|
||||||
|
flash(','.join(l), 'error')
|
||||||
|
return redirect(url_for('tags.tags_overview_page'))
|
||||||
|
|
||||||
|
title = request.form.get('name').strip()
|
||||||
|
|
||||||
|
if datastore.tag_exists_by_name(title):
|
||||||
|
flash(f'The tag "{title}" already exists', "error")
|
||||||
|
return redirect(url_for('tags.tags_overview_page'))
|
||||||
|
|
||||||
|
datastore.add_tag(title)
|
||||||
|
flash("Tag added")
|
||||||
|
|
||||||
|
|
||||||
|
return redirect(url_for('tags.tags_overview_page'))
|
||||||
|
|
||||||
|
@tags_blueprint.route("/mute/<string:uuid>", methods=['GET'])
|
||||||
|
@login_optionally_required
|
||||||
|
def mute(uuid):
|
||||||
|
if datastore.data['settings']['application']['tags'].get(uuid):
|
||||||
|
datastore.data['settings']['application']['tags'][uuid]['notification_muted'] = not datastore.data['settings']['application']['tags'][uuid]['notification_muted']
|
||||||
|
return redirect(url_for('tags.tags_overview_page'))
|
||||||
|
|
||||||
|
@tags_blueprint.route("/delete/<string:uuid>", methods=['GET'])
|
||||||
|
@login_optionally_required
|
||||||
|
def delete(uuid):
|
||||||
|
removed = 0
|
||||||
|
# Delete the tag, and any tag reference
|
||||||
|
if datastore.data['settings']['application']['tags'].get(uuid):
|
||||||
|
del datastore.data['settings']['application']['tags'][uuid]
|
||||||
|
|
||||||
|
for watch_uuid, watch in datastore.data['watching'].items():
|
||||||
|
if watch.get('tags') and uuid in watch['tags']:
|
||||||
|
removed += 1
|
||||||
|
watch['tags'].remove(uuid)
|
||||||
|
|
||||||
|
flash(f"Tag deleted and removed from {removed} watches")
|
||||||
|
return redirect(url_for('tags.tags_overview_page'))
|
||||||
|
|
||||||
|
@tags_blueprint.route("/unlink/<string:uuid>", methods=['GET'])
|
||||||
|
@login_optionally_required
|
||||||
|
def unlink(uuid):
|
||||||
|
unlinked = 0
|
||||||
|
for watch_uuid, watch in datastore.data['watching'].items():
|
||||||
|
if watch.get('tags') and uuid in watch['tags']:
|
||||||
|
unlinked += 1
|
||||||
|
watch['tags'].remove(uuid)
|
||||||
|
|
||||||
|
flash(f"Tag unlinked removed from {unlinked} watches")
|
||||||
|
return redirect(url_for('tags.tags_overview_page'))
|
||||||
|
|
||||||
|
@tags_blueprint.route("/edit/<string:uuid>", methods=['GET'])
|
||||||
|
@login_optionally_required
|
||||||
|
def form_tag_edit(uuid):
|
||||||
|
from changedetectionio import forms
|
||||||
|
|
||||||
|
if uuid == 'first':
|
||||||
|
uuid = list(datastore.data['settings']['application']['tags'].keys()).pop()
|
||||||
|
|
||||||
|
default = datastore.data['settings']['application']['tags'].get(uuid)
|
||||||
|
|
||||||
|
form = forms.watchForm(formdata=request.form if request.method == 'POST' else None,
|
||||||
|
data=default,
|
||||||
|
)
|
||||||
|
form.datastore=datastore # needed?
|
||||||
|
|
||||||
|
output = render_template("edit-tag.html",
|
||||||
|
data=default,
|
||||||
|
form=form,
|
||||||
|
settings_application=datastore.data['settings']['application'],
|
||||||
|
)
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
@tags_blueprint.route("/edit/<string:uuid>", methods=['POST'])
|
||||||
|
@login_optionally_required
|
||||||
|
def form_tag_edit_submit(uuid):
|
||||||
|
from changedetectionio import forms
|
||||||
|
if uuid == 'first':
|
||||||
|
uuid = list(datastore.data['settings']['application']['tags'].keys()).pop()
|
||||||
|
|
||||||
|
default = datastore.data['settings']['application']['tags'].get(uuid)
|
||||||
|
|
||||||
|
form = forms.watchForm(formdata=request.form if request.method == 'POST' else None,
|
||||||
|
data=default,
|
||||||
|
)
|
||||||
|
# @todo subclass form so validation works
|
||||||
|
#if not form.validate():
|
||||||
|
# for widget, l in form.errors.items():
|
||||||
|
# flash(','.join(l), 'error')
|
||||||
|
# return redirect(url_for('tags.form_tag_edit_submit', uuid=uuid))
|
||||||
|
|
||||||
|
datastore.data['settings']['application']['tags'][uuid].update(form.data)
|
||||||
|
datastore.needs_write_urgent = True
|
||||||
|
flash("Updated")
|
||||||
|
|
||||||
|
return redirect(url_for('tags.tags_overview_page'))
|
||||||
|
|
||||||
|
|
||||||
|
@tags_blueprint.route("/delete/<string:uuid>", methods=['GET'])
|
||||||
|
def form_tag_delete(uuid):
|
||||||
|
return redirect(url_for('tags.tags_overview_page'))
|
||||||
|
return tags_blueprint
|
@ -0,0 +1,22 @@
|
|||||||
|
from wtforms import (
|
||||||
|
BooleanField,
|
||||||
|
Form,
|
||||||
|
IntegerField,
|
||||||
|
RadioField,
|
||||||
|
SelectField,
|
||||||
|
StringField,
|
||||||
|
SubmitField,
|
||||||
|
TextAreaField,
|
||||||
|
validators,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class SingleTag(Form):
|
||||||
|
|
||||||
|
name = StringField('Tag name', [validators.InputRequired()], render_kw={"placeholder": "Name"})
|
||||||
|
save_button = SubmitField('Save', render_kw={"class": "pure-button pure-button-primary"})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,131 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
{% block content %}
|
||||||
|
{% from '_helpers.jinja' import render_field, render_checkbox_field, render_button %}
|
||||||
|
{% from '_common_fields.jinja' import render_common_settings_form %}
|
||||||
|
<script src="{{url_for('static_content', group='js', filename='tabs.js')}}" defer></script>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
/*{% if emailprefix %}*/
|
||||||
|
/*const email_notification_prefix=JSON.parse('{{ emailprefix|tojson }}');*/
|
||||||
|
/*{% endif %}*/
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script src="{{url_for('static_content', group='js', filename='watch-settings.js')}}" defer></script>
|
||||||
|
<!--<script src="{{url_for('static_content', group='js', filename='limit.js')}}" defer></script>-->
|
||||||
|
<script src="{{url_for('static_content', group='js', filename='notifications.js')}}" defer></script>
|
||||||
|
|
||||||
|
<div class="edit-form monospaced-textarea">
|
||||||
|
|
||||||
|
<div class="tabs collapsable">
|
||||||
|
<ul>
|
||||||
|
<li class="tab" id=""><a href="#general">General</a></li>
|
||||||
|
<li class="tab"><a href="#filters-and-triggers">Filters & Triggers</a></li>
|
||||||
|
<li class="tab"><a href="#notifications">Notifications</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box-wrap inner">
|
||||||
|
<form class="pure-form pure-form-stacked"
|
||||||
|
action="{{ url_for('tags.form_tag_edit', uuid=data.uuid) }}" method="POST">
|
||||||
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||||
|
|
||||||
|
<div class="tab-pane-inner" id="general">
|
||||||
|
<fieldset>
|
||||||
|
<div class="pure-control-group">
|
||||||
|
{{ render_field(form.title, placeholder="https://...", required=true, class="m-d") }}
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tab-pane-inner" id="filters-and-triggers">
|
||||||
|
<div class="pure-control-group">
|
||||||
|
{% set field = render_field(form.include_filters,
|
||||||
|
rows=5,
|
||||||
|
placeholder="#example
|
||||||
|
xpath://body/div/span[contains(@class, 'example-class')]",
|
||||||
|
class="m-d")
|
||||||
|
%}
|
||||||
|
{{ field }}
|
||||||
|
{% if '/text()' in field %}
|
||||||
|
<span class="pure-form-message-inline"><strong>Note!: //text() function does not work where the <element> contains <![CDATA[]]></strong></span><br>
|
||||||
|
{% endif %}
|
||||||
|
<span class="pure-form-message-inline">One rule per line, <i>any</i> rules that matches will be used.<br>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>CSS - Limit text to this CSS rule, only text matching this CSS rule is included.</li>
|
||||||
|
<li>JSON - Limit text to this JSON rule, using either <a href="https://pypi.org/project/jsonpath-ng/" target="new">JSONPath</a> or <a href="https://stedolan.github.io/jq/" target="new">jq</a> (if installed).
|
||||||
|
<ul>
|
||||||
|
<li>JSONPath: Prefix with <code>json:</code>, use <code>json:$</code> to force re-formatting if required, <a href="https://jsonpath.com/" target="new">test your JSONPath here</a>.</li>
|
||||||
|
{% if jq_support %}
|
||||||
|
<li>jq: Prefix with <code>jq:</code> and <a href="https://jqplay.org/" target="new">test your jq here</a>. Using <a href="https://stedolan.github.io/jq/" target="new">jq</a> allows for complex filtering and processing of JSON data with built-in functions, regex, filtering, and more. See examples and documentation <a href="https://stedolan.github.io/jq/manual/" target="new">here</a>.</li>
|
||||||
|
{% else %}
|
||||||
|
<li>jq support not installed</li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>XPath - Limit text to this XPath rule, simply start with a forward-slash,
|
||||||
|
<ul>
|
||||||
|
<li>Example: <code>//*[contains(@class, 'sametext')]</code> or <code>xpath://*[contains(@class, 'sametext')]</code>, <a
|
||||||
|
href="http://xpather.com/" target="new">test your XPath here</a></li>
|
||||||
|
<li>Example: Get all titles from an RSS feed <code>//title/text()</code></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
Please be sure that you thoroughly understand how to write CSS, JSONPath, XPath{% if jq_support %}, or jq selector{%endif%} rules before filing an issue on GitHub! <a
|
||||||
|
href="https://github.com/dgtlmoon/changedetection.io/wiki/CSS-Selector-help">here for more CSS selector help</a>.<br>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<fieldset class="pure-control-group">
|
||||||
|
{{ render_field(form.subtractive_selectors, rows=5, placeholder="header
|
||||||
|
footer
|
||||||
|
nav
|
||||||
|
.stockticker") }}
|
||||||
|
<span class="pure-form-message-inline">
|
||||||
|
<ul>
|
||||||
|
<li> Remove HTML element(s) by CSS selector before text conversion. </li>
|
||||||
|
<li> Add multiple elements or CSS selectors per line to ignore multiple parts of the HTML. </li>
|
||||||
|
</ul>
|
||||||
|
</span>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tab-pane-inner" id="notifications">
|
||||||
|
<fieldset>
|
||||||
|
<div class="pure-control-group inline-radio">
|
||||||
|
{{ render_checkbox_field(form.notification_muted) }}
|
||||||
|
</div>
|
||||||
|
{% if is_html_webdriver %}
|
||||||
|
<div class="pure-control-group inline-radio">
|
||||||
|
{{ render_checkbox_field(form.notification_screenshot) }}
|
||||||
|
<span class="pure-form-message-inline">
|
||||||
|
<strong>Use with caution!</strong> This will easily fill up your email storage quota or flood other storages.
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
<div class="field-group" id="notification-field-group">
|
||||||
|
{% if has_default_notification_urls %}
|
||||||
|
<div class="inline-warning">
|
||||||
|
<img class="inline-warning-icon" src="{{url_for('static_content', group='images', filename='notice.svg')}}" alt="Look out!" title="Lookout!" >
|
||||||
|
There are <a href="{{ url_for('settings_page')}}#notifications">system-wide notification URLs enabled</a>, this form will override notification settings for this watch only ‐ an empty Notification URL list here will still send notifications.
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
<a href="#notifications" id="notification-setting-reset-to-default" class="pure-button button-xsmall" style="right: 20px; top: 20px; position: absolute; background-color: #5f42dd; border-radius: 4px; font-size: 70%; color: #fff">Use system defaults</a>
|
||||||
|
|
||||||
|
{{ render_common_settings_form(form, emailprefix, settings_application) }}
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="actions">
|
||||||
|
<div class="pure-control-group">
|
||||||
|
{{ render_button(form.save_button) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
@ -0,0 +1,60 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
{% block content %}
|
||||||
|
{% from '_helpers.jinja' import render_simple_field, render_field %}
|
||||||
|
<script src="{{url_for('static_content', group='js', filename='jquery-3.6.0.min.js')}}"></script>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
<form class="pure-form" action="{{ url_for('tags.form_tag_add') }}" method="POST" id="new-watch-form">
|
||||||
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" >
|
||||||
|
<fieldset>
|
||||||
|
<legend>Add a new organisational tag</legend>
|
||||||
|
<div id="watch-add-wrapper-zone">
|
||||||
|
<div>
|
||||||
|
{{ render_simple_field(form.name, placeholder="watch label / tag") }}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{{ render_simple_field(form.save_button, title="Save" ) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div style="color: #fff;">Groups allows you to manage filters and notifications for multiple watches under a single organisational tag.</div>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
<!-- @todo maybe some overview matrix, 'tick' with which has notification, filter rules etc -->
|
||||||
|
<div id="watch-table-wrapper">
|
||||||
|
|
||||||
|
<table class="pure-table pure-table-striped watch-table group-overview-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th>Tag / Label name</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<!--
|
||||||
|
@Todo - connect Last checked, Last Changed, Number of Watches etc
|
||||||
|
--->
|
||||||
|
{% if not available_tags|length %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="3">No website organisational tags/groups configured</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
{% for uuid, tag in available_tags.items() %}
|
||||||
|
<tr id="{{ uuid }}" class="{{ loop.cycle('pure-table-odd', 'pure-table-even') }}">
|
||||||
|
<td class="watch-controls">
|
||||||
|
<a class="link-mute state-{{'on' if tag.notification_muted else 'off'}}" href="{{url_for('tags.mute', uuid=tag.uuid)}}"><img src="{{url_for('static_content', group='images', filename='bell-off.svg')}}" alt="Mute notifications" title="Mute notifications" class="icon icon-mute" ></a>
|
||||||
|
</td>
|
||||||
|
<td class="title-col inline">{{tag.title}}</td>
|
||||||
|
<td>
|
||||||
|
<a class="pure-button pure-button-primary" href="{{ url_for('tags.form_tag_edit', uuid=uuid) }}">Edit</a>
|
||||||
|
<a class="pure-button pure-button-primary" href="{{ url_for('tags.delete', uuid=uuid) }}" title="Deletes and removes tag">Delete</a>
|
||||||
|
<a class="pure-button pure-button-primary" href="{{ url_for('tags.unlink', uuid=uuid) }}" title="Keep the tag but unlink any watches">Unlink</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -0,0 +1,19 @@
|
|||||||
|
from .Watch import base_config
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
class model(dict):
|
||||||
|
|
||||||
|
def __init__(self, *arg, **kw):
|
||||||
|
|
||||||
|
self.update(base_config)
|
||||||
|
|
||||||
|
self['uuid'] = str(uuid.uuid4())
|
||||||
|
|
||||||
|
if kw.get('default'):
|
||||||
|
self.update(kw['default'])
|
||||||
|
del kw['default']
|
||||||
|
|
||||||
|
|
||||||
|
# Goes at the end so we update the default object with the initialiser
|
||||||
|
super(model, self).__init__(*arg, **kw)
|
||||||
|
|
@ -0,0 +1,262 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import time
|
||||||
|
from flask import url_for
|
||||||
|
from .util import live_server_setup, wait_for_all_checks, extract_rss_token_from_UI, get_UUID_for_tag_name
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def test_setup(client, live_server):
|
||||||
|
live_server_setup(live_server)
|
||||||
|
|
||||||
|
def set_original_response():
|
||||||
|
test_return_data = """<html>
|
||||||
|
<body>
|
||||||
|
Some initial text<br>
|
||||||
|
<p id="only-this">Should be only this</p>
|
||||||
|
<br>
|
||||||
|
<p id="not-this">And never this</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
|
||||||
|
with open("test-datastore/endpoint-content.txt", "w") as f:
|
||||||
|
f.write(test_return_data)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def set_modified_response():
|
||||||
|
test_return_data = """<html>
|
||||||
|
<body>
|
||||||
|
Some initial text<br>
|
||||||
|
<p id="only-this">Should be REALLY only this</p>
|
||||||
|
<br>
|
||||||
|
<p id="not-this">And never this</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
|
||||||
|
with open("test-datastore/endpoint-content.txt", "w") as f:
|
||||||
|
f.write(test_return_data)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def test_setup_group_tag(client, live_server):
|
||||||
|
#live_server_setup(live_server)
|
||||||
|
set_original_response()
|
||||||
|
|
||||||
|
# Add a tag with some config, import a tag and it should roughly work
|
||||||
|
res = client.post(
|
||||||
|
url_for("tags.form_tag_add"),
|
||||||
|
data={"name": "test-tag"},
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
|
assert b"Tag added" in res.data
|
||||||
|
assert b"test-tag" in res.data
|
||||||
|
|
||||||
|
res = client.post(
|
||||||
|
url_for("tags.form_tag_edit_submit", uuid="first"),
|
||||||
|
data={"name": "test-tag",
|
||||||
|
"include_filters": '#only-this',
|
||||||
|
"subtractive_selectors": '#not-this'},
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
|
assert b"Updated" in res.data
|
||||||
|
tag_uuid = get_UUID_for_tag_name(client, name="test-tag")
|
||||||
|
res = client.get(
|
||||||
|
url_for("tags.form_tag_edit", uuid="first")
|
||||||
|
)
|
||||||
|
assert b"#only-this" in res.data
|
||||||
|
assert b"#not-this" in res.data
|
||||||
|
|
||||||
|
# Tag should be setup and ready, now add a watch
|
||||||
|
|
||||||
|
test_url = url_for('test_endpoint', _external=True)
|
||||||
|
res = client.post(
|
||||||
|
url_for("import_page"),
|
||||||
|
data={"urls": test_url + "?first-imported=1 test-tag, extra-import-tag"},
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
|
assert b"1 Imported" in res.data
|
||||||
|
|
||||||
|
res = client.get(url_for("index"))
|
||||||
|
assert b'import-tag' in res.data
|
||||||
|
assert b'extra-import-tag' in res.data
|
||||||
|
|
||||||
|
res = client.get(
|
||||||
|
url_for("tags.tags_overview_page"),
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
|
assert b'import-tag' in res.data
|
||||||
|
assert b'extra-import-tag' in res.data
|
||||||
|
|
||||||
|
wait_for_all_checks(client)
|
||||||
|
|
||||||
|
res = client.get(url_for("index"))
|
||||||
|
assert b'Warning, no filters were found' not in res.data
|
||||||
|
|
||||||
|
res = client.get(
|
||||||
|
url_for("preview_page", uuid="first"),
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
|
assert b'Should be only this' in res.data
|
||||||
|
assert b'And never this' not in res.data
|
||||||
|
|
||||||
|
|
||||||
|
# RSS Group tag filter
|
||||||
|
# An extra one that should be excluded
|
||||||
|
res = client.post(
|
||||||
|
url_for("import_page"),
|
||||||
|
data={"urls": test_url + "?should-be-excluded=1 some-tag"},
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
|
assert b"1 Imported" in res.data
|
||||||
|
wait_for_all_checks(client)
|
||||||
|
set_modified_response()
|
||||||
|
res = client.get(url_for("form_watch_checknow"), follow_redirects=True)
|
||||||
|
wait_for_all_checks(client)
|
||||||
|
rss_token = extract_rss_token_from_UI(client)
|
||||||
|
res = client.get(
|
||||||
|
url_for("rss", token=rss_token, tag="extra-import-tag", _external=True),
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
|
assert b"should-be-excluded" not in res.data
|
||||||
|
assert res.status_code == 200
|
||||||
|
assert b"first-imported=1" in res.data
|
||||||
|
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
||||||
|
assert b'Deleted' in res.data
|
||||||
|
|
||||||
|
def test_tag_import_singular(client, live_server):
|
||||||
|
#live_server_setup(live_server)
|
||||||
|
|
||||||
|
test_url = url_for('test_endpoint', _external=True)
|
||||||
|
res = client.post(
|
||||||
|
url_for("import_page"),
|
||||||
|
data={"urls": test_url + " test-tag, test-tag\r\n"+ test_url + "?x=1 test-tag, test-tag\r\n"},
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
|
assert b"2 Imported" in res.data
|
||||||
|
|
||||||
|
res = client.get(
|
||||||
|
url_for("tags.tags_overview_page"),
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
|
# Should be only 1 tag because they both had the same
|
||||||
|
assert res.data.count(b'test-tag') == 1
|
||||||
|
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
||||||
|
assert b'Deleted' in res.data
|
||||||
|
|
||||||
|
def test_tag_add_in_ui(client, live_server):
|
||||||
|
#live_server_setup(live_server)
|
||||||
|
#
|
||||||
|
res = client.post(
|
||||||
|
url_for("tags.form_tag_add"),
|
||||||
|
data={"name": "new-test-tag"},
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
|
assert b"Tag added" in res.data
|
||||||
|
assert b"new-test-tag" in res.data
|
||||||
|
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
||||||
|
assert b'Deleted' in res.data
|
||||||
|
|
||||||
|
def test_group_tag_notification(client, live_server):
|
||||||
|
#live_server_setup(live_server)
|
||||||
|
set_original_response()
|
||||||
|
|
||||||
|
test_url = url_for('test_endpoint', _external=True)
|
||||||
|
res = client.post(
|
||||||
|
url_for("form_quick_watch_add"),
|
||||||
|
data={"url": test_url, "tags": 'test-tag, other-tag'},
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
|
|
||||||
|
assert b"Watch added" in res.data
|
||||||
|
|
||||||
|
notification_url = url_for('test_notification_endpoint', _external=True).replace('http', 'json')
|
||||||
|
notification_form_data = {"notification_urls": notification_url,
|
||||||
|
"notification_title": "New GROUP TAG ChangeDetection.io Notification - {{watch_url}}",
|
||||||
|
"notification_body": "BASE URL: {{base_url}}\n"
|
||||||
|
"Watch URL: {{watch_url}}\n"
|
||||||
|
"Watch UUID: {{watch_uuid}}\n"
|
||||||
|
"Watch title: {{watch_title}}\n"
|
||||||
|
"Watch tag: {{watch_tag}}\n"
|
||||||
|
"Preview: {{preview_url}}\n"
|
||||||
|
"Diff URL: {{diff_url}}\n"
|
||||||
|
"Snapshot: {{current_snapshot}}\n"
|
||||||
|
"Diff: {{diff}}\n"
|
||||||
|
"Diff Added: {{diff_added}}\n"
|
||||||
|
"Diff Removed: {{diff_removed}}\n"
|
||||||
|
"Diff Full: {{diff_full}}\n"
|
||||||
|
":-)",
|
||||||
|
"notification_screenshot": True,
|
||||||
|
"notification_format": "Text",
|
||||||
|
"title": "test-tag"}
|
||||||
|
|
||||||
|
res = client.post(
|
||||||
|
url_for("tags.form_tag_edit_submit", uuid=get_UUID_for_tag_name(client, name="test-tag")),
|
||||||
|
data=notification_form_data,
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
|
assert b"Updated" in res.data
|
||||||
|
|
||||||
|
wait_for_all_checks(client)
|
||||||
|
|
||||||
|
set_modified_response()
|
||||||
|
client.get(url_for("form_watch_checknow"), follow_redirects=True)
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
|
assert os.path.isfile("test-datastore/notification.txt")
|
||||||
|
|
||||||
|
# Verify what was sent as a notification, this file should exist
|
||||||
|
with open("test-datastore/notification.txt", "r") as f:
|
||||||
|
notification_submission = f.read()
|
||||||
|
os.unlink("test-datastore/notification.txt")
|
||||||
|
|
||||||
|
# Did we see the URL that had a change, in the notification?
|
||||||
|
# Diff was correctly executed
|
||||||
|
assert test_url in notification_submission
|
||||||
|
assert ':-)' in notification_submission
|
||||||
|
assert "Diff Full: Some initial text" in notification_submission
|
||||||
|
assert "New GROUP TAG ChangeDetection.io" in notification_submission
|
||||||
|
assert "test-tag" in notification_submission
|
||||||
|
assert "other-tag" in notification_submission
|
||||||
|
|
||||||
|
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
||||||
|
assert b'Deleted' in res.data
|
||||||
|
|
||||||
|
#@todo Test that multiple notifications fired
|
||||||
|
#@todo Test that each of multiple notifications with different settings
|
||||||
|
|
||||||
|
|
||||||
|
def test_limit_tag_ui(client, live_server):
|
||||||
|
#live_server_setup(live_server)
|
||||||
|
|
||||||
|
test_url = url_for('test_endpoint', _external=True)
|
||||||
|
urls=[]
|
||||||
|
|
||||||
|
for i in range(20):
|
||||||
|
urls.append(test_url+"?x="+str(i)+" test-tag")
|
||||||
|
|
||||||
|
for i in range(20):
|
||||||
|
urls.append(test_url+"?non-grouped="+str(i))
|
||||||
|
|
||||||
|
res = client.post(
|
||||||
|
url_for("import_page"),
|
||||||
|
data={"urls": "\r\n".join(urls)},
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
|
|
||||||
|
assert b"40 Imported" in res.data
|
||||||
|
|
||||||
|
res = client.get(url_for("index"))
|
||||||
|
assert b'test-tag' in res.data
|
||||||
|
|
||||||
|
# All should be here
|
||||||
|
assert res.data.count(b'processor-text_json_diff') == 40
|
||||||
|
|
||||||
|
tag_uuid = get_UUID_for_tag_name(client, name="test-tag")
|
||||||
|
|
||||||
|
res = client.get(url_for("index", tag=tag_uuid))
|
||||||
|
|
||||||
|
# Just a subset should be here
|
||||||
|
assert b'test-tag' in res.data
|
||||||
|
assert res.data.count(b'processor-text_json_diff') == 20
|
||||||
|
assert b"object at" not in res.data
|
Loading…
Reference in new issue