Attachment 'test_presenters.py'
Download 1 #----------------------------------------------------------------------------
2 # Name: test_presenters.py
3 # Purpose: Unittesting for the AlbumPresenter
4 #
5 # Author: Peter Damoc (peter at sigmacore.net)
6 #
7 # Created: January 2006
8 # Version: 0.2
9 # Licence: wxWindows license
10
11 import unittest
12 import mock_objects
13 import models
14 import presenters
15
16 class TestAlbumPresenter(unittest.TestCase):
17 '''
18 A sample test case to demonstrate the use of mock objects
19 '''
20
21 def setUp(self):
22 self.someAlbums = models.someAlbums
23 def getMVP(self):
24 view = mock_objects.MockAlbumWindow();
25 model = [models.Album(*data) for data in self.someAlbums]
26 interactor = mock_objects.MockAlbumInteractor()
27 presenter = presenters.AlbumPresenter(model, view, interactor)
28 return model, view, presenter
29
30 def testUpdateCausesComposerEnabledToBeRefreshed(self):
31 model, view, presenter = self.getMVP()
32 assert view.isClassical() is False
33 assert view.composerIsEnabled is False
34 view.setClassical(True)
35 presenter.dataFieldUpdated()
36 assert view.composerIsEnabled is True
37
38 def testApplySavesDataToModel(self):
39 model, view, presenter = self.getMVP()
40 newTitle = "Some Other Title"
41 view.title = newTitle
42 presenter.updateModel()
43 assert view.title == newTitle
44
45 def testCancelRestoresDataFromModel(self):
46 model, view, presenter = self.getMVP()
47 newTitle = "Some Other Title"
48 view.title = newTitle
49 presenter.loadViewFromModel()
50 assert view.title != newTitle
51
52 def testOrderToggle(self):
53 model, view, presenter = self.getMVP()
54 assert presenter.order is 1
55 assert view.getOrderLabel() == "Z->A"
56 presenter.toggleOrder()
57 assert presenter.order is -1
58 assert view.getOrderLabel() == "A->Z"
59
60 def testAddNewAlbum(self):
61 model, view, presenter = self.getMVP()
62 albumCount = len(presenter.albums)
63 presenter.addNewAlbum()
64 assert len(presenter.albums) is albumCount+1
65
66 if __name__ == '__main__':
67 unittest.main()
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.