Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/uamtests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/uamtests.py')
-rw-r--r--tests/uamtests.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/uamtests.py b/tests/uamtests.py
new file mode 100644
index 0000000..b2a5901
--- /dev/null
+++ b/tests/uamtests.py
@@ -0,0 +1,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()
+