Skip to content

Commit

Permalink
catch pep8 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jahwag committed Jul 23, 2024
1 parent c874870 commit 2df4354
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 . --count --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
1 change: 0 additions & 1 deletion src/claudesync/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from .organization import organization
from .project import project
from .sync import ls, sync, schedule
from .api import ratelimit, max_filesize

click_completion.init()

Expand Down
80 changes: 44 additions & 36 deletions tests/cli/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,86 +12,94 @@ def setUp(self):
self.mock_config = MagicMock()
self.mock_provider = MagicMock()

@patch('claudesync.cli.api.get_provider')
@patch('claudesync.cli.main.ConfigManager')
@patch("claudesync.cli.api.get_provider")
@patch("claudesync.cli.main.ConfigManager")
def test_login_success(self, mock_config_manager, mock_get_provider):
mock_config_manager.return_value = self.mock_config
mock_get_provider.return_value = self.mock_provider
mock_get_provider.side_effect = lambda x=None: ['claude.ai'] if x is None else self.mock_provider
self.mock_provider.login.return_value = 'test_session_key'
mock_get_provider.side_effect = lambda x=None: (
["claude.ai"] if x is None else self.mock_provider
)
self.mock_provider.login.return_value = "test_session_key"

result = self.runner.invoke(cli, ['api', 'login', 'claude.ai'])
result = self.runner.invoke(cli, ["api", "login", "claude.ai"])

self.assertEqual(result.exit_code, 0)
self.assertIn('Logged in successfully.', result.output)
self.mock_config.set.assert_any_call('session_key', 'test_session_key')
self.mock_config.set.assert_any_call('active_provider', 'claude.ai')
self.assertIn("Logged in successfully.", result.output)
self.mock_config.set.assert_any_call("session_key", "test_session_key")
self.mock_config.set.assert_any_call("active_provider", "claude.ai")

@patch('claudesync.cli.api.get_provider')
@patch('claudesync.cli.main.ConfigManager')
@patch("claudesync.cli.api.get_provider")
@patch("claudesync.cli.main.ConfigManager")
def test_login_provider_error(self, mock_config_manager, mock_get_provider):
mock_config_manager.return_value = self.mock_config
mock_get_provider.return_value = self.mock_provider
mock_get_provider.side_effect = lambda x=None: ['claude.ai'] if x is None else self.mock_provider
self.mock_provider.login.side_effect = ProviderError('Login failed')
mock_get_provider.side_effect = lambda x=None: (
["claude.ai"] if x is None else self.mock_provider
)
self.mock_provider.login.side_effect = ProviderError("Login failed")

result = self.runner.invoke(cli, ['api', 'login', 'claude.ai'])
result = self.runner.invoke(cli, ["api", "login", "claude.ai"])

self.assertEqual(result.exit_code, 0)
self.assertIn('Error: Login failed', result.output)
self.assertIn("Error: Login failed", result.output)

@patch('claudesync.cli.main.ConfigManager')
@patch("claudesync.cli.main.ConfigManager")
def test_logout(self, mock_config_manager):
mock_config_manager.return_value = self.mock_config

result = self.runner.invoke(cli, ['api', 'logout'])
result = self.runner.invoke(cli, ["api", "logout"])

self.assertEqual(result.exit_code, 0)
self.assertIn('Logged out successfully.', result.output)
self.mock_config.set.assert_any_call('session_key', None)
self.mock_config.set.assert_any_call('active_provider', None)
self.mock_config.set.assert_any_call('active_organization_id', None)
self.assertIn("Logged out successfully.", result.output)
self.mock_config.set.assert_any_call("session_key", None)
self.mock_config.set.assert_any_call("active_provider", None)
self.mock_config.set.assert_any_call("active_organization_id", None)

@patch('claudesync.cli.main.ConfigManager')
@patch("claudesync.cli.main.ConfigManager")
def test_ratelimit_set(self, mock_config_manager):
mock_config_manager.return_value = self.mock_config

result = self.runner.invoke(cli, ['api', 'ratelimit', '--delay', '1.5'])
result = self.runner.invoke(cli, ["api", "ratelimit", "--delay", "1.5"])

self.assertEqual(result.exit_code, 0)
self.assertIn('Upload delay set to 1.5 seconds.', result.output)
self.mock_config.set.assert_called_once_with('upload_delay', 1.5)
self.assertIn("Upload delay set to 1.5 seconds.", result.output)
self.mock_config.set.assert_called_once_with("upload_delay", 1.5)

@patch('claudesync.cli.main.ConfigManager')
@patch("claudesync.cli.main.ConfigManager")
def test_ratelimit_negative_value(self, mock_config_manager):
mock_config_manager.return_value = self.mock_config

result = self.runner.invoke(cli, ['api', 'ratelimit', '--delay', '-1'])
result = self.runner.invoke(cli, ["api", "ratelimit", "--delay", "-1"])

self.assertEqual(result.exit_code, 0)
self.assertIn('Error: Upload delay must be a non-negative number.', result.output)
self.assertIn(
"Error: Upload delay must be a non-negative number.", result.output
)
self.mock_config.set.assert_not_called()

@patch('claudesync.cli.main.ConfigManager')
@patch("claudesync.cli.main.ConfigManager")
def test_max_filesize_set(self, mock_config_manager):
mock_config_manager.return_value = self.mock_config

result = self.runner.invoke(cli, ['api', 'max-filesize', '--size', '1048576'])
result = self.runner.invoke(cli, ["api", "max-filesize", "--size", "1048576"])

self.assertEqual(result.exit_code, 0)
self.assertIn('Maximum file size set to 1048576 bytes.', result.output)
self.mock_config.set.assert_called_once_with('max_file_size', 1048576)
self.assertIn("Maximum file size set to 1048576 bytes.", result.output)
self.mock_config.set.assert_called_once_with("max_file_size", 1048576)

@patch('claudesync.cli.main.ConfigManager')
@patch("claudesync.cli.main.ConfigManager")
def test_max_filesize_negative_value(self, mock_config_manager):
mock_config_manager.return_value = self.mock_config

result = self.runner.invoke(cli, ['api', 'max-filesize', '--size', '-1'])
result = self.runner.invoke(cli, ["api", "max-filesize", "--size", "-1"])

self.assertEqual(result.exit_code, 0)
self.assertIn('Error: Maximum file size must be a non-negative number.', result.output)
self.assertIn(
"Error: Maximum file size must be a non-negative number.", result.output
)
self.mock_config.set.assert_not_called()


if __name__ == '__main__':
unittest.main()
if __name__ == "__main__":
unittest.main()

0 comments on commit 2df4354

Please sign in to comment.