-
Notifications
You must be signed in to change notification settings - Fork 3
Add integration tests #52
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
aa8677f
test: add integration tests
ninoseki 2ba399f
fix: fix saved search issue
ninoseki 7ddb7ea
refactor: move unit tests under unit/
ninoseki 3123010
docs: update test section
ninoseki a2c59a2
fix: remove markers
ninoseki 1ad7d75
fix: don't use UTC from datetime
ninoseki 88b9657
Merge branch 'main' into integration
ninoseki c9923df
Update docs/dev.md
ninoseki b53ef3f
Update docs/dev.md
ninoseki 8aece29
docs: add <root> prefix
ninoseki 590a89e
refactor: use httpbin.org
ninoseki 4401398
refactor: add more strict assertions
ninoseki 9db1d1b
Merge branch 'main' into integration
ninoseki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [pytest] | ||
| optional_tests= | ||
| integration: tests requiring real API access (require URLSCAN_API_KEY env variable) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import os | ||
|
|
||
| import pytest | ||
| from dotenv import load_dotenv | ||
|
|
||
| from urlscan import Client, Pro | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def api_key() -> str: | ||
| load_dotenv() | ||
| key = os.getenv("URLSCAN_API_KEY") | ||
| assert key | ||
| return key | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def client(api_key: str): | ||
| with Client(api_key) as client: | ||
| yield client | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def pro(api_key: str): | ||
| with Pro(api_key) as client: | ||
| yield client | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def url() -> str: | ||
| return "https://httpbin.org/html" |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import pytest | ||
|
|
||
| from urlscan import Pro | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_get_available_brands(pro: Pro): | ||
| brands = pro.brand.get_available_brands() | ||
| assert isinstance(brands, dict) | ||
| assert "kits" in brands | ||
| assert len(brands["kits"]) > 0 | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_get_brands(pro: Pro): | ||
| brands = pro.brand.get_brands() | ||
| assert isinstance(brands, dict) | ||
fw42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert "responses" in brands | ||
| assert len(brands["responses"]) > 0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import os | ||
|
|
||
| import pytest | ||
|
|
||
| from urlscan import Pro | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def channel_id() -> str: | ||
| """Get channel ID from environment variable. | ||
|
|
||
| Set CHANNEL_ID environment variable to test channel operations. | ||
| """ | ||
| channel_id = os.getenv("CHANNEL_ID") | ||
| if not channel_id: | ||
| pytest.skip("CHANNEL_ID environment variable not set") | ||
|
|
||
| return channel_id | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_get_channels(pro: Pro): | ||
| channels = pro.channel.get_channels() | ||
| assert isinstance(channels, dict) | ||
| assert "channels" in channels | ||
| assert len(channels["channels"]) > 0 | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_get_channel(pro: Pro, channel_id: str): | ||
| channel = pro.channel.get(channel_id) | ||
| assert channel is not None | ||
| assert "channel" in channel | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_update_channel(pro: Pro, channel_id: str): | ||
| # Get the current channel details | ||
| channel = pro.channel.get(channel_id) | ||
| original_name = channel["channel"]["name"] | ||
| channel_type = channel["channel"]["type"] | ||
|
|
||
| try: | ||
| # Update the channel name | ||
| updated = pro.channel.update( | ||
| channel_id, channel_type=channel_type, name="integration-test" | ||
| ) | ||
| assert updated is not None | ||
|
|
||
| # Verify the update | ||
| retrieved = pro.channel.get(channel_id) | ||
| assert retrieved["channel"]["name"] == "integration-test" | ||
|
|
||
| finally: | ||
| # Revert the change | ||
| pro.channel.update(channel_id, channel_type=channel_type, name=original_name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import datetime | ||
|
|
||
| import pytest | ||
|
|
||
| from urlscan import Pro | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def today() -> str: | ||
| return datetime.datetime.now(tz=datetime.timezone.utc).strftime("%Y%m%d") | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_datadump_list(pro: Pro, today: str): | ||
| result = pro.datadump.get_list(f"hours/api/{today}") | ||
| assert isinstance(result, dict) | ||
| assert "files" in result | ||
| assert len(result["files"]) > 0 | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_datadump_download(pro: Pro, today: str, tmp_path): | ||
| # Download a file from the hours/search path | ||
| output_path = tmp_path / f"{today}.gz" | ||
| with open(output_path, "wb") as f: | ||
| pro.datadump.download_file( | ||
| f"hours/search/{today}/{today}-00.gz", | ||
| file=f, | ||
| ) | ||
| assert output_path.exists() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import pytest | ||
|
|
||
| from urlscan import Pro | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_hostname_with_limit(pro: Pro): | ||
| it = pro.hostname("example.com", limit=1) | ||
| results = list(it) | ||
| assert len(results) == 1 | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_hostname_with_limit_and_size(pro: Pro): | ||
| it = pro.hostname("example.com", limit=10, size=10) | ||
| results = list(it) | ||
| assert len(results) == 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import pytest | ||
|
|
||
| from urlscan import Pro | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_get_scanners(pro: Pro): | ||
| scanners = pro.livescan.get_scanners() | ||
| assert isinstance(scanners, dict) | ||
| assert "scanners" in scanners | ||
cdnsyseng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert len(scanners["scanners"]) > 0 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def scanner_id() -> str: | ||
| return "us01" | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_scan_get_result_dom_and_purge(pro: Pro, url: str, scanner_id: str): | ||
| # Scan a URL | ||
| result = pro.livescan.scan(url, scanner_id=scanner_id) | ||
| uuid = result["uuid"] | ||
|
|
||
| # Get the result | ||
| scan_result = pro.livescan.get_resource( | ||
| scanner_id=scanner_id, resource_type="result", resource_id=uuid | ||
| ) | ||
| assert scan_result is not None | ||
|
|
||
| # Get the DOM | ||
| dom = pro.livescan.get_resource( | ||
| scanner_id=scanner_id, resource_type="dom", resource_id=uuid | ||
| ) | ||
| assert dom is not None | ||
cdnsyseng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Purge the scan | ||
| purge_result = pro.livescan.purge(scanner_id=scanner_id, scan_id=uuid) | ||
| assert purge_result is not None | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import pytest | ||
|
|
||
| from urlscan import Pro | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_saved_search_crud(pro: Pro): | ||
| # Create a saved search | ||
| created = pro.saved_search.create( | ||
| datasource="scans", | ||
| query="page.domain:example.com", | ||
| name="integration-test", | ||
| ) | ||
| search_id = created["search"]["_id"] | ||
|
|
||
| try: | ||
| # Get the saved search results | ||
| results = pro.saved_search.get_results(search_id) | ||
| assert results is not None | ||
|
|
||
| # Update the saved search | ||
| updated = pro.saved_search.update( | ||
| search_id, | ||
| datasource="scans", | ||
| query="page.domain:example.net", | ||
| name="integration-test-updated", | ||
| ) | ||
| assert updated is not None | ||
|
|
||
| finally: | ||
| # Delete the saved search | ||
| pro.saved_search.remove(search_id) | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_saved_search_list(pro: Pro): | ||
| result = pro.saved_search.get_list() | ||
| assert isinstance(result, dict) | ||
| assert "searches" in result | ||
| assert len(result["searches"]) > 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import pytest | ||
|
|
||
| from urlscan import Pro | ||
|
|
||
| # Reference UUID from urlscan.io documentation | ||
| # https://docs.urlscan.io/apis/urlscan-openapi/search/similarsearch | ||
| REFERENCE_UUID = "68e26c59-2eae-437b-aeb1-cf750fafe7d7" | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_structure_search(pro: Pro): | ||
| it = pro.structure_search(REFERENCE_UUID, size=10, limit=10) | ||
| results = list(it) | ||
| assert len(results) >= 1 | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_structure_search_with_query(pro: Pro): | ||
| it = pro.structure_search(REFERENCE_UUID, q="page.domain:*", size=10, limit=10) | ||
| results = list(it) | ||
| assert len(results) >= 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import pytest | ||
|
|
||
| from urlscan import Pro | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_subscription_crud(pro: Pro): | ||
| # First, create a saved search to use for the subscription | ||
| search_result = pro.saved_search.create( | ||
| datasource="scans", | ||
| query="page.domain:example.com", | ||
| name="integration-test-subscription", | ||
| ) | ||
| search_id = search_result["search"]["_id"] | ||
|
|
||
| try: | ||
| # Create a subscription | ||
| created = pro.subscription.create( | ||
| search_ids=[search_id], | ||
| frequency="daily", | ||
| name="integration-test", | ||
| email_addresses=["test@example.com"], | ||
| is_active=True, | ||
| ignore_time=False, | ||
| ) | ||
| subscription_id = created["subscription"]["_id"] | ||
|
|
||
| try: | ||
| # Update the subscription | ||
| updated = pro.subscription.update( | ||
| subscription_id=subscription_id, | ||
| search_ids=[search_id], | ||
| frequency="hourly", | ||
| name="integration-test-updated", | ||
| email_addresses=["test@example.com"], | ||
| is_active=True, | ||
| ignore_time=False, | ||
| ) | ||
| assert updated is not None | ||
|
|
||
| finally: | ||
| # Delete the subscription | ||
| pro.subscription.delete_subscription(subscription_id=subscription_id) | ||
|
|
||
| finally: | ||
| # Clean up the saved search | ||
| pro.saved_search.remove(search_id) | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_subscription_list(pro: Pro): | ||
| result = pro.subscription.get_subscriptions() | ||
| assert isinstance(result, dict) | ||
| assert "subscriptions" in result | ||
| assert len(result["subscriptions"]) > 0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.