1#!/usr/bin/python3 2# 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 six.moves.urllib.parse 7import unittest 8 9import common 10 11from autotest_lib.server import afe_urls 12 13 14class AfeUrlsTestCase(unittest.TestCase): 15 16 """Tests for AfeUrls.""" 17 18 def assertURLEqual(self, a, b): 19 """Assert two URLs are equal. 20 21 @param a First URL to compare 22 @param b First URL to compare 23 24 """ 25 urlsplit = six.moves.urllib.parse.urlsplit 26 self.assertEqual(urlsplit(a), urlsplit(b)) 27 28 def test__geturl(self): 29 """Test _geturl() happy path.""" 30 urls = afe_urls.AfeUrls('http://localhost/afe/') 31 got = urls._geturl({'foo': 'bar', 'spam': 'eggs'}) 32 self.assertURLEqual(got, 'http://localhost/afe/#foo=bar&spam=eggs') 33 34 def test_get_host_url(self): 35 """Test get_host_url() happy path.""" 36 urls = afe_urls.AfeUrls('http://localhost/afe/') 37 got = urls.get_host_url(42) 38 self.assertURLEqual( 39 got, 40 'http://localhost/afe/#tab_id=view_host&object_id=42') 41 42 def test_root_url(self): 43 """Test happy path for root_url attribute.""" 44 urls = afe_urls.AfeUrls('http://localhost/afe/') 45 self.assertEqual(urls.root_url, 'http://localhost/afe/') 46 47 def test_equal(self): 48 """Test happy path for equality.""" 49 urls1 = afe_urls.AfeUrls('http://localhost/afe/') 50 urls2 = afe_urls.AfeUrls('http://localhost/afe/') 51 self.assertEqual(urls1, urls2) 52 53 def test_from_hostname(self): 54 """Test from_hostname() happy path.""" 55 urls = afe_urls.AfeUrls.from_hostname('sharanohiar') 56 self.assertEqual(urls.root_url, 'http://sharanohiar/afe/') 57 58 59if __name__ == '__main__': 60 unittest.main() 61