blob: 3a84ce3ee7b0336ba477efa093b906919401a31d [file] [log] [blame]
Mike Frysingerd03e6b52019-08-03 12:49:01 -04001#!/usr/bin/python2
Allen Li6a612392016-08-18 12:09:32 -07002# Copyright 2016 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import urlparse
7import unittest
8
9import common
10from autotest_lib.server import afe_urls
11
12
13class AfeUrlsTestCase(unittest.TestCase):
14
15 """Tests for AfeUrls."""
16
17 def assertURLEqual(self, a, b):
18 """Assert two URLs are equal.
19
20 @param a First URL to compare
21 @param b First URL to compare
22
23 """
24 urlsplit = urlparse.urlsplit
25 self.assertEqual(urlsplit(a), urlsplit(b))
26
27 def test__geturl(self):
28 """Test _geturl() happy path."""
29 urls = afe_urls.AfeUrls('http://localhost/afe/')
30 got = urls._geturl({'foo': 'bar', 'spam': 'eggs'})
31 self.assertURLEqual(got, 'http://localhost/afe/#foo=bar&spam=eggs')
32
33 def test_get_host_url(self):
34 """Test get_host_url() happy path."""
35 urls = afe_urls.AfeUrls('http://localhost/afe/')
36 got = urls.get_host_url(42)
37 self.assertURLEqual(
38 got,
39 'http://localhost/afe/#tab_id=view_host&object_id=42')
40
41 def test_root_url(self):
42 """Test happy path for root_url attribute."""
43 urls = afe_urls.AfeUrls('http://localhost/afe/')
44 self.assertEqual(urls.root_url, 'http://localhost/afe/')
45
46 def test_equal(self):
47 """Test happy path for equality."""
48 urls1 = afe_urls.AfeUrls('http://localhost/afe/')
49 urls2 = afe_urls.AfeUrls('http://localhost/afe/')
50 self.assertEqual(urls1, urls2)
51
52 def test_from_hostname(self):
53 """Test from_hostname() happy path."""
54 urls = afe_urls.AfeUrls.from_hostname('sharanohiar')
55 self.assertEqual(urls.root_url, 'http://sharanohiar/afe/')
56
57
58if __name__ == '__main__':
59 unittest.main()