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.
  • [get | view] (2009-10-04 09:16:02, 0.7 KB) [[attachment:albums.pyw]]
  • [get | view] (2009-10-04 09:16:02, 1.5 KB) [[attachment:interactors.py]]
  • [get | view] (2009-10-04 09:16:02, 2.3 KB) [[attachment:mock_objects.py]]
  • [get | view] (2009-10-04 09:16:02, 1.1 KB) [[attachment:models.py]]
  • [get | view] (2009-10-04 09:16:02, 12.4 KB) [[attachment:mvp.png]]
  • [get | view] (2009-10-04 09:16:02, 5.5 KB) [[attachment:mvp.zip]]
  • [get | view] (2009-10-04 09:16:02, 12.9 KB) [[attachment:mvp2.png]]
  • [get | view] (2009-10-04 09:16:02, 5.9 KB) [[attachment:mvp2.zip]]
  • [get | view] (2009-10-04 09:16:02, 3.8 KB) [[attachment:package.zip]]
  • [get | view] (2009-10-04 09:16:02, 4.4 KB) [[attachment:presenters.py]]
  • [get | view] (2009-10-04 09:16:02, 2.2 KB) [[attachment:test_presenters.py]]
  • [get | view] (2009-10-04 09:16:02, 4.3 KB) [[attachment:views.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.