test_cli.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3. """Tests for `twhatter` package."""
  4. import pytest
  5. from twhatter import cli
  6. def test_command_line_interface(cli_runner):
  7. """Test the CLI."""
  8. result = cli_runner.invoke(cli.main)
  9. assert result.exit_code == 0
  10. help_result = cli_runner.invoke(cli.main, ['--help'])
  11. assert help_result.exit_code == 0
  12. assert 'Show this message and exit.' in help_result.output
  13. class TestMain:
  14. @pytest.mark.send_request
  15. def test_timeline_no_limit(self, cli_runner, user_prolific):
  16. result = cli_runner.invoke(
  17. cli.main,
  18. ['timeline', user_prolific]
  19. )
  20. assert result.exit_code == 0
  21. lines = result.output.split('\n')[:-1]
  22. assert len(lines) == 100
  23. for l in lines:
  24. assert "Tweet" in l
  25. @pytest.mark.send_request
  26. def test_timeline_limit(self, cli_runner, user_prolific, tweet_limit):
  27. result = cli_runner.invoke(
  28. cli.main,
  29. ['timeline', user_prolific, '--limit', tweet_limit]
  30. )
  31. assert result.exit_code == 0
  32. lines = result.output.split('\n')[:-1]
  33. assert len(lines) == tweet_limit
  34. class TestDb:
  35. @pytest.mark.send_request
  36. def test_timeline_no_limit(self, cli_runner, user_prolific):
  37. result = cli_runner.invoke(
  38. cli.main,
  39. ['db', 'timeline', user_prolific]
  40. )
  41. assert result.exit_code == 0
  42. @pytest.mark.send_request
  43. def test_timeline_limit(self, cli_runner, user_prolific, tweet_limit):
  44. result = cli_runner.invoke(
  45. cli.main,
  46. ['db', 'timeline', user_prolific, '--limit', tweet_limit]
  47. )
  48. assert result.exit_code == 0