def validate_params(self): UserUtil.verified_phone_and_email(self.event) # single # check price type is integer or decimal try: self.params['price'] = int(self.params['price']) except ValueError: raise ValidationError('Price must be integer') # check price value is not decimal price = self.params['price'] / 10**18 if price.is_integer() is False: raise ValidationError('Decimal value is not allowed') validate(self.params, self.get_schema()) # relation DBUtil.validate_article_existence(self.dynamodb, self.params['article_id'], status='public') DBUtil.validate_latest_price(self.dynamodb, self.params['article_id'], self.params['price']) DBUtil.validate_not_purchased( self.dynamodb, self.params['article_id'], self.event['requestContext']['authorizer']['claims'] ['cognito:username'])
def validate_params(self): # 認証・ウォレット情報が登録済であること UserUtil.verified_phone_and_email(self.event) UserUtil.validate_private_eth_address( self.dynamodb, self.event['requestContext']['authorizer']['claims'] ['cognito:username']) # single validate(self.params, self.get_schema()) # 署名が正しいこと PrivateChainUtil.validate_raw_transaction_signature( self.params['purchase_signed_transaction'], self.event['requestContext']['authorizer']['claims'] ['custom:private_eth_address']) PrivateChainUtil.validate_raw_transaction_signature( self.params['burn_signed_transaction'], self.event['requestContext']['authorizer']['claims'] ['custom:private_eth_address']) # relation DBUtil.validate_article_existence(self.dynamodb, self.params['article_id'], status='public', is_purchased=True) DBUtil.validate_not_purchased( self.dynamodb, self.params['article_id'], self.event['requestContext']['authorizer']['claims'] ['cognito:username'])
def test_validate_status_doing_or_done_2_cases(self): with self.assertRaises(ValidationError): article_id = 'articleid003' user_id = 'purchaseuser004' DBUtil.validate_not_purchased( self.dynamodb, article_id, user_id )
def test_validate_not_purchased(self): with self.assertRaises(ValidationError): article_id = 'articleid001' user_id = 'purchaseuser001' DBUtil.validate_not_purchased( self.dynamodb, article_id, user_id )
def test_validate_not_exist_article(self): article_id = 'articleidxxx' user_id = 'purchaseuser001' self.assertTrue(DBUtil.validate_not_purchased( self.dynamodb, article_id, user_id ))
def test_validate_not_purchased_only_fail(self): article_id = 'articleid003' user_id = 'purchaseuser001' self.assertTrue(DBUtil.validate_not_purchased( self.dynamodb, article_id, user_id ))