Ignore:
Timestamp:
30 Dec 2014, 09:49:24 (10 years ago)
Author:
Henrik Bettermann
Message:

Test contract product option handling in UI.

File:
1 edited

Legend:

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

    r12336 r12341  
    2323import pytz
    2424import base64
     25from decimal import Decimal
    2526from datetime import datetime, timedelta, date
    2627from StringIO import StringIO
     
    5253from waeup.ikoba.interfaces import VERIFIED
    5354from waeup.ikoba.browser.tests.test_pdf import samples_dir
     55from waeup.ikoba.products.productoptions import ProductOption
    5456
    5557PH_LEN = 15911  # Length of placeholder file
     
    104106        self.product.title = u'Our Sample Product'
    105107        self.product.contract_category = u'sample'
     108        prodoption = ProductOption()
     109        prodoption.title = u'First option'
     110        prodoption.fee = Decimal('99.9')
     111        prodoption.currency = 'usd'
     112        self.product.options = [prodoption,]
    106113        self.app['products'].addProduct(self.product)
    107114
     
    11541161        # Managers can access the pages of customer contractsconter
    11551162        # and can perform actions
     1163        IWorkflowState(self.customer).setState(APPROVED)
    11561164        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    11571165        self.browser.open(self.customer_path)
     
    12001208            in logcontent)
    12011209        self.assertTrue(
    1202             'INFO - zope.mgr - customers.browser.ContractAddFormPage '
     1210            'INFO - zope.mgr - customers.browser.ContractAddPage '
    12031211            '- K1000000 - added: Sample Contract %s'
    12041212            % contract.contract_id in logcontent)
     
    12101218            in logcontent)
    12111219        self.assertTrue(
    1212             'INFO - zope.mgr - customers.browser.ContractsManageFormPage '
     1220            'INFO - zope.mgr - customers.browser.ContractsFormPage '
    12131221            '- K1000000 - removed: %s' % conid
    12141222            in logcontent)
     
    12291237            '...You logged in...', self.browser.contents)
    12301238        self.browser.getLink("Contracts").click()
     1239        # Customer is in wrong state
     1240        self.assertFalse('Add contract' in self.browser.contents)
     1241        self.browser.open(self.contracts_path + '/addcontract')
     1242        self.assertTrue('The requested form is locked' in self.browser.contents)
     1243        IWorkflowState(self.customer).setState(APPROVED)
     1244        self.browser.open(self.contracts_path)
     1245        # Now customer can add a contract
    12311246        self.browser.getControl("Add contract").click()
    12321247        self.browser.getControl(name="contype").value = ['SampleContract']
     
    12351250        conid = [i for i in self.customer['contracts'].keys() if len(i) > 10][0]
    12361251        contract = self.customer['contracts'][conid]
    1237         # Contract can be edited ...
    1238         self.browser.open(self.contracts_path + '/%s/edit' % conid)
    1239         #self.browser.getLink("Edit").click()
    1240         self.assertTrue('The requested form is locked' in self.browser.contents)
    1241         # Customer is in wrong state
    1242         IWorkflowState(self.customer).setState(APPROVED)
    1243         self.browser.open(self.contracts_path + '/%s/edit' % conid)
     1252        self.assertEqual(
     1253            self.browser.url, self.contracts_path + '/%s/selectproduct' % conid)
    12441254        # SAM is in the correct contract_category ...
    12451255        self.assertTrue('<option value="SAM">' in self.browser.contents)
     
    12491259        self.assertTrue(self.customer['contracts'][conid].last_product_id is None)
    12501260        self.browser.getControl(name="form.product_object").value = ['SAM']
     1261        self.browser.getControl("Save and proceed").click()
     1262        self.assertEqual(
     1263            self.browser.url, self.contracts_path + '/%s/edit' % conid)
     1264        # Document is a required field on edit form page.
    12511265        self.browser.getControl("Save").click()
    1252         # Document is a required field on edit form page.
    12531266        self.assertTrue('Document: <span class="error">Required input is missing.</span>'
    12541267            in self.browser.contents)
     
    12571270        IWorkflowState(self.document).setState(SUBMITTED)
    12581271        self.browser.open(self.contracts_path + '/%s/edit' % conid)
    1259         self.browser.getControl(name="form.product_object").value = ['SAM']
    12601272        self.browser.getControl(name="form.document_object").value = ['DOC1']
    12611273        self.browser.getControl("Save").click()
     
    12701282        self.assertEqual(self.customer['contracts'][conid].last_product_id, 'SAM')
    12711283        self.assertTrue('Form has been saved.' in self.browser.contents)
     1284        # So far we have not yet set product options.
     1285        # Unfortunately, we can't set them in test browser
     1286        prodoption = ProductOption()
     1287        prodoption.title = u'Any product option'
     1288        prodoption.fee = Decimal('88.8')
     1289        prodoption.currency = 'eur'
     1290        contract.product_options = [prodoption,]
     1291        self.browser.open(self.contracts_path + '/%s/edit' % conid)
     1292        # We can see both the stored and the recent product options
     1293        # from the chosen product.
     1294        self.assertTrue('<option selected="selected" value="Any product option">'
     1295                        'Any product option @ 88.8 eur</option>'
     1296                        in self.browser.contents)
     1297        self.assertTrue('<option value="First option">First option '
     1298                        '@ 99.9 usd</option>' in self.browser.contents)
     1299        # In test browser we can at least replace the option
     1300        self.browser.getControl(
     1301            name="form.product_options.0.").value = ['First option']
     1302        self.assertEqual(contract.product_options[0].title, 'Any product option')
     1303        self.browser.getControl("Save").click()
     1304        self.assertEqual(contract.product_options[0].title, 'First option')
    12721305        self.browser.getLink("View").click()
     1306        self.assertTrue('<span>First option @ 99.9 usd</span>' in self.browser.contents)
    12731307        self.assertEqual(self.browser.url, self.contracts_path + '/%s/index' % conid)
    12741308        # An href attribute is referring to the document and product objects
Note: See TracChangeset for help on using the changeset viewer.