Ignore:
Timestamp:
25 Dec 2014, 18:23:17 (10 years ago)
Author:
Henrik Bettermann
Message:

#Remove unchanged product options from data when saving the form.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/products/tests/test_browser.py

    r12288 r12318  
    2323import pytz
    2424import base64
     25from decimal import Decimal
    2526from datetime import datetime, timedelta, date
    2627from StringIO import StringIO
     
    4344from waeup.ikoba.tests.test_async import FunctionalAsyncTestCase
    4445from waeup.ikoba.browser.tests.test_pdf import samples_dir
     46from waeup.ikoba.products.productoptions import ProductOptionEntry
    4547
    4648def lookup_submit_value(name, value, browser):
     
    8385        # to access grok.getSite() and should get our new app then
    8486        setSite(app)
     87
     88        self.logfile = os.path.join(
     89            self.app['datacenter'].storage, 'logs', 'main.log')
    8590
    8691        # Add user
     
    211216            None)
    212217        return
     218
     219    def test_product_options(self):
     220        prodoptions = ProductOptionEntry()
     221        prodoptions.title = u'My option'
     222        prodoptions.fee = Decimal('99.9')
     223        prodoptions.currency = 'usd'
     224        self.product.options = [prodoptions,]
     225        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     226        self.browser.open(self.product_path)
     227        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     228        self.assertEqual(self.product.options[0], prodoptions)
     229        self.browser.open(self.manage_product_path)
     230        self.browser.getControl("Save").click()
     231        # applyData must not exchange the object
     232        self.assertEqual(self.product.options[0], prodoptions)
     233        # and thus not add a logging message (the log file
     234        # do not even exist so far)
     235        self.assertRaises(IOError, open, self.logfile, 'read')
     236        # Now we change the content after opening the manage page
     237        self.browser.open(self.manage_product_path)
     238        prodoptions.title = u'My new option'
     239        self.assertEqual(self.product.options[0].title, 'My new option')
     240        # but save the opened form with the old data.
     241        self.browser.getControl("Save").click()
     242        # The object has been replaced,
     243        self.assertTrue(self.product.options[0] != prodoptions)
     244        # the old title has been restored
     245        self.assertEqual(self.product.options[0].title, 'My option')
     246        # and a logging message has been added.
     247        logcontent = open(self.logfile).read()
     248        self.assertTrue('saved: options' in logcontent)
Note: See TracChangeset for help on using the changeset viewer.