def test_process_order(self, name, order, pricing, checker, side_effect=None, err_msg=None): OFFERING['productOfferingPrice'] = [pricing] if side_effect is not None: side_effect(self) ordering_manager = ordering_management.OrderingManager() error = None try: redirect_url = ordering_manager.process_order( self._customer, order) except OrderingError as e: error = e if err_msg is None: self.assertTrue(error is None) # Check returned value self.assertEquals('http://redirectionurl.com/', redirect_url) # Check common calls ordering_management.ChargingEngine.assert_called_once_with( self._order_inst) # Check offering and product downloads self.assertEquals(4, ordering_management.requests.get.call_count) headers = { 'Authorization': 'Bearer ' + self._customer.userprofile.access_token } self.assertEquals([ call( 'http://localhost:8004/DSProductCatalog/api/catalogManagement/v2/productOffering/20:(2.0)' ), call(BILLING_ACCOUNT_HREF, headers=headers), call(BILLING_ACCOUNT['customerAccount']['href'], headers=headers), call(CUSTOMER_ACCOUNT['customer']['href'], headers=headers) ], ordering_management.requests.get.call_args_list) contact_medium = CUSTOMER['contactMedium'][0]['medium'] ordering_management.Order.objects.create.assert_called_once_with( order_id="12", customer=self._customer, owner_organization=self._org_inst, date=self._now, state='pending', tax_address={ 'street': contact_medium['streetOne'] + '\n' + contact_medium['streetTwo'], 'postal': contact_medium['postcode'], 'city': contact_medium['city'], 'province': contact_medium['stateOrProvince'], 'country': contact_medium['country'] }, contracts=[self._contract_inst], description="") # Check particular calls checker(self) else: self.assertEquals(err_msg, unicode(error))
def test_modify_order(self, name, order, pricing, new_pricing, err_msg=None): # Mock order method mock_contract = MagicMock() mock_contract.pricing_model = pricing mock_contract.revenue_class = 'old_revenue' self._order_inst.get_product_contract.return_value = mock_contract ordering_management.InventoryClient = MagicMock() ordering_management.InventoryClient().get_product.return_value = { 'id': '1', 'name': 'oid=35' } ordering = ordering_management.OrderingManager() ordering._build_contract = MagicMock() new_contract = MagicMock() new_contract.pricing_model = new_pricing new_contract.revenue_class = 'new_revenue' ordering._build_contract.return_value = new_contract error = None try: ordering.process_order(self._customer, order) except OrderingError as e: error = e if err_msg is None: self.assertTrue(error is None) ordering_management.InventoryClient( ).get_product.assert_called_once_with('89') ordering_management.Order.objects.get.assert_called_once_with( order_id='35') self._order_inst.get_product_contract.assert_called_once_with('89') ordering._build_contract.assert_called_once_with({ 'id': '1', 'action': 'modify', 'product': { 'id': '89' } }) ordering_management.ChargingEngine.assert_called_once_with( self._order_inst) self._charging_inst.resolve_charging.assert_called_once_with( type_='initial', related_contracts=[mock_contract]) if new_pricing != {}: self.assertEquals(new_pricing, mock_contract.pricing_model) self.assertEquals('new_revenue', mock_contract.revenue_class) else: self.assertEquals(pricing, mock_contract.pricing_model) self.assertEquals('old_revenue', mock_contract.revenue_class) else: self.assertEquals(err_msg, unicode(error))
def test_process_order(self, name, order, pricing, checker, side_effect=None, err_msg=None, terms_accepted=True): #if name == 'free_add': # import ipdb; ipdb.sset_trace() OFFERING['productOfferingPrice'] = [pricing] if side_effect is not None: side_effect(self) ordering_manager = ordering_management.OrderingManager() error = None try: redirect_url = ordering_manager.process_order( self._customer, order, terms_accepted=terms_accepted) except OrderingError as e: error = e if err_msg is None: self.assertTrue(error is None) # Check returned value self.assertEquals('http://redirectionurl.com/', redirect_url) # Check common calls ordering_management.ChargingEngine.assert_called_once_with( self._order_inst) # Check offering and product downloads self.assertEquals(4, ordering_management.requests.get.call_count) headers = { 'Authorization': 'Bearer ' + self._customer.userprofile.access_token } exp_url = 'http://extpath.com:8080{}' exp_billing = 'http://apis.docker:8080{}' self.assertEquals([ call(exp_url.format( '/DSProductCatalog/api/catalogManagement/v2/productOffering/20:(2.0)' ), verify=True), call(exp_billing.format(urlparse(BILLING_ACCOUNT_HREF).path), headers={}, verify=True), call(exp_billing.format( urlparse(BILLING_ACCOUNT['customerAccount']['href']).path), headers={}, verify=True), call(exp_billing.format( urlparse(CUSTOMER_ACCOUNT['customer']['href']).path), headers={}, verify=True) ], ordering_management.requests.get.call_args_list) contact_medium = CUSTOMER['contactMedium'][0]['medium'] ordering_management.Order.objects.create.assert_called_once_with( order_id="12", customer=self._customer, owner_organization=self._org_inst, date=self._now, state='pending', tax_address={ 'street': contact_medium['streetOne'] + '\n' + contact_medium['streetTwo'], 'postal': contact_medium['postcode'], 'city': contact_medium['city'], 'province': contact_medium['stateOrProvince'], 'country': contact_medium['country'] }, contracts=[self._contract_inst], description="") # Check particular calls checker(self) else: self.assertEquals(err_msg, str(error))