blob: 11727f49607b6d0801229a4f19987696d437c665 [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
65testdata = yaml.load(open('test_rsync_url.yaml'))
66
67index = 1
68for remote, tests in testdata.items():
69
70 for test, expected in tests.items():
71
72 print index, test, expected
73
74 def test_function(self, test=test,
75 remote=remote, expected_result=expected):
76 getattr(self, test)(remote, expected_result)
77
78 test_function.__name__ = \
Max Rasskazov64f77bf2015-06-02 15:22:48 +030079 'test_rsync_url_{}_{}_{}'.format(index, tests['classed'], test)
Max Rasskazova8db7a92015-05-30 02:23:43 +030080 test_function.__doc__ = test_function.__name__
81 setattr(TestRsyncUrl, test_function.__name__, test_function)
82 del test_function
83
84 index += 1
85
86
87if __name__ == '__main__':
88 unittest.main()