Ignore:
Timestamp:
28 Oct 2011, 05:34:33 (13 years ago)
Author:
Henrik Bettermann
Message:

Add UI tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py

    r6951 r6961  
    1515##
    1616"""
    17 Tests for hostels.
     17Tests for hostels. and their UI components
    1818"""
     19import shutil
     20import tempfile
    1921from zope.interface.verify import verifyClass, verifyObject
     22from zope.component.hooks import setSite, clearSite
     23from zope.testbrowser.testing import Browser
     24from zope.security.interfaces import Unauthorized
     25from waeup.sirp.app import University
    2026from waeup.sirp.hostels.interfaces import (
    2127    IHostelsContainer, IHostel)
     
    5561        self.assertRaises(
    5662            NotImplementedError, container.clear)
     63
     64class HostelsFullSetup(FunctionalTestCase):
     65
     66    def setUp(self):
     67        super(HostelsFullSetup, self).setUp()
     68
     69        # Setup a sample site for each test
     70        app = University()
     71        self.dc_root = tempfile.mkdtemp()
     72        app['datacenter'].setStoragePath(self.dc_root)
     73
     74        # Prepopulate the ZODB...
     75        self.getRootFolder()['app'] = app
     76        # we add the site immediately after creation to the
     77        # ZODB. Catalogs and other local utilities are not setup
     78        # before that step.
     79        self.app = self.getRootFolder()['app']
     80        # Set site here. Some of the following setup code might need
     81        # to access grok.getSite() and should get our new app then
     82        setSite(app)
     83
     84        self.container_path = 'http://localhost/app/hostels'
     85        self.manage_container_path = self.container_path + '/@@manage'
     86        self.add_hostel_path = self.container_path + '/addhostel'
     87
     88        # Put the prepopulated site into test ZODB and prepare test
     89        # browser
     90        self.browser = Browser()
     91        self.browser.handleErrors = False
     92
     93    def tearDown(self):
     94        super(HostelsFullSetup, self).tearDown()
     95        clearSite()
     96        shutil.rmtree(self.dc_root)
     97
     98class HostelsUITests(HostelsFullSetup):
     99
     100    layer = FunctionalLayer
     101
     102    def test_anonymous_access(self):
     103        # Anonymous users can't access hostels containers
     104        self.assertRaises(
     105            Unauthorized, self.browser.open, self.manage_container_path)
     106        return
     107
     108    def test_add_search_delete_hostels(self):
     109        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     110        self.browser.open(self.container_path)
     111        self.browser.getLink("Manage accommodation").click()
     112        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     113        self.assertEqual(self.browser.url, self.manage_container_path)
     114        self.browser.getControl("Add hostel").click()
     115        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     116        self.assertEqual(self.browser.url, self.add_hostel_path)
     117        self.browser.getControl("Create hostel").click()
     118        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     119        self.assertTrue('Hostel created' in self.browser.contents)
     120        #import pdb; pdb.set_trace()
     121        hall = self.app['hostels']['hall_1']
     122        hall.blocks_for_female = ['A','B']
     123        self.browser.open(self.container_path + '/hall_1')
     124        expected = '''...<ul id="form.blocks_for_female" ><li>Block A</li>
     125<li>Block B</li></ul>...'''
     126        self.assertMatches(expected,self.browser.contents)
     127        self.browser.open(self.container_path + '/hall_1/edit')
Note: See TracChangeset for help on using the changeset viewer.