Send diff in notifications (#296)
This commit is contained in:
@@ -22,7 +22,6 @@ def cleanup(datastore_path):
|
||||
for file in files:
|
||||
try:
|
||||
os.unlink("{}/{}".format(datastore_path, file))
|
||||
x = 1
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
@@ -55,6 +55,8 @@ def test_check_notification(client, live_server):
|
||||
"Preview: {preview_url}\n"
|
||||
"Diff URL: {diff_url}\n"
|
||||
"Snapshot: {current_snapshot}\n"
|
||||
"Diff: {diff}\n"
|
||||
"Diff Full: {diff_full}\n"
|
||||
":-)",
|
||||
"notification_format": "Text",
|
||||
"url": test_url,
|
||||
@@ -114,6 +116,11 @@ def test_check_notification(client, live_server):
|
||||
|
||||
assert test_url in notification_submission
|
||||
|
||||
# Diff was correctly executed
|
||||
assert "Diff Full: (changed) Which is across multiple lines" in notification_submission
|
||||
assert "(-> into) which has this one new line" in notification_submission
|
||||
|
||||
|
||||
if env_base_url:
|
||||
# Re #65 - did we see our BASE_URl ?
|
||||
logging.debug (">>> BASE_URL checking in notification: %s", env_base_url)
|
||||
|
||||
1
changedetectionio/tests/unit/__init__.py
Normal file
1
changedetectionio/tests/unit/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Unit tests for the app."""
|
||||
5
changedetectionio/tests/unit/test-content/README.md
Normal file
5
changedetectionio/tests/unit/test-content/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# What is this?
|
||||
This is test content for the python diff engine, we use the JS interface for the front end, because you can explore
|
||||
differences in words etc, but we use (at the moment) the python difflib engine.
|
||||
|
||||
This content `before.txt` and `after.txt` is for unit testing
|
||||
6
changedetectionio/tests/unit/test-content/after.txt
Normal file
6
changedetectionio/tests/unit/test-content/after.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
After twenty years, as cursed as I may be
|
||||
for having learned computerese,
|
||||
I continue to examine bits, bytes and words
|
||||
xok
|
||||
and insure that I'm one of those computer nerds.
|
||||
and something new
|
||||
5
changedetectionio/tests/unit/test-content/before.txt
Normal file
5
changedetectionio/tests/unit/test-content/before.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
After twenty years, as cursed as I may be
|
||||
for having learned computerese,
|
||||
I continue to examine bits, bytes and words
|
||||
ok
|
||||
and insure that I'm one of those computer nerds.
|
||||
25
changedetectionio/tests/unit/test_notification_diff.py
Executable file
25
changedetectionio/tests/unit/test_notification_diff.py
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
# run from dir above changedetectionio/ dir
|
||||
# python3 -m unittest changedetectionio.tests.unit.test_notification_diff
|
||||
|
||||
import unittest
|
||||
import os
|
||||
|
||||
from changedetectionio import diff
|
||||
|
||||
# mostly
|
||||
class TestDiffBuilder(unittest.TestCase):
|
||||
|
||||
def test_expected_diff_output(self):
|
||||
base_dir=os.path.dirname(__file__)
|
||||
output = diff.render_diff(base_dir+"/test-content/before.txt", base_dir+"/test-content/after.txt")
|
||||
output = output.split("\n")
|
||||
self.assertIn("(changed) ok", output)
|
||||
self.assertIn("(-> into) xok", output)
|
||||
self.assertIn("(added) and something new", output)
|
||||
|
||||
# @todo test blocks of changed, blocks of added, blocks of removed
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user