Skip to content

Alis 5265 #416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from boto3.dynamodb.conditions import Key
from lambda_base import LambdaBase
from jsonschema import validate, ValidationError
from jsonschema import validate
from db_util import DBUtil
from parameter_util import ParameterUtil
from tag_util import TagUtil
Expand All @@ -30,8 +30,8 @@ def get_schema(self):

def validate_params(self):
UserUtil.verified_phone_and_email(self.event)
if self.event['requestContext']['authorizer']['claims'].get('custom:private_eth_address') is None:
raise ValidationError('not exists private_eth_address')
UserUtil.validate_private_eth_address(self.dynamodb,
self.event['requestContext']['authorizer']['claims']['cognito:username'])

validate(self.params, self.get_schema())

Expand Down Expand Up @@ -81,7 +81,8 @@ def exec_main_proc(self):

def __delete_article_content_edit(self):
article_content_edit_table = self.dynamodb.Table(os.environ['ARTICLE_CONTENT_EDIT_TABLE_NAME'])
article_content_edit = article_content_edit_table.get_item(Key={'article_id': self.params['article_id']}).get('Item')
article_content_edit = article_content_edit_table.get_item(Key={'article_id': self.params['article_id']}).get(
'Item')

if article_content_edit:
article_content_edit_table.delete_item(Key={'article_id': self.params['article_id']})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def get_schema(self):

def validate_params(self):
UserUtil.verified_phone_and_email(self.event)
if self.event['requestContext']['authorizer']['claims'].get('custom:private_eth_address') is None:
raise ValidationError('not exists private_eth_address')
UserUtil.validate_private_eth_address(self.dynamodb,
self.event['requestContext']['authorizer']['claims']['cognito:username'])

# check price type is integer or decimal
ParameterUtil.validate_price_params(self.params.get('price'))
Expand Down
25 changes: 13 additions & 12 deletions src/handlers/me/articles/like/create/me_articles_like_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def get_schema(self):

def validate_params(self):
UserUtil.verified_phone_and_email(self.event)
if self.event['requestContext']['authorizer']['claims'].get('custom:private_eth_address') is None:
raise ValidationError('not exists private_eth_address')
UserUtil.validate_private_eth_address(self.dynamodb,
self.event['requestContext']['authorizer']['claims']['cognito:username'])

# single
if self.event.get('pathParameters') is None:
Expand Down Expand Up @@ -72,7 +72,8 @@ def exec_main_proc(self):

def __create_like_notification(self, article_info):
notification_table = self.dynamodb.Table(os.environ['NOTIFICATION_TABLE_NAME'])
notification_id = '-'.join([settings.LIKE_NOTIFICATION_TYPE, article_info['user_id'], article_info['article_id']])
notification_id = '-'.join(
[settings.LIKE_NOTIFICATION_TYPE, article_info['user_id'], article_info['article_id']])
notification = notification_table.get_item(Key={'notification_id': notification_id}).get('Item')

liked_count = self.__get_article_likes_count()
Expand All @@ -91,15 +92,15 @@ def __create_like_notification(self, article_info):
)
else:
notification_table.put_item(Item={
'notification_id': notification_id,
'user_id': article_info['user_id'],
'article_id': article_info['article_id'],
'article_title': article_info['title'],
'sort_key': TimeUtil.generate_sort_key(),
'type': settings.LIKE_NOTIFICATION_TYPE,
'liked_count': liked_count,
'created_at': int(time.time())
}
'notification_id': notification_id,
'user_id': article_info['user_id'],
'article_id': article_info['article_id'],
'article_title': article_info['title'],
'sort_key': TimeUtil.generate_sort_key(),
'type': settings.LIKE_NOTIFICATION_TYPE,
'liked_count': liked_count,
'created_at': int(time.time())
}
)

def __update_unread_notification_manager(self, article_info):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import os
import boto3
import time

from elasticsearch import Elasticsearch
Expand All @@ -17,7 +16,7 @@


class TestMeArticlesDraftsPublish(TestCase):
dynamodb = boto3.resource('dynamodb', endpoint_url='http://localhost:4569/')
dynamodb = TestsUtil.get_dynamodb_client()
elasticsearch = Elasticsearch(
hosts=[{'host': 'localhost'}]
)
Expand Down Expand Up @@ -109,6 +108,14 @@ def setUp(self):

TestsUtil.create_table(self.dynamodb, os.environ['SCREENED_ARTICLE_TABLE_NAME'], [])

user_configurations_items = [
{
'user_id': 'test01',
'private_eth_address': '0x1234567890123456789012345678901234567890'
},
]
TestsUtil.create_table(self.dynamodb, os.environ['USER_CONFIGURATIONS_TABLE_NAME'], user_configurations_items)

TestsEsUtil.create_tag_index(self.elasticsearch)
self.elasticsearch.indices.refresh(index="tags")

Expand Down Expand Up @@ -142,7 +149,6 @@ def test_main_ok(self):
'authorizer': {
'claims': {
'cognito:username': 'test01',
'custom:private_eth_address': '0x1234567890123456789012345678901234567890',
'phone_number_verified': 'true',
'email_verified': 'true'
}
Expand All @@ -163,7 +169,8 @@ def test_main_ok(self):

self.assertEqual(response['statusCode'], 200)

article_info = self.article_info_table.get_item(Key={'article_id': params['pathParameters']['article_id']})['Item']
article_info = self.article_info_table.get_item(Key={'article_id': params['pathParameters']['article_id']})[
'Item']
article_content = self.article_content_table.get_item(
Key={'article_id': params['pathParameters']['article_id']}
)['Item']
Expand Down Expand Up @@ -195,7 +202,6 @@ def test_main_ok_with_article_content_edit(self):
'authorizer': {
'claims': {
'cognito:username': 'test01',
'custom:private_eth_address': '0x1234567890123456789012345678901234567890',
'phone_number_verified': 'true',
'email_verified': 'true'
}
Expand All @@ -214,7 +220,8 @@ def test_main_ok_with_article_content_edit(self):
article_history_after = self.article_history_table.scan()['Items']
article_content_edit_after = self.article_content_edit_table.scan()['Items']

article_info = self.article_info_table.get_item(Key={'article_id': params['pathParameters']['article_id']})['Item']
article_info = self.article_info_table.get_item(Key={'article_id': params['pathParameters']['article_id']})[
'Item']
article_content = self.article_content_table.get_item(
Key={'article_id': params['pathParameters']['article_id']}
)['Item']
Expand Down Expand Up @@ -244,7 +251,6 @@ def test_main_ok_article_history_arleady_exists(self):
'authorizer': {
'claims': {
'cognito:username': 'test01',
'custom:private_eth_address': '0x1234567890123456789012345678901234567890',
'phone_number_verified': 'true',
'email_verified': 'true'
}
Expand All @@ -263,7 +269,8 @@ def test_main_ok_article_history_arleady_exists(self):
article_history_after = self.article_history_table.scan()['Items']
article_content_edit_after = self.article_content_edit_table.scan()['Items']

article_info = self.article_info_table.get_item(Key={'article_id': params['pathParameters']['article_id']})['Item']
article_info = self.article_info_table.get_item(Key={'article_id': params['pathParameters']['article_id']})[
'Item']
article_content = self.article_content_table.get_item(
Key={'article_id': params['pathParameters']['article_id']}
)['Item']
Expand Down Expand Up @@ -295,7 +302,6 @@ def test_create_and_count_raise_exception(self):
'authorizer': {
'claims': {
'cognito:username': 'test01',
'custom:private_eth_address': '0x1234567890123456789012345678901234567890',
'phone_number_verified': 'true',
'email_verified': 'true'
}
Expand All @@ -321,7 +327,6 @@ def test_call_tag_util_methods(self):
'authorizer': {
'claims': {
'cognito:username': 'test01',
'custom:private_eth_address': '0x1234567890123456789012345678901234567890',
'phone_number_verified': 'true',
'email_verified': 'true'
}
Expand Down Expand Up @@ -363,7 +368,6 @@ def test_call_validate_array_unique(self):
'authorizer': {
'claims': {
'cognito:username': 'test01',
'custom:private_eth_address': '0x1234567890123456789012345678901234567890',
'phone_number_verified': 'true',
'email_verified': 'true'
}
Expand Down Expand Up @@ -395,7 +399,6 @@ def test_call_validate_methods(self):
'authorizer': {
'claims': {
'cognito:username': 'test01',
'custom:private_eth_address': '0x1234567890123456789012345678901234567890',
'phone_number_verified': 'true',
'email_verified': 'true'
}
Expand Down Expand Up @@ -429,7 +432,7 @@ def test_validation_not_exists_private_eth_address(self):
'requestContext': {
'authorizer': {
'claims': {
'cognito:username': 'test01',
'cognito:username': 'no_eth_address_user',
'phone_number_verified': 'true',
'email_verified': 'true'
}
Expand All @@ -438,8 +441,8 @@ def test_validation_not_exists_private_eth_address(self):
}
params['body'] = json.dumps(params['body'])
response = MeArticlesDraftsPublish(params, {}, dynamodb=self.dynamodb, elasticsearch=self.elasticsearch).main()
self.assertEqual(response['statusCode'], 400)
self.assertEqual(response['body'], '{"message": "Invalid parameter: not exists private_eth_address"}')
self.assertEqual(response['statusCode'], 403)
self.assertEqual(response['body'], '{"message": "Not exists private_eth_address"}')

def test_validation_with_no_article_id(self):
params = {
Expand All @@ -451,7 +454,6 @@ def test_validation_with_no_article_id(self):
'authorizer': {
'claims': {
'cognito:username': 'test01',
'custom:private_eth_address': '0x1234567890123456789012345678901234567890',
'phone_number_verified': 'true',
'email_verified': 'true'
}
Expand All @@ -474,7 +476,6 @@ def test_validation_article_id_max(self):
'authorizer': {
'claims': {
'cognito:username': 'test01',
'custom:private_eth_address': '0x1234567890123456789012345678901234567890',
'phone_number_verified': 'true',
'email_verified': 'true'
}
Expand All @@ -497,7 +498,6 @@ def test_validation_article_id_min(self):
'authorizer': {
'claims': {
'cognito:username': 'test01',
'custom:private_eth_address': '0x1234567890123456789012345678901234567890',
'phone_number_verified': 'true',
'email_verified': 'true'
}
Expand All @@ -518,7 +518,6 @@ def test_validation_with_no_topic(self):
'authorizer': {
'claims': {
'cognito:username': 'test01',
'custom:private_eth_address': '0x1234567890123456789012345678901234567890',
'phone_number_verified': 'true',
'email_verified': 'true'
}
Expand All @@ -542,7 +541,6 @@ def test_validation_topic_max(self):
'authorizer': {
'claims': {
'cognito:username': 'test01',
'custom:private_eth_address': '0x1234567890123456789012345678901234567890',
'phone_number_verified': 'true',
'email_verified': 'true'
}
Expand All @@ -566,7 +564,6 @@ def test_validation_many_tags(self):
'authorizer': {
'claims': {
'cognito:username': 'test01',
'custom:private_eth_address': '0x1234567890123456789012345678901234567890',
'phone_number_verified': 'true',
'email_verified': 'true'
}
Expand All @@ -590,7 +587,6 @@ def test_validation_tag_name_max(self):
'authorizer': {
'claims': {
'cognito:username': 'test01',
'custom:private_eth_address': '0x1234567890123456789012345678901234567890',
'phone_number_verified': 'true',
'email_verified': 'true'
}
Expand All @@ -614,7 +610,6 @@ def test_validation_tag_name_min(self):
'authorizer': {
'claims': {
'cognito:username': 'test01',
'custom:private_eth_address': '0x1234567890123456789012345678901234567890',
'phone_number_verified': 'true',
'email_verified': 'true'
}
Expand Down
Loading