test_cli.py 2.3 KB

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