aboutsummaryrefslogtreecommitdiffstats
path: root/test_strings.py
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-11-19 09:24:17 +0100
committerMatěj Cepl <mcepl@redhat.com>2011-11-19 19:52:42 +0100
commit536c112a1c7b808729cb6e7f1103e1a541f10ce7 (patch)
tree76240c2a1cf4aea9de807f6717e6824a90fd036b /test_strings.py
parent5cc8f8468fcba6e0cc6855d064c45be20968fbda (diff)
downloadjson_diff-536c112a1c7b808729cb6e7f1103e1a541f10ce7.tar.gz
Add tons of elementary tests.
Tests now should cover all basics of JSON format. Also added a method _run_test_strings for simple tests. Created a parent class OurTestCase containing the above helper methods. Moved static strings to special module.
Diffstat (limited to 'test_strings.py')
-rw-r--r--test_strings.py213
1 files changed, 213 insertions, 0 deletions
diff --git a/test_strings.py b/test_strings.py
new file mode 100644
index 0000000..c96db7a
--- /dev/null
+++ b/test_strings.py
@@ -0,0 +1,213 @@
+# -*- coding: utf-8 -*-
+from __future__ import division, absolute_import, unicode_literals
+
+NO_JSON_OLD = """
+THIS IS NOT A JSON STRING
+"""
+
+NO_JSON_NEW = """
+AND THIS NEITHER
+"""
+
+SIMPLE_OLD = """
+{
+ "a": 1,
+ "b": true,
+ "c": "Janošek"
+}
+"""
+
+SIMPLE_NEW = """
+{
+ "b": false,
+ "c": "Maruška",
+ "d": "přidáno"
+}
+"""
+
+SIMPLE_DIFF = """
+{
+ "_append": {
+ "d": "přidáno"
+ },
+ "_remove": {
+ "a": 1
+ },
+ "_update": {
+ "c": "Maruška",
+ "b": false
+ }
+}
+"""
+
+SIMPLE_DIFF_HTML="""
+<!DOCTYPE html>
+<html lang='en'>
+<meta charset="utf-8" />
+<title>json_diff result</title>
+<style>
+td {
+text-align: center;
+}
+.append_class {
+color: green;
+}
+.remove_class {
+color: red;
+}
+.update_class {
+color: navy;
+}
+</style>
+<body>
+<h1>json_diff result</h1>
+<table>
+<tr>
+<td class='remove_class'>a = 1</td>
+</tr><tr>
+<td class='update_class'>c = Maruška</td>
+</tr><tr>
+<td class='update_class'>b = False</td>
+</tr><tr>
+<td class='append_class'>d = přidáno</td>
+</tr>
+</table>
+</body>
+</html>
+"""
+
+SIMPLE_ARRAY_OLD = """
+{
+ "a": [ 1 ]
+}
+"""
+
+SIMPLE_ARRAY_NEW = """
+{
+ "a": [ 1, 2 ]
+}
+"""
+
+SIMPLE_ARRAY_DIFF = """
+{
+ "_update": {
+ "a": {
+ "_append": {
+ "1": 2
+ }
+ }
+ }
+}
+"""
+
+NESTED_OLD = """
+{
+ "a": 1,
+ "b": 2,
+ "ignore": {
+ "else": true
+ },
+ "child": {
+ "nome": "Janošek"
+ }
+}
+"""
+
+NESTED_NEW = """
+{
+ "a": 2,
+ "c": 3,
+ "child": {
+ "nome": "Maruška"
+ }
+}
+"""
+
+NESTED_DIFF = """
+{
+ "_append": {
+ "c": 3
+ },
+ "_remove": {
+ "b": 2,
+ "ignore": {
+ "else": true
+ }
+ },
+ "_update": {
+ "a": 2,
+ "child": {
+ "_update": {
+ "nome": "Maruška"
+ }
+ }
+ }
+}
+"""
+
+NESTED_DIFF_EXCL = """
+{
+ "_append": {
+ "c": 3
+ },
+ "_remove": {
+ "b": 2,
+ "ignore": {
+ "else": true
+ }
+ },
+ "_update": {
+ "a": 2
+ }
+}
+"""
+
+NESTED_DIFF_INCL = """
+{
+ "_update": {
+ "child": {
+ "_update": {
+ "nome": "Maruška"
+ }
+ }
+ }
+}
+"""
+
+ARRAY_OLD = """
+{
+ "a": 1,
+ "b": 2,
+ "children": [
+ "Pepíček", "Anička", "Maruška"
+ ]
+}
+"""
+
+ARRAY_NEW = """
+{
+ "a": 1,
+ "children": [
+ "Pepíček", "Tonička", "Maruška"
+ ],
+ "c": 3
+}
+"""
+
+ARRAY_DIFF = """
+{
+ "_remove": {
+ "b": 2
+ },
+ "_append": {
+ "c": 3
+ },
+ "_update": {
+ "children": [
+ "Pepíček",
+ "Tonička",
+ "Maruška"
+ ]
+ }
+}
+"""