Repository: somm15/PyViCare

Issue:
When will pyViCare be updated in PyLib
typo in "/usr/local/lib/python3.9/dist-packages/PyViCare/PyViCareService.py" line 48

Error raised:
dump() missing 1 required positional argument: 'fp' in python json

Change
 post_data = data if isinstance(data, str) else json.dump(data)
to
 post_data = data if isinstance(data, str) else json.dumps(data)


Discussion:

Patch:
diff --git a/PyViCare/PyViCareService.py b/PyViCare/PyViCareService.py
index bd4d1fe..f280fde 100644
--- a/PyViCare/PyViCareService.py
+++ b/PyViCare/PyViCareService.py
@@ -45,5 +45,5 @@ class ViCareService:
         url = buildSetPropertyUrl(
             self.accessor, property_name, action)
 
-        post_data = data if isinstance(data, str) else json.dump(data)
+        post_data = data if isinstance(data, str) else json.dumps(data)
         return self.oauth_manager.post(url, post_data)
\ No newline at end of file


Test patch:
diff --git a/tests/test_PyViCareService.py b/tests/test_PyViCareService.py
new file mode 100644
index 0000000..0fc4abe
--- /dev/null
+++ b/tests/test_PyViCareService.py
@@ -0,0 +1,27 @@
+import unittest
+from PyViCare.PyViCareService import ViCareDeviceAccessor, ViCareService
+from PyViCare.PyViCareOAuthManager import AbstractViCareOAuthManager
+from unittest.mock import Mock
+
+
+
+
+class GenericDevice(unittest.TestCase):
+
+    def setUp(self):
+        self.oauth_mock = Mock()
+        accessor = ViCareDeviceAccessor("[id]", "[serial]", "[device]")
+        self.service = ViCareService(self.oauth_mock, accessor)
+        
+    def test_getProperty(self):
+        self.service.getProperty("someprop")
+        self.oauth_mock.get.assert_called_once_with('/equipment/installations/[id]/gateways/[serial]/devices/[device]/features/someprop')
+
+    def test_setProperty_object(self):
+        self.service.setProperty("someprop", "doaction", {'name': 'abc'})
+        self.oauth_mock.post.assert_called_once_with('/equipment/installations/[id]/gateways/[serial]/devices/[device]/features/someprop/doaction', '{"name": "abc"}')
+
+    def test_setProperty_string(self):
+        self.service.setProperty("someprop", "doaction", '{}')
+        self.oauth_mock.post.assert_called_once_with('/equipment/installations/[id]/gateways/[serial]/devices/[device]/features/someprop/doaction', '{}')
+       
\ No newline at end of file