def test_main_ok(self):
        params = {
            'requestContext': {
                'authorizer': {
                    'claims': {
                        'cognito:username': '******',
                        'phone_number_verified': 'true',
                        'email_verified': 'true'
                    }
                }
            }
        }

        article_info_before = self.article_info_table.scan()['Items']
        article_content_before = self.article_content_table.scan()['Items']

        me_articles_drafts_article_id_create = MeArticlesDraftsArticleIdCreate(
            params, {}, self.dynamodb)

        response = me_articles_drafts_article_id_create.main()

        article_info_after = self.article_info_table.scan()['Items']
        article_content_after = self.article_content_table.scan()['Items']

        self.assertEqual(json.loads(response['body']),
                         {'article_id': 'HOGEHOGEHOGE'})

        self.assertEqual(response['statusCode'], 200)
        self.assertEqual(
            params['requestContext']['authorizer']['claims']
            ['cognito:username'], article_info_after[0]['user_id'])
        self.assertEqual(len(article_info_after) - len(article_info_before), 1)
        self.assertEqual(
            len(article_content_after) - len(article_content_before), 1)
    def assert_bad_request(self, params):
        function = MeArticlesDraftsArticleIdCreate(params, {}, self.dynamodb)
        response = function.main()

        self.assertEqual(response['statusCode'], 400)
Exemple #3
0
def lambda_handler(event, context):
    me_articles_drafts_article_id_create = MeArticlesDraftsArticleIdCreate(
        event, context, dynamodb)
    return me_articles_drafts_article_id_create.main()