5 from sfa.util.faults import *
6 from sfa.util.xrn import Xrn
7 from sfa.util.plxrn import PlXrn
11 class TestXrn(unittest.TestCase):
13 def __hrn(self,h,t,exp_urn):
14 if verbose: print 'testing (',h,t,') expecting',exp_urn
17 if verbose: print xrn.dump_string()
19 (h1,t1) = Xrn(urn).get_hrn_type()
20 if h1!=h or t1!=t or urn!=exp_urn:
21 print "hrn->urn->hrn : MISMATCH with in=(%s,%s) -- out=(%s,%s) -- urn=%s"%(h,t,h1,t1,urn)
22 self.assertEqual(h1,h)
23 self.assertEqual(t1,t)
24 self.assertEqual(urn,exp_urn)
26 # could not figure how to use assertFails on object construction..
27 # with self.assertRaises(SfaAPIError):
28 # Xrn(h,type=t).get_urn()
30 Xrn(h,type=t).get_urn()
31 failure="Unexpectedly created Xrn object"
35 failure="Xrn creation raised unexpected exception %r"%e
37 print "hrn->urn->hrn - %s with HRN=%s TYPE=%s"%(failure,h,t)
38 self.assertFalse(True)
41 def test_hrn001 (self):
42 self.__hrn("ple.inria.baris",'user',
43 "urn:publicid:IDN+ple:inria+user+baris")
44 def test_hnr002 (self):
45 self.__hrn("emulab\.net.myslice.jktest",'slice',
46 "urn:publicid:IDN+emulab.net:myslice+slice+jktest")
47 def test_hrn003(self):
48 self.__hrn("emulab\\.net.jktest", "slice",
49 "urn:publicid:IDN+emulab.net+slice+jktest")
50 def test_hrn004(self):
51 self.__hrn("plc.princeton.tmack",'user',
52 "urn:publicid:IDN+plc:princeton+user+tmack")
53 def test_hrn005(self):
54 self.__hrn("fake-pi1@onelab.eu",'user',
55 "urn:publicid:IDN+fake-pi1@onelab+user+eu")
56 def test_hrn006(self):
57 self.__hrn("plc.princeton.tmack", 'user',
58 "urn:publicid:IDN+plc:princeton+user+tmack" )
59 # def test_hrn007(self):
60 # # not providing a type is currently not supporte
61 # self.__hrn("fake-pi1@onelab.eu",None,
63 def test_hrn008(self):
64 self.__hrn("plc.princeton.planetlab1", 'node',
65 "urn:publicid:IDN+plc:princeton+node+planetlab1" )
66 def test_hrn009(self):
67 self.__hrn("plc.princeton", 'authority',
68 "urn:publicid:IDN+plc:princeton+authority+sa" )
69 def test_hrn010(self):
70 self.__hrn("plc.vini.site", 'authority',
71 "urn:publicid:IDN+plc:vini:site+authority+sa" )
73 # this one is a bit off limits but it's used in some places
74 # like .e.g when running sfi.py resources
76 void=Xrn(xrn='',type=None)
77 expected='urn:publicid:IDN++'
78 self.assertEqual(void.get_hrn(),'')
79 self.assertEqual(void.get_type(),None)
80 self.assertEqual(void.get_urn(),expected)
81 loop=Xrn(xrn=expected)
82 self.assertEqual(loop.get_hrn(),'')
83 # xxx - this is not quite right as the first object has type None
84 self.assertEqual(loop.get_type(),'')
87 def test_host001 (self):
88 xrn=PlXrn (auth="ple.inria",hostname="onelab09.pl.sophia.inria.fr")
89 self.assertEqual (xrn.get_hrn_type(), ("ple.inria.onelab09",'node'))
90 def test_host002 (self):
91 xrn=PlXrn (auth="ple\\.inria",hostname="onelab09.pl.sophia.inria.fr")
92 self.assertEqual (xrn.get_hrn_type(), ("ple\\.inria.onelab09",'node'))
94 def test_slice001 (self):
95 xrn=PlXrn (auth="ple",slicename="inria_omftest")
96 self.assertEqual (xrn.get_hrn_type(), ("ple.inria.omftest",'slice'))
98 def test_person001 (self):
99 xrn=PlXrn (auth="ple.inria",email="first.last@some.domain.com")
100 self.assertEqual (xrn.get_hrn_type(), ("ple.inria.first_last",'person'))
101 def test_person002 (self):
102 xrn=PlXrn (auth="ple.inria",email="first+last@some.domain.com")
103 self.assertEqual (xrn.get_hrn_type(), ("ple.inria.first_last",'person'))
107 def test_login_base_001 (self):
108 xrn=PlXrn(xrn='ple.inria.omftest',type='slice')
109 self.assertEqual(xrn.pl_login_base(),'inria')
111 def test_slicename_001 (self):
112 xrn=PlXrn(xrn='ple.inria.omftest',type='slice')
113 self.assertEqual(xrn.pl_slicename(),'inria_omftest')
115 def test_authname_001 (self):
116 xrn=PlXrn(xrn='ple.inria.omftest',type='slice')
117 self.assertEqual(xrn.pl_authname(),'inria')