def test_main_ok(self): response = ArticlesEyecatch({}, {}, dynamodb=self.dynamodb).main() self.assertEqual(response['statusCode'], 200) expected = [ self.article_info_items[0], self.article_info_items[1], self.article_info_items[2] ] self.assertEqual(json.loads(response['body'])['Items'], expected)
def test_main_ok_with_empty_article(self): table = self.dynamodb.Table(os.environ['SCREENED_ARTICLE_TABLE_NAME']) params = { 'queryStringParameters': { 'topic': 'test_topic' } } table.delete_item(Key={'article_type': 'eyecatch'}) response = ArticlesEyecatch(params, {}, dynamodb=self.dynamodb).main() self.assertEqual(response['statusCode'], 200) expected = [] self.assertEqual(json.loads(response['body'])['Items'], expected) table.put_item(Item={ 'article_type': 'eyecatch', 'articles': {} }) response = ArticlesEyecatch(params, {}, dynamodb=self.dynamodb).main() self.assertEqual(response['statusCode'], 200) expected = [] self.assertEqual(json.loads(response['body'])['Items'], expected) table.put_item(Item={ 'article_type': 'eyecatch', 'articles': { 'not_exists': ['testid000001', 'testid000002', 'testid000003'] } }) response = ArticlesEyecatch(params, {}, dynamodb=self.dynamodb).main() self.assertEqual(response['statusCode'], 200) expected = [] self.assertEqual(json.loads(response['body'])['Items'], expected)
def test_main_ok_with_empty_article(self): table = self.dynamodb.Table(os.environ['SCREENED_ARTICLE_TABLE_NAME']) table.delete_item(Key={'article_type': 'eyecatch'}) response = ArticlesEyecatch({}, {}, dynamodb=self.dynamodb).main() self.assertEqual(response['statusCode'], 200) expected = [None, None, None] self.assertEqual(json.loads(response['body'])['Items'], expected) table.put_item(Item={'article_type': 'eyecatch', 'articles': []}) response = ArticlesEyecatch({}, {}, dynamodb=self.dynamodb).main() self.assertEqual(response['statusCode'], 200) expected = [None, None, None] self.assertEqual(json.loads(response['body'])['Items'], expected)
def test_main_ok(self): params = { 'queryStringParameters': { 'topic': 'test_topic' } } response = ArticlesEyecatch(params, {}, dynamodb=self.dynamodb).main() self.assertEqual(response['statusCode'], 200) expected = [self.article_info_items[0], self.article_info_items[1], self.article_info_items[2]] self.assertEqual(json.loads(response['body'])['Items'], expected)
def test_main_ok_with_none_response(self): table = self.dynamodb.Table(os.environ['SCREENED_ARTICLE_TABLE_NAME']) table.put_item( Item={ 'article_type': 'eyecatch', 'articles': ['testid000004', 'testid000005', 'testid000003'] }) response = ArticlesEyecatch({}, {}, dynamodb=self.dynamodb).main() self.assertEqual(response['statusCode'], 200) expected = [None, None, self.article_info_items[2]] self.assertEqual(json.loads(response['body'])['Items'], expected)
def lambda_handler(event, context): articles_eyecatch = ArticlesEyecatch(event, context, dynamodb=dynamodb) return articles_eyecatch.main()