def _validate_offering_pricing(self, provider, product_offering, bundled_offerings): is_open = False # Validate offering pricing fields if 'productOfferingPrice' in product_offering: names = [] for price_model in product_offering['productOfferingPrice']: if 'name' not in price_model: raise ValueError('Missing required field name in productOfferingPrice') if price_model['name'].lower() in names: raise ValueError('Price plans names must be unique (' + price_model['name'] + ')') names.append(price_model['name'].lower()) # Check if the offering is an open offering if price_model['name'].lower() == 'open' and (len(price_model.keys()) == 1 or (len(price_model.keys()) == 2 and 'description' in price_model)): is_open = True continue # Validate price unit if 'priceType' not in price_model: raise ValueError('Missing required field priceType in productOfferingPrice') if price_model['priceType'] != 'one time' and price_model['priceType'] != 'recurring' and price_model['priceType'] != 'usage': raise ValueError('Invalid priceType, it must be one time, recurring, or usage') if price_model['priceType'] == 'recurring' and 'recurringChargePeriod' not in price_model: raise ValueError('Missing required field recurringChargePeriod for recurring priceType') if price_model['priceType'] == 'recurring' and not ChargePeriod.contains(price_model['recurringChargePeriod']): raise ValueError('Unrecognized recurringChargePeriod: ' + price_model['recurringChargePeriod']) # Validate currency if 'price' not in price_model: raise ValueError('Missing required field price in productOfferingPrice') if 'currencyCode' not in price_model['price']: raise ValueError('Missing required field currencyCode in price') if not CurrencyCode.contains(price_model['price']['currencyCode']): raise ValueError('Unrecognized currency: ' + price_model['price']['currencyCode']) if Decimal(price_model['price']['taxIncludedAmount']) <= Decimal("0"): raise ValueError('Invalid price, it must be greater than zero.') if is_open and len(names) > 1: raise ValueError('Open offerings cannot include price plans') return is_open
def _validate_offering_pricing(self, provider, product_offering, bundled_offerings): # Validate offering pricing fields if 'productOfferingPrice' in product_offering: names = [] for price_model in product_offering['productOfferingPrice']: if 'name' not in price_model: raise ValueError('Missing required field name in productOfferingPrice') if price_model['name'].lower() in names: raise ValueError('Price plans names must be unique (' + price_model['name'] + ')') names.append(price_model['name'].lower()) # Validate price unit if 'priceType' not in price_model: raise ValueError('Missing required field priceType in productOfferingPrice') if price_model['priceType'] != 'one time' and price_model['priceType'] != 'recurring' and price_model['priceType'] != 'usage': raise ValueError('Invalid priceType, it must be one time, recurring, or usage') if price_model['priceType'] == 'recurring' and 'recurringChargePeriod' not in price_model: raise ValueError('Missing required field recurringChargePeriod for recurring priceType') if price_model['priceType'] == 'recurring' and not ChargePeriod.contains(price_model['recurringChargePeriod']): raise ValueError('Unrecognized recurringChargePeriod: ' + price_model['recurringChargePeriod']) # Validate currency if 'price' not in price_model: raise ValueError('Missing required field price in productOfferingPrice') if 'currencyCode' not in price_model['price']: raise ValueError('Missing required field currencyCode in price') if not CurrencyCode.contains(price_model['price']['currencyCode']): raise ValueError('Unrecognized currency: ' + price_model['price']['currencyCode']) if Decimal(price_model['price']['taxIncludedAmount']) <= Decimal("0"): raise ValueError('Invalid price, it must be greater than zero.')
def read(self, request): return JsonResponse(200, ChargePeriod.to_json())
def test_should_parse_to_json(self): dict_expected = [ self.valid, ] self.assertEqual(ChargePeriod.to_json(), dict_expected)
def test_should_get_value_of_given_title(self, name, valid, uppercase): title = self._get_title(valid, uppercase) expected = self.valid['value'] if valid else None self.assertEqual(ChargePeriod.get_value(title), expected)
def test_should_check_if_given_title_exists(self, name, valid, uppercase, expected): title = self._get_title(valid, uppercase) self.assertEqual(ChargePeriod.contains(title), expected)
def _calculate_renovation_date(self, unit): return datetime.utcnow() + timedelta(days=ChargePeriod.get_value(unit))