source: OpenRLabs-Git/web2py/applications/rlabs/unitTest/disabledTest/test_global_context.py

main
Last change on this file was 648257b, checked in by David Fuertes <dfuertes@…>, 4 years ago

Creado menu inserción de pre-reservas laboratorios

  • Property mode set to 100644
File size: 3.3 KB
Line 
1#!/usr/bin/python3
2from fileinput import filename
3
4
5try:
6    import unittest2 as unittest #for Python <= 2.6
7except:
8    import unittest   
9
10import os
11import sys
12sys.path.append(os.path.dirname(sys.argv[0]) + '/') #Path to my unitTest directory
13from gluon import *
14
15from baseTest import BaseTest
16
17APP =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())
22filename = "applications/" + APP + "/controllers/default.py"
23
24exec(compile(open(filename, "rb").read(), filename, 'exec'), globals())
25
26#import global_context
27#import adoDB_reserves
28from gluon.storage import Storage
29
30class 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   
115suite = unittest.TestSuite()
116suite.addTest(unittest.makeSuite(GlobalContext))
117unittest.TextTestRunner(verbosity=2).run(suite)
Note: See TracBrowser for help on using the repository browser.