test_cli.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. # Remove log lines
  22. lines = [
  23. l for l in result.output.split('\n')[:-1] if "twhatter" not in l
  24. ]
  25. assert len(lines) == 100
  26. for l in lines:
  27. assert "Tweet" in l
  28. @pytest.mark.send_request
  29. def test_timeline_limit(self, cli_runner, user_prolific, tweet_limit):
  30. result = cli_runner.invoke(
  31. cli.main,
  32. ['timeline', user_prolific, '--limit', tweet_limit]
  33. )
  34. assert result.exit_code == 0
  35. # Remove log lines
  36. lines = [
  37. l for l in result.output.split('\n')[:-1] if "twhatter" not in l
  38. ]
  39. assert len(lines) == tweet_limit
  40. @pytest.mark.send_request
  41. def test_profile(self, cli_runner, user_prolific, tweet_limit):
  42. result = cli_runner.invoke(
  43. cli.main,
  44. ['profile', user_prolific]
  45. )
  46. assert result.exit_code == 0
  47. class TestDb:
  48. @pytest.mark.send_request
  49. def test_timeline_no_limit(self, cli_runner, user_prolific):
  50. result = cli_runner.invoke(
  51. cli.main,
  52. ['db', 'timeline', user_prolific]
  53. )
  54. assert result.exit_code == 0
  55. @pytest.mark.send_request
  56. def test_timeline_limit(self, cli_runner, user_prolific, tweet_limit):
  57. result = cli_runner.invoke(
  58. cli.main,
  59. ['db', 'timeline', user_prolific, '--limit', tweet_limit]
  60. )
  61. assert result.exit_code == 0