-
Notifications
You must be signed in to change notification settings - Fork 1
π¨ Palette: Smart Profile ID Extraction from URLs #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -247,6 +247,21 @@ | |||||
|
|
||||||
| return True | ||||||
|
|
||||||
| def extract_profile_id(text: str) -> str: | ||||||
| """ | ||||||
| Extracts the Profile ID from a Control D URL if present, | ||||||
| otherwise returns the text as-is (cleaned). | ||||||
| """ | ||||||
| if not text: | ||||||
| return "" | ||||||
| text = text.strip() | ||||||
| # Pattern for Control D Dashboard URLs | ||||||
| # e.g. https://controld.com/dashboard/profiles/12345abc/filters | ||||||
| match = re.search(r"controld\.com/dashboard/profiles/([^/?#\s]+)", text) | ||||||
|
||||||
| match = re.search(r"controld\.com/dashboard/profiles/([^/?#\s]+)", text) | |
| match = re.search(r"controld\.com/dashboard/profiles/([^/?#\s]+)", text, re.IGNORECASE) |
Check warning
Code scanning / Pylint (reported by Codacy)
Line too long (146/100) Warning
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Line too long (146/100) Warning
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -319,3 +319,62 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert m.check_api_access(mock_client, "profile") is False | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert mock_log.error.called | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert "Network failure" in str(mock_log.error.call_args) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Case 8: extract_profile_id correctly extracts ID from URL or returns input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_extract_profile_id(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / Pylint (reported by Codacy) Missing function docstring Warning test
Missing function docstring
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Regular ID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert main.extract_profile_id("12345") == "12345" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # URL with /filters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert main.extract_profile_id("https://controld.com/dashboard/profiles/12345/filters") == "12345" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check warningCode scanning / Pylint (reported by Codacy) Line too long (102/100) Warning test
Line too long (102/100)
Check warningCode scanning / Pylintpython3 (reported by Codacy) Line too long (102/100) Warning test
Line too long (102/100)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # URL without /filters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert main.extract_profile_id("https://controld.com/dashboard/profiles/12345") == "12345" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # URL with params | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert main.extract_profile_id("https://controld.com/dashboard/profiles/12345?foo=bar") == "12345" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check warningCode scanning / Pylint (reported by Codacy) Line too long (102/100) Warning test
Line too long (102/100)
Check warningCode scanning / Pylintpython3 (reported by Codacy) Line too long (102/100) Warning test
Line too long (102/100)
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Clean up whitespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert main.extract_profile_id(" 12345 ") == "12345" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Invalid input returns as is (cleaned) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert main.extract_profile_id("random-string") == "random-string" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Empty input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert main.extract_profile_id("") == "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert main.extract_profile_id(None) == "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Comment on lines
+324
to
+339
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test function contains multiple
Suggested change
Comment on lines
+324
to
+339
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Case 9: Interactive input handles URL pasting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_interactive_input_extracts_id(monkeypatch, capsys): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / Pylint (reported by Codacy) Missing function docstring Warning test
Missing function docstring
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Ensure environment is clean | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| monkeypatch.delenv("PROFILE", raising=False) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| monkeypatch.delenv("TOKEN", raising=False) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Reload main with isatty=True | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m = reload_main_with_env(monkeypatch, isatty=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / Pylint (reported by Codacy) Variable name "m" doesn't conform to snake_case naming style Warning test
Variable name "m" doesn't conform to snake_case naming style
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| monkeypatch.setattr('sys.stdin.isatty', lambda: True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Provide URL as input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| url_input = "https://controld.com/dashboard/profiles/extracted_id/filters" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| monkeypatch.setattr('builtins.input', lambda prompt="": url_input) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| monkeypatch.setattr('getpass.getpass', lambda prompt="": "test_token") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Mock parse_args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mock_args = MagicMock() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mock_args.profiles = None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mock_args.folder_url = None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mock_args.dry_run = False | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mock_args.no_delete = False | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mock_args.plan_json = None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| monkeypatch.setattr(m, "parse_args", lambda: mock_args) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Mock sync_profile to catch the call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mock_sync = MagicMock(return_value=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| monkeypatch.setattr(m, "sync_profile", mock_sync) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| monkeypatch.setattr(m, "warm_up_cache", MagicMock()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Run main, expect clean exit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with pytest.raises(SystemExit): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m.main() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Verify sync_profile called with extracted ID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| args, _ = mock_sync.call_args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert args[0] == "extracted_id" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Verify prompt text update | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| captured = capsys.readouterr() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert "(or just paste the URL)" in captured.out | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type hint for
textisstr, but the function logic and tests handleNoneas a valid input. To make the function signature more accurate and prevent potential type checker issues, it's better to useOptional[str]. You'll need to ensurefrom typing import Optionalis present.