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