def validate(self): # NAME: if self.name is None: raise MissingRequiredField('name') if self.type is None: raise MissingRequiredField('type')
def validate(self): # NAME: if self.name is not None and not is_empty(self.name): raise StringMustNotBeEmpty('name') if self.buying_price is not None: raise MissingRequiredField('buying_price') if self.selling_price is not None: raise MissingRequiredField('selling_price')
def validate(self): # NAME: if self.name is None: raise MissingRequiredField('name') # BUYING_PRICE if self.buying_price is None: raise MissingRequiredField('buying_price') # SELLING_PRICE if self.selling_price is None: raise MissingRequiredField('selling_price')
def validate(self): if self.room_number is None: raise MissingRequiredField('room_number') if is_empty(self.room_number): raise StringMustNotBeEmpty('room_number') if self.description is None: raise MissingRequiredField('description') if self.vlan_number is None: raise MissingRequiredField('vlan_number') if is_empty(self.vlan_number): raise StringMustNotBeEmpty('vlan_number')
def validate(self): """ Validate the fields that are set in a MutationRequest. """ if self.name is None: raise MissingRequiredField('name') if is_empty(self.name): raise StringMustNotBeEmpty('name')
def validate(self): """ Validate the fields that are set in a MutationRequest. """ if self.ip_v4 is None: raise MissingRequiredField('ip_v4') if not is_ip_v4(self.ip_v4): raise InvalidIPv4(self.ip_v4) if self.description is None: raise MissingRequiredField('description') if self.community is None: raise MissingRequiredField('community') if is_empty(self.community): raise StringMustNotBeEmpty('community')
def update_or_create(self, ctx, req: FullMutationRequest, product_id=None) -> bool: req.validate() LOG.info('product_update_or_create', extra=log_extra(ctx, product_id=product_id)) try: result, _ = self.product_repository.search_product_by( ctx, product_id=product_id) fields = {k: v for k, v in asdict(req).items()} except ProductNotFoundError: raise Exception if req.name == '': raise StringMustNotBeEmpty('name') if not req.name: raise MissingRequiredField('name') if not req.selling_price: raise MissingRequiredField('selling_price') if not req.buying_price: raise MissingRequiredField('buying_price') if not result or not product_id: LOG.info('product_create', extra=log_extra(ctx, product_id=product_id)) # No product with that id/name, creating one... self.product_repository.create_product(ctx, **fields) return True else: # A product exists, updating it # Warning: ProductNotFound LOG.info('product_update', extra=log_extra( ctx, product_id=product_id, )) self.product_repository.update_product(ctx, product_id=product_id, **fields) return False
def validate(self): # NAME: if self.name is not None and not is_empty(self.name): raise StringMustNotBeEmpty('name') if self.type is not None: raise MissingRequiredField('type') # CREATION_DATE: if self.creation_date is not None and not is_date(self.creation_date): raise InvalidDate(self.creation_date)
def validate(self): """ Validate the fields that are set in a MutationRequest. """ if self.port_number is None: raise MissingRequiredField('port_number') if is_empty(self.port_number): raise StringMustNotBeEmpty('port_number') if self.switch_id is None: raise MissingRequiredField('switch_id') if is_empty(self.switch_id): raise StringMustNotBeEmpty('switch_id') if self.rcom is None: raise MissingRequiredField('rcom') if self.rcom < 0: raise IntMustBePositive('rcom')
def update_or_create(self, ctx, req: FullMutationRequest, account_id=None) -> bool: req.validate() try: result, _ = self.account_repository.search_account_by( ctx, account_id=account_id) fields = {k: v for k, v in asdict(req).items()} except AccountNotFoundError: raise if req.name == '': raise StringMustNotBeEmpty('name') if not req.name: raise MissingRequiredField('name') if not req.type: raise MissingRequiredField('type') if not result or not account_id: LOG.info('account_create', extra=log_extra(ctx, account_id=account_id, type=req.type)) # No account with that name, creating one... self.account_repository.create_account(ctx, **fields) return True else: # An account exists, updating it # Warning: AccountNotFound LOG.info('account_update', extra=log_extra( ctx, account_id=account_id, )) self.account_repository.update_account(ctx, account_id=account_id, **fields) return False
def validate(self): # EMAIL: if self.email is None: raise MissingRequiredField('email') # FIRST_NAME: if self.first_name is None: raise MissingRequiredField('first_name') # LAST_NAME: if self.last_name is None: raise MissingRequiredField('last_name') # USERNAME: if self.username is None: raise MissingRequiredField('username') # DEPARTURE_DATE: if self.departure_date is None: raise MissingRequiredField('departure_date') super().validate()
def validate(self): # SOURCE: if self.src is None: raise MissingRequiredField('src') # DESTINATION: if self.dst is None: raise MissingRequiredField('dst') # NAME: if self.name is None: raise MissingRequiredField('name') # VALUE: if self.value is None: raise MissingRequiredField('value') # TYPE: if self.paymentMethod is None: raise MissingRequiredField('paymentMethod') super().validate()
def validate(self): # MAC ADDRESS: if not is_mac_address(self.mac_address): raise InvalidMACAddress(self.mac_address) # OWNER USERNAME: if is_empty(self.owner_username): raise MissingRequiredField('owner_username') # CONNECTION TYPE: if self.connection_type not in ALL_DEVICE_TYPES: raise ValueError('invalid connection type') # IP_V4_ADDRESS: if self.ip_v4_address is not None and not is_ip_v4(self.ip_v4_address): raise InvalidIPv4(self.ip_v4_address) # IP_V6_ADDRESS: if self.ip_v6_address is not None and not is_ip_v6(self.ip_v6_address): raise InvalidIPv6(self.ip_v6_address)