[tx-robot] updated from transifex
[pub/Android/ownCloud.git] / third_party / transifex-client / tests / test_processors.py
1 # -*- coding: utf-8 -*-
2
3 """
4 Unit tests for processor functions.
5 """
6
7 import unittest
8 from urlparse import urlparse
9 from txclib.processors import hostname_tld_migration, hostname_ssl_migration
10
11
12 class TestHostname(unittest.TestCase):
13 """Test for hostname processors."""
14
15 def test_tld_migration_needed(self):
16 """
17 Test the tld migration of Transifex, when needed.
18 """
19 hostnames = [
20 'http://transifex.net', 'http://www.transifex.net',
21 'https://fedora.transifex.net',
22 ]
23 for h in hostnames:
24 hostname = hostname_tld_migration(h)
25 self.assertTrue(hostname.endswith('com'))
26 orig_hostname = 'http://www.transifex.net/path/'
27 hostname = hostname_tld_migration(orig_hostname)
28 self.assertEqual(hostname, orig_hostname.replace('net', 'com', 1))
29
30 def test_tld_migration_needed(self):
31 """
32 Test that unneeded tld migrations are detected correctly.
33 """
34 hostnames = [
35 'https://www.transifex.com', 'http://fedora.transifex.com',
36 'http://www.example.net/path/'
37 ]
38 for h in hostnames:
39 hostname = hostname_tld_migration(h)
40 self.assertEqual(hostname, h)
41
42 def test_no_scheme_specified(self):
43 """
44 Test that, if no scheme has been specified, the https one will be used.
45 """
46 hostname = '//transifex.net'
47 hostname = hostname_ssl_migration(hostname)
48 self.assertTrue(hostname.startswith('https://'))
49
50 def test_http_replacement(self):
51 """Test the replacement of http with https."""
52 hostnames = [
53 'http://transifex.com', 'http://transifex.net/http/',
54 'http://www.transifex.com/path/'
55 ]
56 for h in hostnames:
57 hostname = hostname_ssl_migration(h)
58 self.assertEqual(hostname[:8], 'https://')
59 self.assertEqual(hostname[7:], h[6:])
60
61 def test_no_http_replacement_needed(self):
62 """Test that http will not be replaces with https, when not needed."""
63 for h in ['http://example.com', 'http://example.com/http/']:
64 hostname = hostname_ssl_migration(h)
65 self.assertEqual(hostname, hostname)