1 # -*- coding: utf-8 -*-
4 Unit tests for processor functions.
8 from urlparse
import urlparse
9 from txclib
.processors
import hostname_tld_migration
, hostname_ssl_migration
12 class TestHostname(unittest
.TestCase
):
13 """Test for hostname processors."""
15 def test_tld_migration_needed(self
):
17 Test the tld migration of Transifex, when needed.
20 'http://transifex.net', 'http://www.transifex.net',
21 'https://fedora.transifex.net',
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))
30 def test_tld_migration_needed(self
):
32 Test that unneeded tld migrations are detected correctly.
35 'https://www.transifex.com', 'http://fedora.transifex.com',
36 'http://www.example.net/path/'
39 hostname
= hostname_tld_migration(h
)
40 self
.assertEqual(hostname
, h
)
42 def test_no_scheme_specified(self
):
44 Test that, if no scheme has been specified, the https one will be used.
46 hostname
= '//transifex.net'
47 hostname
= hostname_ssl_migration(hostname
)
48 self
.assertTrue(hostname
.startswith('https://'))
50 def test_http_replacement(self
):
51 """Test the replacement of http with https."""
53 'http://transifex.com', 'http://transifex.net/http/',
54 'http://www.transifex.com/path/'
57 hostname
= hostname_ssl_migration(h
)
58 self
.assertEqual(hostname
[:8], 'https://')
59 self
.assertEqual(hostname
[7:], h
[6:])
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
)