Skip to content

Commit

Permalink
add test resources to gitignore
Browse files Browse the repository at this point in the history
add test class to implement test cases
add test case to cover filestation login
add test case to cover surveillance station login
  • Loading branch information
Fabio Testa committed Mar 14, 2024
1 parent af66dd6 commit c0c28db
Show file tree
Hide file tree
Showing 4 changed files with 67 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
}
53 changes: 53 additions & 0 deletions tests/test_syno_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import datetime
import json
from unittest import TestCase

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/')

0 comments on commit c0c28db

Please sign in to comment.