async def test_flag_as_popular_from_api(self, loop): meta_1 = Meta(key="some-meta-1") meta_2 = Meta(key="some-meta-2") meta_3 = Meta(key="some-meta-3") my_response = ClientResponse('GET', URL('http://api.wordpress.org/plugins/info/1.1/?action=query_plugins' '&request[browse]=popular&request[per_page]=200')) my_response.status = 200 my_response.headers = {'Content-Type': 'application/json'} my_response._body = read_file(__file__, 'popular-plugins.json').encode('utf8') aiohttp_session = ClientSessionMock(get_response=my_response) handler = WordPressRepository(loop=loop, aiohttp_session=aiohttp_session, storage=MagicMock()) handler.storage.read_meta.side_effect = [meta_1, meta_2, meta_3] await handler.mark_popular_plugins() handler.session.get.assert_called_with('http://api.wordpress.org/plugins/info/1.1/?action=query_plugins' '&request[browse]=popular&request[per_page]=200') handler.storage.write_meta.assert_has_calls([ call(meta_1), call(meta_2), ]) handler.storage.read_meta.assert_has_calls([ call("plugins/woocommerce"), call("plugins/google-sitemap-generator"), ], any_order=True) self.assertTrue(meta_1.is_popular) self.assertTrue(meta_2.is_popular) self.assertIsNone(meta_3.is_popular)
async def test_fetch_plugin_data(self, loop): my_response = ClientResponse('GET', URL('https://api.wordpress.org/plugins/info/1.0/better-wp-security.json')) my_response.status = 200 my_response.headers = {'Content-Type': 'application/json'} my_response._body = read_file(__file__, 'better-wp-security.json').encode('utf8') aiohttp_session = ClientSessionMock(get_response=my_response) handler = WordPressRepository(loop=loop, aiohttp_session=aiohttp_session) plugin = await handler.fetch_plugin('better-wp-security') handler.session.get.assert_called_with('https://api.wordpress.org/plugins/info/1.0/better-wp-security.json') self.assertEqual('plugins/better-wp-security', plugin.key)
async def test_fetch_theme_data(self, loop): my_response = ClientResponse( 'GET', URL('https://api.wordpress.org/themes/info/1.1/?action=theme_information&request[slug]=twentyeleven' )) # noqa my_response.status = 200 my_response._headers = {'Content-Type': 'application/json'} my_response._body = read_file(__file__, 'twentyeleven.json').encode('utf8') aiohttp_session = ClientSessionMock(get_response=my_response) handler = WordPressRepository(loop=loop, aiohttp_session=aiohttp_session) theme = await handler.fetch_theme('twentyeleven') handler.session.get.assert_called_with( 'https://api.wordpress.org/themes/info/1.1/?action=theme_information&request[slug]=twentyeleven' ) # noqa self.assertEqual('themes/twentyeleven', theme.key) self.assertEqual('Twenty Eleven', theme.name)