Ignore:
Timestamp:
27 Nov 2014, 17:08:19 (10 years ago)
Author:
Henrik Bettermann
Message:

Add more products browser tests.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/permissions.py

    r12068 r12072  
    9292    grok.permissions('waeup.viewProducts')
    9393
    94 class ProductssManager(grok.Role):
     94class ProductsManager(grok.Role):
    9595    grok.name('waeup.ProductsManager')
    9696    grok.title(u'Products Manager')
  • main/waeup.ikoba/trunk/src/waeup/ikoba/products/browser.py

    r12068 r12072  
    9999                       type='danger')
    100100            return
    101         delSubobjects(self, redirect='@@manage', tab='2')
     101        delSubobjects(self, redirect='manage', tab='2')
    102102        return
    103103
     
    113113    @action(_('Add product'), validator=NullValidator)
    114114    def addSubunit(self, **data):
    115         self.redirect(self.url(self.context, '@@addproduct'))
     115        self.redirect(self.url(self.context, 'addproduct'))
    116116        return
    117117
     
    142142        self.context.__parent__.logger.info(
    143143            '%s - added: %s' % (ob_class, data['product_id']))
    144         self.redirect(self.url(self.context, u'@@manage')+'#tab2')
     144        self.redirect(self.url(self.context, u'manage')+'#tab2')
    145145        return
    146146
  • main/waeup.ikoba/trunk/src/waeup/ikoba/products/tests/test_browser.py

    r12069 r12072  
    8484        setSite(app)
    8585
    86 
    87         self.login_path = 'http://localhost/app/login'
    88 
     86        # Add user
     87        self.app['users'].addUser(name='john', password='johnpwd',
     88                                  title='John Tester',
     89                                  email='john@tester.de')
     90
     91        # Add some product
     92        self.product = createObject('waeup.Product')
     93        self.product.product_id = u'LIC'
     94        self.product.title = u'Our License'
     95        self.app['products'].addProduct(self.product)
     96
     97        # Add session configuration
    8998        self.app['configuration'].carry_over = True
    9099        configuration = createObject('waeup.SessionConfiguration')
     100
    91101        self.app['configuration'].addSessionConfiguration(configuration)
     102        self.login_path = 'http://localhost/app/login'
     103        self.container_path = 'http://localhost/app/products'
     104        self.manage_container_path = self.container_path + '/manage'
     105        self.add_product_path = self.container_path + '/addproduct'
     106        self.product_path = self.container_path + '/LIC'
     107        self.manage_product_path = self.container_path + '/LIC/manage'
    92108
    93109        # Put the prepopulated site into test ZODB and prepare test
     
    97113
    98114    def tearDown(self):
    99         super(CustomersFullSetup, self).tearDown()
     115        super(ProductssFullSetup, self).tearDown()
    100116        clearSite()
    101117        shutil.rmtree(self.dc_root)
     118
     119class ProductsContainerUITests(ProductssFullSetup):
     120    # Tests for ProductsContainer class views and pages
     121
     122    layer = FunctionalLayer
     123
     124    def test_anonymous_access(self):
     125        # Anonymous users can view products containers ...
     126        self.browser.open(self.container_path)
     127        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     128        # ... but not manage
     129        self.assertRaises(
     130            Unauthorized, self.browser.open, self.manage_container_path)
     131        return
     132
     133    def test_manage_access(self):
     134        # Managers can access the view page of products
     135        # containers and can perform actions
     136        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     137        self.browser.open(self.container_path)
     138        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     139        self.assertEqual(self.browser.url, self.container_path)
     140        self.browser.getLink("Manage").click()
     141        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     142        self.assertEqual(self.browser.url, self.manage_container_path)
     143        return
     144
     145    def test_add_delete_products(self):
     146        # Managers can add search and remove products
     147        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     148        self.browser.open(self.manage_container_path)
     149        self.browser.getControl("Add product").click()
     150        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     151        self.assertEqual(self.browser.url, self.add_product_path)
     152        self.browser.getControl(name="form.product_id").value = 'bob'
     153        self.browser.getControl(name="form.title").value = 'My product'
     154        self.browser.getControl("Create product").click()
     155        self.assertTrue('Product bob added' in self.browser.contents)
     156        self.assertEqual(len(self.app['products'].keys()), 2)
     157        self.assertEqual(self.app['products']['bob'].title, 'My product')
     158        ctrl = self.browser.getControl(name='val_id')
     159        ctrl.getControl(value='bob').selected = True
     160        self.browser.getControl("Remove selected", index=0).click()
     161        self.assertTrue('Successfully removed' in self.browser.contents)
     162        self.assertEqual(len(self.app['products'].keys()), 1)
     163
     164
     165class ProductsUITests(ProductssFullSetup):
     166    # Tests for Products class views and pages
     167
     168    layer = FunctionalLayer
     169
     170    def test_anonymous_access(self):
     171        # Anonymous users can access products ...
     172        self.browser.open(self.product_path)
     173        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     174        # ... but not manage products
     175        self.assertRaises(
     176            Unauthorized, self.browser.open, self.manage_product_path)
     177        return
     178
     179    def test_manage_access(self):
     180        # Managers can access the view page of products
     181        # and can perform actions
     182        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     183        self.browser.open(self.product_path)
     184        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     185        self.browser.getLink("Manage").click()
     186        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     187        self.assertEqual(self.browser.url, self.manage_product_path)
     188        self.browser.getControl(name="form.title").value = 'New license'
     189        self.browser.getControl("Save").click()
     190        self.assertEqual(self.app['products']['LIC'].title, 'New license')
     191        # Managers can asign local roles
     192        self.browser.getControl(name="user").value = ['john']
     193        self.browser.getControl(
     194            name="local_role").value = ['waeup.local.ProductManager']
     195        self.browser.getControl("Add local role").click()
     196        self.assertTrue('john|waeup.local.ProductManager' in self.browser.contents)
     197        self.assertEqual(
     198            self.app['users']['john'].getLocalRoles().get(
     199                'waeup.local.ProductManager')[0],
     200            self.product)
     201        # If products is deleted also the local role disappears
     202        self.browser.open(self.manage_container_path)
     203        ctrl = self.browser.getControl(name='val_id')
     204        ctrl.getControl(value='LIC').selected = True
     205        self.browser.getControl("Remove selected", index=0).click()
     206        self.assertEqual(
     207            self.app['users']['john'].getLocalRoles().get('waeup.local.ProductManager'),
     208            None)
     209        return
Note: See TracChangeset for help on using the changeset viewer.