File: test_connection.py

package info (click to toggle)
python-webdavclient 3.14.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 644 kB
  • sloc: python: 2,241; xml: 535; makefile: 5; sh: 3
file content (111 lines) | stat: -rw-r--r-- 4,350 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import unittest

from webdav3.client import get_options
from webdav3.connection import WebDAVSettings, OptionNotValid, ConnectionSettings


class ConnectionTestCase(unittest.TestCase):
    def test_connection_settings_valid(self):
        options = {
            'webdav_hostname': 'http://localhost:8585',
            'webdav_login': 'alice',
            'webdav_password': 'secret1234'
        }
        webdav_options = get_options(option_type=WebDAVSettings, from_options=options)
        settings = WebDAVSettings(webdav_options)
        self.assertTrue(settings.is_valid())
        self.assertTrue(settings.valid())

    def test_connection_settings_timeout_set(self):
        options = {
            'webdav_hostname': 'http://localhost:8585',
            'webdav_login': 'alice',
            'webdav_password': 'secret1234',
            'timeout': 60
        }
        webdav_options = get_options(option_type=WebDAVSettings, from_options=options)
        settings = WebDAVSettings(webdav_options)
        self.assertEqual(60, settings.timeout)

    def test_connection_settings_timeout_default(self):
        options = {
            'webdav_hostname': 'http://localhost:8585',
            'webdav_login': 'alice',
            'webdav_password': 'secret1234'
        }
        webdav_options = get_options(option_type=WebDAVSettings, from_options=options)
        settings = WebDAVSettings(webdav_options)
        self.assertEqual(30, settings.timeout)

    def test_connection_settings_no_hostname(self):
        options = {
            'webdav_login': 'alice',
            'webdav_password': 'secret1234'
        }
        webdav_options = get_options(option_type=WebDAVSettings, from_options=options)
        settings = WebDAVSettings(webdav_options)
        self.assertRaises(OptionNotValid, settings.is_valid)
        self.assertFalse(settings.valid())

    def test_connection_settings_no_login(self):
        options = {
            'webdav_hostname': 'http://localhost:8585',
            'webdav_password': 'secret1234'
        }
        webdav_options = get_options(option_type=WebDAVSettings, from_options=options)
        settings = WebDAVSettings(webdav_options)
        self.assertRaises(OptionNotValid, settings.is_valid)
        self.assertFalse(settings.valid())

    def test_connection_settings_anonymous_login(self):
        options = {
            'webdav_hostname': 'http://localhost:8585'
        }
        webdav_options = get_options(option_type=WebDAVSettings, from_options=options)
        settings = WebDAVSettings(webdav_options)
        self.assertTrue(settings.valid())

    def test_connection_settings_wrong_cert_path(self):
        options = {
            'webdav_hostname': 'http://localhost:8585',
            'webdav_login': 'alice',
            'cert_path': './wrong.file',
            'webdav_password': 'secret1234'
        }
        webdav_options = get_options(option_type=WebDAVSettings, from_options=options)
        settings = WebDAVSettings(webdav_options)
        self.assertRaises(OptionNotValid, settings.is_valid)
        self.assertFalse(settings.valid())

    def test_connection_settings_wrong_key_path(self):
        options = {
            'webdav_hostname': 'http://localhost:8585',
            'webdav_login': 'alice',
            'key_path': './wrong.file',
            'webdav_password': 'secret1234'
        }
        webdav_options = get_options(option_type=WebDAVSettings, from_options=options)
        settings = WebDAVSettings(webdav_options)
        self.assertRaises(OptionNotValid, settings.is_valid)
        self.assertFalse(settings.valid())

    def test_connection_settings_with_key_path_an_no_cert_path(self):
        options = {
            'webdav_hostname': 'http://localhost:8585',
            'webdav_login': 'alice',
            'key_path': './publish.sh',
            'webdav_password': 'secret1234'
        }
        webdav_options = get_options(option_type=WebDAVSettings, from_options=options)
        settings = WebDAVSettings(webdav_options)
        self.assertRaises(OptionNotValid, settings.is_valid)
        self.assertFalse(settings.valid())

    def test_connection_settings_does_nothing(self):
        settings = ConnectionSettings()
        settings.is_valid()
        self.assertTrue(settings.valid())


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