|
| 1 | +# coding=utf-8 |
| 2 | +import sys |
| 3 | +import unittest |
| 4 | +from unittest.mock import patch |
| 5 | + |
| 6 | +sys.path.insert(0, "../../src") |
| 7 | + |
| 8 | +from kaggle.api.kaggle_api_extended import KaggleApi |
| 9 | + |
| 10 | + |
| 11 | +class TestHelpOrVersionAuth(unittest.TestCase): |
| 12 | + """Tests for help/version detection used during authenticate().""" |
| 13 | + |
| 14 | + def setUp(self): |
| 15 | + self.api = KaggleApi.__new__(KaggleApi) |
| 16 | + |
| 17 | + def _assert_help_or_version(self, argv, expected): |
| 18 | + with patch.object(sys, "argv", argv): |
| 19 | + api_command = " ".join(argv[1:]) |
| 20 | + self.assertEqual(self.api._is_help_or_version_command(api_command), expected) |
| 21 | + |
| 22 | + def test_top_level_version_and_help(self): |
| 23 | + self._assert_help_or_version(["kaggle", "-v"], True) |
| 24 | + self._assert_help_or_version(["kaggle", "--version"], True) |
| 25 | + self._assert_help_or_version(["kaggle", "-h"], True) |
| 26 | + self._assert_help_or_version(["kaggle", "--help"], True) |
| 27 | + |
| 28 | + def test_subcommand_csv_flag_is_not_version(self): |
| 29 | + self._assert_help_or_version(["kaggle", "quota", "-v"], False) |
| 30 | + self._assert_help_or_version(["kaggle", "datasets", "list", "-v"], False) |
| 31 | + |
| 32 | + def test_subcommand_help_still_skips_auth(self): |
| 33 | + self._assert_help_or_version(["kaggle", "quota", "-h"], True) |
| 34 | + self._assert_help_or_version(["kaggle", "datasets", "list", "--help"], True) |
| 35 | + |
| 36 | + def test_quota_csv_flag_does_not_allow_logged_out(self): |
| 37 | + with patch.object(sys, "argv", ["kaggle", "quota", "-v"]): |
| 38 | + self.assertFalse(self.api._command_allows_logged_out("quota -v")) |
| 39 | + |
| 40 | + |
| 41 | +if __name__ == "__main__": |
| 42 | + unittest.main() |
0 commit comments