summaryrefslogtreecommitdiff
path: root/pyinflux/test/test_client.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyinflux/test/test_client.py')
-rw-r--r--pyinflux/test/test_client.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/pyinflux/test/test_client.py b/pyinflux/test/test_client.py
new file mode 100644
index 0000000..2c9108f
--- /dev/null
+++ b/pyinflux/test/test_client.py
@@ -0,0 +1,36 @@
+import json
+import codecs
+from unittest import TestCase
+from pyinflux.client import Line, QueryResultOption
+from io import BytesIO
+
+
+class TestLine(TestCase):
+ def test_line(self):
+ self.assertEqual(str(Line('test', [('a', 'b')], [('value', 'asd\\\\')])),
+ r'test,a=b value="asd\\\\"')
+
+ self.assertEqual(repr(Line('test', [('a', 'b')], [('value', 'asd\\\\')])),
+ r"<Line key=test tags=[('a', 'b')] fields=[('value', 'asd\\\\')] timestamp=None>")
+
+
+class TestQueryResultOption(TestCase):
+ def test_json(self):
+ testobject = {'123': 456, '789': '456'}
+ buf = BytesIO()
+ json.dump(testobject, codecs.getwriter('utf-8')(buf))
+
+ buf.seek(0)
+ qro = QueryResultOption(lambda: buf)
+ self.assertEqual(testobject, qro.as_json())
+ self.assertEqual(testobject, qro.as_json())
+
+ def test_text(self):
+ testobject = {'123': 456, '789': '456'}
+ buf = BytesIO()
+ json.dump(testobject, codecs.getwriter('utf-8')(buf))
+
+ buf.seek(0)
+ qro = QueryResultOption(lambda: buf)
+ self.assertEqual(json.dumps(testobject), qro.as_text())
+ self.assertEqual(json.dumps(testobject), qro.as_text())