Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/uamtests.py
blob: b2a590110fb48f56054fd6ad129d49bfbfc2eaff (plain)
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
60
61
# Copyright (C) 2009, Tutorius.org
# Copyright (C) 2009, Michael Janelle-Montcalm <michael.jmontcalm@gmail.com>
# Copyright (C) 2009, Vincent Vinet <vince.vinet@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import unittest

from sugar.tutorius.uam import parse_uri, SchemeError

PARSE_SUITE={
#URI                        SCHEME HOST PARAMS PATH QUERY FRAGMENT
"tap://act.tut.org/":       ["tap", "act.tut.org","", "/", "", ""],
"tap.gtk://a.t.o/0/1":      ["tap.gtk","a.t.o","","/0/1","","",""],
"tap.gobject://a.t.o/Timer?timeout=5":["tap.gobject","a.t.o","","/Timer","timeout=5",""],
}

class ParseUriTests(unittest.TestCase):
    """Tests the UAM parsers"""
    def test_parse_uri(self):
        """Test parsing results"""
        for uri, test in PARSE_SUITE.items():
            res = parse_uri(uri)

            assert res.scheme == test[0], "%s : Expected scheme %s, got %s" % (uri, test[0], res.scheme)
            assert res.netloc == test[1], "%s : Expected netloc %s, got %s" % (uri, test[1], res.netloc)
            assert res.params == test[2], "%s : Expected params %s, got %s" % (uri, test[2], res.params)
            assert res.path == test[3], "%s : Expected path %s, got %s" % (uri, test[3], res.path)
            assert res.query == test[4], "%s : Expected query %s, got %s" % (uri, test[4], res.query)
            assert res.fragment == test[5], "%s : Expected fragment %s, got %s" % (uri, test[5], res.fragment)

    def test_errors(self):
        """Test exceptions"""
        try:
            parse_uri("http://something.org/path")
            assert False, "Parsing http should fail"
        except SchemeError:
            pass

        try:
            parse_uri("tap.notarealsubscheme://something.org/path")
            assert False, "Invalid Subscheme should fail"
        except SchemeError:
            pass

        
if __name__ == "__main__":
    unittest.main()