another step of moving stuff around where it belongs
[sfa.git] / tests / testXrn.py
1 #!/usr/bin/python
2 import sys
3 import unittest
4
5 from sfa.util.faults import *
6 from sfa.util.xrn import Xrn
7 from sfa.util.plxrn import PlXrn
8
9 verbose=False
10
11 class TestXrn(unittest.TestCase):
12
13     def __hrn(self,h,t,exp_urn):
14         if verbose: print 'testing (',h,t,') expecting',exp_urn
15         xrn=Xrn(h,type=t)
16         if verbose: print xrn.dump_string()
17         urn=xrn.get_urn()
18         (h1,t1) = Xrn(urn).get_hrn_type()
19         if h1!=h or t1!=t or urn!=exp_urn:
20             print "hrn->urn->hrn : MISMATCH with in=(%s,%s) -- out=(%s,%s) -- urn=%s"%(h,t,h1,t1,urn)
21         self.assertEqual(h1,h)
22         self.assertEqual(t1,t)
23         self.assertEqual(urn,exp_urn)
24
25     def test_hrn001 (self): 
26         self.__hrn("ple.inria.baris",'user',
27                    "urn:publicid:IDN+ple:inria+user+baris")
28     def test_hnr002 (self): 
29         self.__hrn("emulab\.net.myslice.jktest",'slice',
30                    "urn:publicid:IDN+emulab.net:myslice+slice+jktest")
31     def test_hrn003(self):
32         self.__hrn("emulab\\.net.jktest", "slice",
33                    "urn:publicid:IDN+emulab.net+slice+jktest")
34     def test_hrn004(self):
35         self.__hrn("plc.princeton.tmack",'user',
36                    "urn:publicid:IDN+plc:princeton+user+tmack")
37     def test_hrn005(self):
38         self.__hrn("fake-pi1@onelab.eu",'user',
39                    "urn:publicid:IDN+fake-pi1@onelab+user+eu")
40     def test_hrn006(self):
41         self.__hrn("plc.princeton.tmack", 'user',
42                    "urn:publicid:IDN+plc:princeton+user+tmack" )
43 # not specifying a type ... this gives weird result - xxx todo
44 #     def test_hrn007(self):
45 #         # not providing a type is currently not supporte
46 #         self.__hrn("fake-pi1@onelab.eu",None,
47 #                    None)
48     def test_hrn008(self):
49         self.__hrn("plc.princeton.planetlab1", 'node',
50                    "urn:publicid:IDN+plc:princeton+node+planetlab1" )
51     def test_hrn009(self):
52         self.__hrn("plc.princeton", 'authority',
53                    "urn:publicid:IDN+plc:princeton+authority+sa" )
54     def test_hrn010(self):
55         self.__hrn("plc.vini.site", 'authority',
56                    "urn:publicid:IDN+plc:vini:site+authority+sa" )
57
58     # this one is a bit off limits but it's used in some places
59     # like .e.g when running sfi.py resources
60     def test_void(self):
61         void=Xrn(xrn='',type=None)
62         expected='urn:publicid:IDN++'
63         self.assertEqual(void.get_hrn(),'')
64         self.assertEqual(void.get_type(),None)
65         self.assertEqual(void.get_urn(),expected)
66         loop=Xrn(xrn=expected)
67         self.assertEqual(loop.get_hrn(),'')
68         # xxx - this is not quite right as the first object has type None
69         self.assertEqual(loop.get_type(),'')        
70
71     def test_host001 (self):
72         xrn=PlXrn (auth="ple.inria",hostname="onelab09.pl.sophia.inria.fr")
73         self.assertEqual (xrn.get_hrn_type(), ("ple.inria.onelab09\\.pl\\.sophia\\.inria\\.fr",'node'))
74     def test_host002 (self):
75         xrn=PlXrn (auth="ple\\.inria",hostname="onelab09.pl.sophia.inria.fr")
76         self.assertEqual (xrn.get_hrn_type(), ("ple\\.inria.onelab09\\.pl\\.sophia\\.inria\\.fr",'node'))
77
78     def test_slice001  (self):
79         xrn=PlXrn (auth="ple",slicename="inria_omftest")
80         self.assertEqual (xrn.get_hrn_type(), ("ple.inria.omftest",'slice'))
81
82     def test_person001 (self):
83         xrn=PlXrn (auth="ple.inria",email="first.last@some.domain.com")
84         self.assertEqual (xrn.get_hrn_type(), ("ple.inria.first_last",'person'))
85     def test_person002 (self):
86         xrn=PlXrn (auth="ple.inria",email="first+last@some.domain.com")
87         self.assertEqual (xrn.get_hrn_type(), ("ple.inria.first_last",'person'))
88         
89
90
91     def test_login_base_001 (self):
92         xrn=PlXrn(xrn='ple.inria.omftest',type='slice')
93         self.assertEqual(xrn.pl_login_base(),'inria')
94
95     def test_slicename_001 (self):
96         xrn=PlXrn(xrn='ple.inria.omftest',type='slice')
97         self.assertEqual(xrn.pl_slicename(),'inria_omftest')
98
99     def test_authname_001 (self):
100         xrn=PlXrn(xrn='ple.inria.omftest',type='slice')
101         self.assertEqual(xrn.pl_authname(),'inria')
102
103