Skip to content

Commit

Permalink
Merge pull request #164 from fabtesta/tests-filestation-api-issue-159
Browse files Browse the repository at this point in the history
Tests filestation api issue 159
  • Loading branch information
N4S4 committed Mar 14, 2024
2 parents 4f3ad78 + 2dfc442 commit d6ee5c1
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,7 @@ FodyWeavers.xsd

# JetBrains Rider
.idea/
*.sln.iml
*.sln.iml

# Test resources
tests/resources/config-test.json
Empty file added tests/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions tests/resources/config-test-sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#### COPY THIS FILE AND NAME IT config-test.json AND REPLACE WITH YOUR VALUES
{
"synology_ip": "your_dsm_ip",
"synology_port": your_dsm_port_as_int,
"synology_user": "your_dsm_user",
"synology_password": "your_dsm_password",
"synology_secure": true_if_your_dsm_http_endpoint_is_https,
"dsm_version": your_dsm_version_as_int,
"otp_code": "your_dsm_otp_code"_or_null
}
57 changes: 57 additions & 0 deletions tests/test_syno_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import datetime
import json
from unittest import TestCase
import unittest
from synology_api.filestation import FileStation
from synology_api.surveillancestation import SurveillanceStation


def parse_config(config_path) -> dict[str, str]:
with open(config_path, 'r') as config_file:
config_data = json.load(config_file)
return config_data


class TestSynoApi(TestCase):
config: dict[str, str]

def setUp(self):
self.config = parse_config('./resources/config-test.json')

def test_syno_filestation_login(self):
fs = FileStation(ip_address=self.config["synology_ip"], port=self.config["synology_port"],
username=self.config["synology_user"],
password=self.config["synology_password"],
secure=bool(self.config["synology_secure"]), cert_verify=False,
dsm_version=int(self.config["dsm_version"]), debug=True,
otp_code=self.config["otp_code"])

self.assertIsNotNone(fs)
self.assertIsNotNone(fs.session)
self.assertIsNotNone(fs.session.sid)
self.assertIsNot(fs.session.sid, '')
shares_list = fs.get_list_share()
self.assertIsNotNone(shares_list)
self.assertEqual(shares_list.__len__(), 2)

def test_syno_surveillancestation_login(self):
ss = SurveillanceStation(ip_address=self.config["synology_ip"], port=self.config["synology_port"],
username=self.config["synology_user"],
password=self.config["synology_password"],
secure=bool(self.config["synology_secure"]), cert_verify=False,
dsm_version=int(self.config["dsm_version"]), debug=True,
otp_code=self.config["otp_code"])

self.assertIsNotNone(ss)
self.assertIsNotNone(ss.session)
self.assertIsNotNone(ss.session.sid)
self.assertIsNot(ss.session.sid, '')
ss_info = ss.surveillance_station_info()
self.assertIsNotNone(ss_info)
ss_info_data = ss_info['data']
self.assertIsNotNone(ss_info_data)
self.assertEqual(ss_info_data['path'], '/webman/3rdparty/SurveillanceStation/')


if __name__ == '__main__':
unittest.main()

0 comments on commit d6ee5c1

Please sign in to comment.