test_cli.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. @pytest.mark.send_request
  35. def test_profile(self, cli_runner, user_prolific, tweet_limit):
  36. result = cli_runner.invoke(
  37. cli.main,
  38. ['profile', user_prolific]
  39. )
  40. assert result.exit_code == 0
  41. class TestDb:
  42. @pytest.mark.send_request
  43. def test_timeline_no_limit(self, cli_runner, user_prolific):
  44. result = cli_runner.invoke(
  45. cli.main,
  46. ['db', 'timeline', user_prolific]
  47. )
  48. assert result.exit_code == 0
  49. @pytest.mark.send_request
  50. def test_timeline_limit(self, cli_runner, user_prolific, tweet_limit):
  51. result = cli_runner.invoke(
  52. cli.main,
  53. ['db', 'timeline', user_prolific, '--limit', tweet_limit]
  54. )
  55. assert result.exit_code == 0