summaryrefslogtreecommitdiffstats
path: root/funcweb/funcweb/tests/test_widget_automation.py
blob: d02de93ab3cc5556acc6123fc097d061e1fed36b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import unittest
import turbogears
from turbogears import testutil

from funcweb.widget_automation import WidgetListFactory,RemoteFormAutomation,RemoteFormFactory
from funcweb.widget_validation import WidgetSchemaFactory

class TestWidgetListFactory(unittest.TestCase):
    
    def setUp(self):
        self.widget_factory = WidgetListFactory(self.get_test_default_args(),minion="myminion",module="mymodule",method="my_method")
    
        
    def tearDown(self):
        pass

    def test_default_args(self):
        compare_with = self.get_test_default_args()
        widget_list=self.widget_factory.get_widgetlist()
        
        #print "The widget list is like :",widget_list

        for argument_name,argument_options in compare_with.iteritems():
            assert widget_list.has_key(argument_name) == True
            #print "The argument name is :",argument_name
            #because some of them dont have it like boolean
            if argument_options.has_key('default'):
                assert argument_options['default'] == getattr(widget_list[argument_name],'default')

            if argument_options.has_key("description"):
                assert argument_options['description']==getattr(widget_list[argument_name],'help_text')

            if argument_options.has_key("options"):
                assert argument_options['options'] == getattr(widget_list[argument_name],"options")
            
        #that should be enough
    def test_get_widgetlist_object(self):
        compare_with = self.get_test_default_args()
        widget_list_object = self.widget_factory.get_widgetlist_object()
        
        #print widget_list_object
    
        all_fields = [getattr(field,"name") for field in widget_list_object]
        #print all_fields
        for argument_name in compare_with.keys():
            print argument_name
            assert argument_name in all_fields
            #print getattr(widget_list_object,argument_name)


    def test_remote_form(self):
        schema_factory = WidgetSchemaFactory(self.get_test_default_args())
        schema_validator=schema_factory.get_ready_schema()
        widget_list_object = self.widget_factory.get_widgetlist_object()
        remote_form = RemoteFormAutomation(widget_list_object,schema_validator)
        #print remote_form

    def test_remote_form_factory(self):
        from turbogears.view import load_engines
        load_engines()
       
        # WidgetsList object
        widget_list_object = self.widget_factory.get_widgetlist_object()
        #print widget_list_object
        remote_form = RemoteFormFactory(widget_list_object).get_remote_form()

        #it is a key,value dict
        widget_list=self.widget_factory.get_widgetlist()
        #print widget_list
        all_fields = [getattr(field,"name") for field in remote_form.fields]
        #print all_fields
        #will check if the remote form object hass all the names in it
        for argument_name in widget_list.items():
            argument_name in all_fields 


        #print remote_form.render()
    
    def get_test_default_args(self):
        return {
                'string_default':{
                    'type':'string',
                    'default':'default string',
                    'optional':False,
                    'description':'default description'
                    },
                'int_default':{
                    'type':'int',
                    'default':'default int',
                    'optional':False,
                    'description':'default description'
                   },
                #no sense to have default
                'boolean_default':{
                    'type':'boolean',
                    'optional':False,
                    'description':'default description'
                   },
                'float_default':{
                    'type':'float',
                    'default':'default float',
                    'optional':False,
                    'description':'default description'
                   
                    },
                'hash_default':{
                    'type':'hash',
                    'default':'default hash',
                    'optional':False,
                    'description':'default description'
                   
                    },
                'list_default':{
                    'type':'list',
                    'default':'default list',
                    'optional':False,
                    'description':'default description'
                   
                    },
                #will be converted to dropdown
                'special_string':{
                    'type':'string',
                    'default':'myfirst',
                    'options':['myfirst','mysecond','mythird'],
                    'optional':False,
                    'description':'default dropdown list'
                    }
                
                }