fix loading records from a dictionary when pointer is not defined
[sfa.git] / tests / testGid.py
1 import unittest
2 import xmlrpclib
3 from cert import *
4 from gid import *
5
6 class TestGid(unittest.TestCase):
7    def setUp(self):
8       pass
9
10    def testSetGetHrn(self):
11       gid = GID(subject="test")
12       hrn = "test.hrn"
13
14       gid.set_hrn(hrn)
15       self.assertEqual(gid.get_hrn(), hrn)
16
17    def testSetGetUuid(self):
18       gid = GID(subject="test")
19       u = create_uuid()
20
21       gid.set_uuid(u)
22       self.assertEqual(gid.get_uuid(), u)
23
24    def testEncodeDecode(self):
25       gid = GID(subject="test")
26       u = str(uuid.uuid4().int)
27       hrn = "test.hrn"
28
29       gid.set_uuid(u)
30       gid.set_hrn(hrn)
31
32       gid.encode()
33       gid.decode()
34
35       self.assertEqual(gid.get_hrn(), hrn)
36       self.assertEqual(gid.get_uuid(), u)
37
38    def testSaveAndLoadString(self):
39       gid = GID(subject="test")
40
41       u = str(uuid.uuid4().int)
42       hrn = "test.hrn"
43
44       gid.set_uuid(u)
45       gid.set_hrn(hrn)
46
47       # create an issuer and sign the certificate
48       issuerKey =  Keypair(create = True)
49       issuerSubject = "testissuer"
50       gid.set_issuer(issuerKey, issuerSubject)
51       gid.sign()
52
53       certstr = gid.save_to_string()
54
55       #print certstr
56
57       gid2 = GID(string = certstr)
58
59       self.assertEqual(gid.get_hrn(), hrn)
60       self.assertEqual(gid.get_uuid(), u)
61
62 if __name__ == "__main__":
63     unittest.main()