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'