コード例 #1
0
    def test_main_ok(self):
        params = {
            'pathParameters': {
                'article_id': 'draftId00001'
            },
            'requestContext': {
                'authorizer': {
                    'claims': {
                        'cognito:username': '******'
                    }
                }
            }
        }

        response = MeArticlesDraftsShow(params, {}, self.dynamodb).main()

        expected_item = {
            'article_id': 'draftId00001',
            'user_id': 'test01',
            'status': 'draft',
            'sort_key': 1520150272000000,
            'title': 'sample_title1',
            'body': 'sample_body1'
        }

        self.assertEqual(response['statusCode'], 200)
        self.assertEqual(json.loads(response['body']), expected_item)
コード例 #2
0
    def test_call_validate_article_existence(self):
        params = {
            'pathParameters': {
                'article_id': 'draftId00001'
            },
            'requestContext': {
                'authorizer': {
                    'claims': {
                        'cognito:username': '******',
                        'phone_number_verified': 'true',
                        'email_verified': 'true'
                    }
                }
            }
        }

        mock_lib = MagicMock()
        with patch('me_articles_drafts_show.DBUtil', mock_lib):
            MeArticlesDraftsShow(params, {}, self.dynamodb).main()
            args, kwargs = mock_lib.validate_article_existence.call_args

            self.assertTrue(mock_lib.validate_article_existence.called)
            self.assertTrue(args[0])
            self.assertTrue(args[1])
            self.assertTrue(kwargs['user_id'])
            self.assertEqual(kwargs['status'], 'draft')
コード例 #3
0
    def test_main_ok_with_paid_body(self):
        params = {
            'pathParameters': {
                'article_id': 'draftId00003'
            },
            'requestContext': {
                'authorizer': {
                    'claims': {
                        'cognito:username': '******',
                        'phone_number_verified': 'true',
                        'email_verified': 'true'
                    }
                }
            }
        }

        response = MeArticlesDraftsShow(params, {}, self.dynamodb).main()

        expected_item = {
            'article_id': 'draftId00003',
            'body': 'sample_paid_body3',
            'sort_key': 1520150272000000,
            'status': 'draft',
            'title': 'sample_title3',
            'user_id': 'test01',
            'price': 100
        }

        self.assertEqual(response['statusCode'], 200)
        self.assertEqual(json.loads(response['body']), expected_item)
コード例 #4
0
    def assert_bad_request(self, params):
        function = MeArticlesDraftsShow(params, {}, self.dynamodb)
        response = function.main()

        self.assertEqual(response['statusCode'], 400)
コード例 #5
0
def lambda_handler(event, context):
    me_articles_drafts_show = MeArticlesDraftsShow(event, context, dynamodb)
    return me_articles_drafts_show.main()