async def test_when_fetch_fails_bad_repo(self, loop): handler = WordPressRepository(loop=loop, storage=MagicMock(), repository_checker=MagicMock()) handler.current_plugins = lambda: {'hello-world', 'unknown-plugin'} handler.enumerate_plugins = lambda: fake_future( {'hello-world', 'a', 'b'}, loop) handler.fetch_plugin = MagicMock() handler.fetch_plugin.side_effect = PluginNotFound('A side effect!') handler.checker.has_content.return_value = fake_future(False, loop) await handler.perform_plugin_lookup() handler.fetch_plugin.assert_has_calls([ call('a'), call('b'), ], any_order=True) handler.storage.write_meta.assert_not_called() handler.checker.has_content.assert_has_calls([ call( Repository(type="subversion", location="https://plugins.svn.wordpress.org/a/")), call( Repository(type="subversion", location="https://plugins.svn.wordpress.org/b/")), ], any_order=True) handler.storage.append.assert_has_calls([ call("plugins-ignore.txt", "a"), call("plugins-ignore.txt", "b"), ], any_order=True)
async def test_no_calls_made_when_nothing_new(self, loop): handler = WordPressRepository(loop=loop) handler.current_plugins = lambda: {'hello-world', 'unknown-plugin'} handler.enumerate_plugins = lambda: fake_future({'hello-world'}, loop) handler.fetch_plugin = MagicMock() handler.fetch_plugin.assert_not_called() await handler.perform_plugin_lookup()
async def test_read_path_empty(self, loop): handler = WordPressRepository(loop=loop, storage=MagicMock()) handler.storage.list_directories.return_value = set() handler.storage.read_lines.return_value = [] self.assertEqual(handler.current_plugins(), set()) handler.storage.list_directories.assert_called_with('plugins') handler.storage.read_lines.assert_called_with('plugins-ignore.txt')
async def test_calls_made_when_new_plugins_arrive(self, loop): handler = WordPressRepository(loop=loop, storage=MagicMock()) handler.current_plugins = lambda: {'hello-world', 'unknown-plugin'} handler.enumerate_plugins = lambda: fake_future({'hello-world', 'a', 'b'}, loop) handler.fetch_plugin = MagicMock() handler.fetch_plugin.return_value = fake_future(Meta(key="a", name="A"), loop) await handler.perform_plugin_lookup() handler.fetch_plugin.assert_has_calls([ call('a'), call('b'), ], any_order=True) handler.storage.write_meta.assert_called_with(Meta(key="a", name="A"))
async def test_read_path_with_data(self, loop): handler = WordPressRepository(loop=loop, storage=MagicMock()) handler.storage.list_directories.return_value = {"wordpress_test"} handler.storage.read_lines.return_value = [] self.assertIn("wordpress_test", handler.current_plugins()) handler.storage.list_directories.assert_called_with('plugins')