def test_main_ok(self): params = { 'pathParameters': { 'article_id': 'publicId0001' }, 'requestContext': { 'authorizer': { 'claims': { 'cognito:username': '******' } } } } response = MeArticlesPublicEdit(params, {}, self.dynamodb).main() expected_item = { 'article_id': 'publicId0001', 'user_id': 'test01', 'title': 'sample_title1', 'body': 'sample_body1', 'overview': 'sample_overview', 'eye_catch_url': 'http://example.com/eye_catch_url' } self.assertEqual(response['statusCode'], 200) self.assertEqual(json.loads(response['body']), expected_item)
def test_call_validate_article_existence(self): params = { 'pathParameters': { 'article_id': 'publicId0001' }, 'requestContext': { 'authorizer': { 'claims': { 'cognito:username': '******', 'phone_number_verified': 'true', 'email_verified': 'true' } } } } mock_lib = MagicMock() with patch('me_articles_public_edit.DBUtil', mock_lib): MeArticlesPublicEdit(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'], 'public')
def test_main_ok_with_paid_body(self): params = { 'pathParameters': { 'article_id': 'publicId0003' }, 'requestContext': { 'authorizer': { 'claims': { 'cognito:username': '******', 'phone_number_verified': 'true', 'email_verified': 'true' } } } } response = MeArticlesPublicEdit(params, {}, self.dynamodb).main() expected_item = { 'article_id': 'publicId0003', 'body': 'sample_paid_body3', 'eye_catch_url': 'http://example.com/eye_catch_url', 'overview': 'sample_overview', 'sort_key': 1520150272000000, 'status': 'public', 'title': 'sample_title3', 'user_id': 'test01', 'price': 100 } self.assertEqual(response['statusCode'], 200) self.assertEqual(json.loads(response['body']), expected_item)
def test_main_ok_with_content_edit_history(self): params = { 'pathParameters': { 'article_id': 'publicId0001' }, 'queryStringParameters': { 'version': '01' }, 'requestContext': { 'authorizer': { 'claims': { 'cognito:username': '******', 'phone_number_verified': 'true', 'email_verified': 'true' } } } } response = MeArticlesPublicEdit(params, {}, self.dynamodb).main() expected_item = { 'article_id': 'publicId0001', 'body': 'test01_body_01', 'eye_catch_url': 'http://example.com/eye_catch_url', 'overview': 'sample_overview', 'sort_key': 1520150272000000, 'status': 'public', 'tag': ['hoge', 'fuga'], 'title': 'sample_title1', 'topic': 'aaa', 'user_id': 'test01' } self.assertEqual(response['statusCode'], 200) self.assertEqual(json.loads(response['body']), expected_item)
def assert_bad_request(self, params): function = MeArticlesPublicEdit(params, {}, self.dynamodb) response = function.main() self.assertEqual(response['statusCode'], 400)
def lambda_handler(event, context): me_articles_public_edit = MeArticlesPublicEdit(event, context, dynamodb) return me_articles_public_edit.main()