Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Workshop.activity/tests/MTTests.py
blob: 0687d9259fc6ea37261320a804da895c434b75c3 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import mocks
from WorkshopController import WorkshopController
from WorkshopModel import Tutorial
from Workshop import WorkshopView
from unittest import TestCase
import gtk


class WsControllerTest(TestCase):
    def setUp(self):
        self.model = mocks.WorkshopModelMock()
        self.view = mocks.ViewMock()
        self.controller = WorkshopController(self.view,self.model)
        self.tut = Tutorial({'name':'tut', 'description':'descrip','rating':4, 'author':'Max Power'})
    
    def test_tutorial_query(self):
        widget = 'This is the widget'
        keyword = 'Test Keyword'
        function_name = 'tutorial_query'        
        self.controller.tutorial_query(widget,keyword)
        
        assert function_name in self.model.call_list, 'tutorial_query was not called'
        assert self.model.call_list[function_name] == keyword, "the keyword %s wasn't correct" % (keyword)
        
    def test_sort_selection_changed(self):
        function_name = 'change_sorting'
        widget = gtk.combo_box_new_text()
        widget.insert_text(0,"Name")
        widget.insert_text(1,"Rating")
        widget.set_active(0)
        
        self.controller.sort_selection_changed(widget,None)
        
        assert function_name in self.view.call_list, 'change_sorting was not called'
        assert self.view.call_list[function_name] == "Name", 'the parameter was not correct'
        
        self.view.clear_call_list()
        
        widget.set_active(1)
        self.controller.sort_selection_changed(widget,None)
        
        assert function_name in self.view.call_list, 'change_sorting was not called'
        assert self.view.call_list[function_name] == "Rating", 'the parameter was not correct'
        
    def test_launch_tutorial(self):
        function_name = 'launch_tutorial'
        self.controller.launch_tutorial(None,self.tut)
        
        assert function_name in self.model.call_list, 'launch_tutorial was not called'
        assert self.model.call_list[function_name] == self.tut, 'the parameter was not correct'
        
    def test_show_details(self):
        function_name = 'display_detail'
        self.controller.show_details(None,self.tut)
        
        assert function_name in self.view.call_list, 'display_detil was not called'
        assert self.view.call_list[function_name] == self.tut , 'The parameter was not correct'
        
    def test_back_pressed(self):
        function_name = 'display_main_view'
        self.controller.back_pressed(None,None)
        
        assert function_name in self.view.call_list, 'display_main_view was not called'
        assert self.view.call_list[function_name] == None, 'The parameter was not correct'
        
    def test_rate_tutorial(self):
        rating = 3
        function_name = 'rate_tutorial'
        self.controller.rate_tutorial(self.tut,rating)
        
        assert function_name in self.model.call_list, 'rate_tutorial was not called'
        assert self.model.call_list[function_name][0] == self.tut, 'The first param was not correct'
        assert self.model.call_list[function_name][1] == rating, 'The second param was not correct'
        
    def test_edit_tutorial(self,):
        function_name = 'edit_tutorial'
        
        self.controller.edit_tutorial(None,self.tut)
        
        assert function_name in self.model.call_list, 'edit_tutorial was not called'
        assert self.model.call_list[function_name] == self.tut, 'The parameter was not correct'
        

    def test_info_tutorial(self):
        function_name = 'display_info_dialog'
        
        self.controller.info_tutorial(None,self.tut)
        
        assert function_name in self.view.call_list, 'display_info_dialog was not called'
        assert self.view.call_list[function_name] == self.tut, 'The parameter was not correct'
        


    def test_save_tutorial_info(self):
        function_name = 'save_metadata'
        
        self.controller.save_tutorial_info(self.tut)
        
        assert function_name in self.model.call_list, 'save_metadata was not called'
        assert self.model.call_list[function_name] == self.tut, 'The parameter was not correct'
        

    def test_delete_tutorial(self):
        function_name = 'delete_tutorial'
        
        self.controller.delete_tutorial(None,self.tut)
        
        assert function_name in self.model.call_list, 'delete_tutorial was not called'
        assert self.model.call_list[function_name] == self.tut, 'The parameter was not correct'
        
    def test_publish_tutorial(self):
        function_name = 'publish_tutorial'
        
        self.controller.publish_tutorial(None,self.tut)
        
        assert function_name in self.model.call_list, 'publish_tutorial was not called'
        assert self.model.call_list[function_name] == self.tut, 'The parameter was not correct'

    def test_unpublish_tutorial(self):
        function_name = 'unpublish_tutorial'
        
        self.controller.unpublish_tutorial(None,self.tut)
        
        assert function_name in self.model.call_list, 'unpublish_tutorial was not called'
        assert self.model.call_list[function_name] == self.tut, 'The parameter was not correct'


class WsViewTest(TestCase):
    def setUp(self):
        self.workshop = WorkshopView()
    
    def test_init(self):
        assert self.workshop.mainView is not None, "main View not initialized"
        
    def test_set_tutorial_list(self):
        tut1 = Tutorial({'name':'btut1','description':'tutorial 1'})
        tut2 = Tutorial({'name':'atut2','description':'tutorial 2'})
        tut_list = [tut1,tut2]
        
        assert self.workshop.mainView.list_container.get_children()
        
        self.workshop.set_tutorial_list(tut_list)
        
        assert self.workshop.mainView.tutorial_list == tut_list, 'The tutorial list not was processed correctly'
        
        #tutorials are sorted by name so tut2 comes first
        assert self.workshop.mainView.tutorial_list[0] == tut2
        assert self.workshop.mainView.tutorial_list[1] == tut1
    
    def test_change_sorting(self):
        tut1 = Tutorial({'name':'btut1','description':'tutorial 1','rating':5})
        tut2 = Tutorial({'name':'atut2','description':'tutorial 2','rating':1})
        tut_list = [tut1,tut2]
        
        self.workshop.set_tutorial_list(tut_list)
        
        assert self.workshop.mainView.tutorial_list[0] == tut2
        assert self.workshop.mainView.tutorial_list[1] == tut1
        
        self.workshop.change_sorting('rating')
        
        ##This test fails for the moment because rating are in reverse order
        assert self.workshop.mainView.tutorial_list[0] == tut1, 'Not sorted by rating correctly'
        assert self.workshop.mainView.tutorial_list[1] == tut2, 'Not sorted by rating correctly'