blob: 19c73a877c8bc73893e567107e2638382772378c [file] [log] [blame]
Max Rasskazova8db7a92015-05-30 02:23:43 +03001#-*- coding: utf-8 -*-
2
Max Rasskazova8db7a92015-05-30 02:23:43 +03003import unittest
4import yaml
5
Max Rasskazov64f77bf2015-06-02 15:22:48 +03006import rsync_url
Max Rasskazovb1b09a62015-06-03 15:21:35 +03007import utils
Max Rasskazov64f77bf2015-06-02 15:22:48 +03008
9
Max Rasskazovb1b09a62015-06-03 15:21:35 +030010logger = utils.logger.getChild('TestRsyncUrl')
Max Rasskazov64f77bf2015-06-02 15:22:48 +030011
Max Rasskazova8db7a92015-05-30 02:23:43 +030012
13class TestRsyncUrl(unittest.TestCase):
14
Max Rasskazov64f77bf2015-06-02 15:22:48 +030015 def log_locals(self, url):
16 if url.match:
17 logger.info('RE: "{}"'.format(url.match.pattern))
18 logger.info('user "{}", host "{}", port "{}", module "{}", '
19 'path "{}"'.format(url.user, url.host, url.port,
20 url.module, url.path))
21
Max Rasskazova8db7a92015-05-30 02:23:43 +030022 def exact_match_num(self, remote, expected_result):
Max Rasskazov64f77bf2015-06-02 15:22:48 +030023 logger.info('"{}" - {}'.format(remote, expected_result))
Max Rasskazova8db7a92015-05-30 02:23:43 +030024 url = rsync_url.RsyncUrl(remote)
Max Rasskazov64f77bf2015-06-02 15:22:48 +030025 self.log_locals(url)
Max Rasskazova8db7a92015-05-30 02:23:43 +030026 matching_regexps = url._get_all_matching_regexps()
27 self.assertEqual(len(matching_regexps), expected_result)
28
29 def classed(self, remote, expected_result):
Max Rasskazov64f77bf2015-06-02 15:22:48 +030030 logger.info('"{}" - {}'.format(remote, expected_result))
Max Rasskazova8db7a92015-05-30 02:23:43 +030031 url = rsync_url.RsyncUrl(remote)
Max Rasskazov64f77bf2015-06-02 15:22:48 +030032 self.log_locals(url)
Max Rasskazova8db7a92015-05-30 02:23:43 +030033 self.assertEqual(url.url_type, expected_result)
34
35 def parsed(self, remote, expected_result):
Max Rasskazov64f77bf2015-06-02 15:22:48 +030036 logger.info('"{}" - {}'.format(remote, expected_result))
Max Rasskazova8db7a92015-05-30 02:23:43 +030037 url = rsync_url.RsyncUrl(remote)
Max Rasskazov64f77bf2015-06-02 15:22:48 +030038 self.log_locals(url)
Max Rasskazova8db7a92015-05-30 02:23:43 +030039 self.assertEqual(
Max Rasskazov64f77bf2015-06-02 15:22:48 +030040 [url.user, url.host, url.path],
Max Rasskazova8db7a92015-05-30 02:23:43 +030041 expected_result
42 )
43
Max Rasskazov64f77bf2015-06-02 15:22:48 +030044 def parsed_rsync(self, remote, expected_result):
45 logger.info('"{}" - {}'.format(remote, expected_result))
46 url = rsync_url.RsyncUrl(remote)
47 self.log_locals(url)
48 self.assertEqual(
49 [url.user, url.host, url.port, url.module, url.path],
50 expected_result
51 )
52
53 def valid(self, remote, expected_result):
54 logger.info('"{}" - {}'.format(remote, expected_result))
55 url = rsync_url.RsyncUrl(remote)
56 self.log_locals(url)
57 self.assertEqual(url.is_valid, expected_result)
58
59 def url(self, remote, expected_result):
60 logger.info('"{}" - {}'.format(remote, expected_result))
61 url = rsync_url.RsyncUrl(remote)
62 self.log_locals(url)
63 self.assertEqual(url.url, expected_result)
Max Rasskazova8db7a92015-05-30 02:23:43 +030064
Max Rasskazov2f93dd22015-06-04 14:20:44 +030065 def url_in(self, remote, expected_result):
66 logger.info('"{}" - {}'.format(remote, expected_result))
67 url = rsync_url.RsyncUrl(remote)
68 self.log_locals(url)
69 for par, er in expected_result.items():
70 self.assertEqual(url.url_in(par), er)
71
72 def url_is(self, remote, expected_result):
73 logger.info('"{}" - {}'.format(remote, expected_result))
74 url = rsync_url.RsyncUrl(remote)
75 self.log_locals(url)
76 for par, er in expected_result.items():
77 self.assertEqual(url.url_is(par), er)
78
Max Rasskazova8db7a92015-05-30 02:23:43 +030079testdata = yaml.load(open('test_rsync_url.yaml'))
80
81index = 1
82for remote, tests in testdata.items():
83
84 for test, expected in tests.items():
85
86 print index, test, expected
87
88 def test_function(self, test=test,
89 remote=remote, expected_result=expected):
90 getattr(self, test)(remote, expected_result)
91
92 test_function.__name__ = \
Max Rasskazov64f77bf2015-06-02 15:22:48 +030093 'test_rsync_url_{}_{}_{}'.format(index, tests['classed'], test)
Max Rasskazova8db7a92015-05-30 02:23:43 +030094 test_function.__doc__ = test_function.__name__
95 setattr(TestRsyncUrl, test_function.__name__, test_function)
96 del test_function
97
98 index += 1
99
100
101if __name__ == '__main__':
102 unittest.main()