1 | #!/usr/bin/python3 |
---|
2 | from fileinput import filename |
---|
3 | |
---|
4 | |
---|
5 | try: |
---|
6 | import unittest2 as unittest #for Python <= 2.6 |
---|
7 | except: |
---|
8 | import unittest |
---|
9 | |
---|
10 | import os |
---|
11 | import sys |
---|
12 | sys.path.append(os.path.dirname(sys.argv[0]) + '/') #Path to my unitTest directory |
---|
13 | from gluon import * |
---|
14 | |
---|
15 | from baseTest import BaseTest |
---|
16 | |
---|
17 | APP =sys.argv[1] |
---|
18 | |
---|
19 | |
---|
20 | #This line executes your controller file, bringing all of the function declarations into the local namespace. |
---|
21 | #execfile("applications/" + APP + "/controllers/default.py", globals()) |
---|
22 | filename = "applications/" + APP + "/controllers/default.py" |
---|
23 | |
---|
24 | exec(compile(open(filename, "rb").read(), filename, 'exec'), globals()) |
---|
25 | |
---|
26 | #import global_context |
---|
27 | #import adoDB_reserves |
---|
28 | from gluon.storage import Storage |
---|
29 | |
---|
30 | class GlobalContext(BaseTest): |
---|
31 | |
---|
32 | def test_context(self): |
---|
33 | my_context = Storage({'a' :1, 'b' : 2}) |
---|
34 | |
---|
35 | my_dict = {'c' :3, 'd' : 4} |
---|
36 | for k,v in my_dict.items(): |
---|
37 | my_context[k] = v |
---|
38 | |
---|
39 | my_dict = {'e' :5, 'f' : 6} |
---|
40 | for k,v in my_dict.items(): |
---|
41 | my_context[k] = v |
---|
42 | |
---|
43 | print(my_context) |
---|
44 | print(my_context['b']) |
---|
45 | print(my_context['d']) |
---|
46 | print(my_context['f']) |
---|
47 | self.assertIsNot(len(my_context), 0) |
---|
48 | |
---|
49 | |
---|
50 | ''' |
---|
51 | def test_context(self): |
---|
52 | |
---|
53 | global_context.add_context(db = db, user_id = "pepe") |
---|
54 | |
---|
55 | context = global_context.get_context() |
---|
56 | print('context') |
---|
57 | print(context) |
---|
58 | |
---|
59 | if 'user_id' in context: |
---|
60 | user_id = context['user_id'] |
---|
61 | else: |
---|
62 | user_id = '' |
---|
63 | |
---|
64 | |
---|
65 | |
---|
66 | global_context.add_context(new_context = "new context") |
---|
67 | |
---|
68 | context = global_context.get_context() |
---|
69 | print('new context') |
---|
70 | print(context) |
---|
71 | |
---|
72 | kk = {} |
---|
73 | kk['kk'] = 'kk' |
---|
74 | kk['kk2'] = 'kk2' |
---|
75 | print(kk) |
---|
76 | global_context.add_context(**kk) |
---|
77 | |
---|
78 | print(global_context.get_context() ) |
---|
79 | global_context.add_context(new_context = "new context_repeated") |
---|
80 | |
---|
81 | context = global_context.get_context() |
---|
82 | print('new context') |
---|
83 | print(context) |
---|
84 | |
---|
85 | objs = global_context.get_context('user_id', 'new_context') |
---|
86 | print('objects') |
---|
87 | print(objs) |
---|
88 | |
---|
89 | print(global_context.get_context() ) |
---|
90 | |
---|
91 | if 'new_context' in context: |
---|
92 | new_context = context['new_context'] |
---|
93 | else: |
---|
94 | new_context = '' |
---|
95 | |
---|
96 | self.assertIsNot(new_context, '') |
---|
97 | self.assertIsNot(user_id, '') |
---|
98 | |
---|
99 | def test_insert_reserve(self): |
---|
100 | global_context.add_context(port = '3389', |
---|
101 | lab_id = '17', |
---|
102 | image_id = '16', |
---|
103 | ou_id = '4', |
---|
104 | protocol = 'rdp', |
---|
105 | user_id = 11, |
---|
106 | id = 210, |
---|
107 | name = 'eupti117', |
---|
108 | ip = '10.7.1.112', |
---|
109 | expiration_time = '08/04/2020 13:20:26') |
---|
110 | |
---|
111 | global_context.add_context(db = db) |
---|
112 | adoDB_reserves.insert(global_context) |
---|
113 | ''' |
---|
114 | |
---|
115 | suite = unittest.TestSuite() |
---|
116 | suite.addTest(unittest.makeSuite(GlobalContext)) |
---|
117 | unittest.TextTestRunner(verbosity=2).run(suite) |
---|