liyujie
2025-08-28 b3810562527858a3b3d98ffa6e9c9c5b0f4a9a8e
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
#!/usr/bin/python
# Copyright 2016 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
 
import urlparse
import unittest
 
import common
from autotest_lib.server import afe_urls
 
 
class AfeUrlsTestCase(unittest.TestCase):
 
    """Tests for AfeUrls."""
 
    def assertURLEqual(self, a, b):
        """Assert two URLs are equal.
 
        @param a First URL to compare
        @param b First URL to compare
 
        """
        urlsplit = urlparse.urlsplit
        self.assertEqual(urlsplit(a), urlsplit(b))
 
    def test__geturl(self):
        """Test _geturl() happy path."""
        urls = afe_urls.AfeUrls('http://localhost/afe/')
        got = urls._geturl({'foo': 'bar', 'spam': 'eggs'})
        self.assertURLEqual(got, 'http://localhost/afe/#foo=bar&spam=eggs')
 
    def test_get_host_url(self):
        """Test get_host_url() happy path."""
        urls = afe_urls.AfeUrls('http://localhost/afe/')
        got = urls.get_host_url(42)
        self.assertURLEqual(
            got,
            'http://localhost/afe/#tab_id=view_host&object_id=42')
 
    def test_root_url(self):
        """Test happy path for root_url attribute."""
        urls = afe_urls.AfeUrls('http://localhost/afe/')
        self.assertEqual(urls.root_url, 'http://localhost/afe/')
 
    def test_equal(self):
        """Test happy path for equality."""
        urls1 = afe_urls.AfeUrls('http://localhost/afe/')
        urls2 = afe_urls.AfeUrls('http://localhost/afe/')
        self.assertEqual(urls1, urls2)
 
    def test_from_hostname(self):
        """Test from_hostname() happy path."""
        urls = afe_urls.AfeUrls.from_hostname('sharanohiar')
        self.assertEqual(urls.root_url, 'http://sharanohiar/afe/')
 
 
if __name__ == '__main__':
    unittest.main()