test_plugins.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import click
  2. import zipfile,urllib,os
  3. from click.testing import CliRunner
  4. from flaskbb.cli import main as cli_main
  5. def test_new_plugin(tmpdir,application,monkeypatch):
  6. runner=CliRunner()
  7. zipfilename=str(tmpdir.join('cookiecutter.zip'))
  8. monkeypatch.setattr(cli_main,'create_app',lambda s: application)
  9. urllib.urlretrieve('https://github.com/sh4nks/cookiecutter-flaskbb-plugin/archive/master.zip',zipfilename)
  10. with zipfile.ZipFile(zipfilename) as zf:
  11. zf.extractall(str(tmpdir))
  12. cookiecutterpath=tmpdir.join('cookiecutter-flaskbb-plugin-master')
  13. input='\n'.join([
  14. 'Test Name',
  15. 'someone@nowhere.com',
  16. 'Testing Plugin',
  17. '',
  18. '',
  19. 'Straightforward Test Plugin',
  20. 'www.example.com',
  21. '1.0.0'])
  22. result=runner.invoke(cli_main.flaskbb,['plugins','new','testplugin','--template',str(cookiecutterpath)],input=input)
  23. assert result.exit_code == 0
  24. plugin_dir = os.join(application.extensions['plugin_manager'].plugin_folder, 'testing_plugin')
  25. assert os.path.exists(plugin_dir)
  26. assert os.path.isdir(plugin_dir)
  27. assert __import__('flaskbb.plugins.testing_plugin').__plugin__=='TestingPlugin'