Skip to content

Commit

Permalink
tests: add a few vcr marks
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed May 14, 2024
1 parent 6f7f12c commit a9c76c0
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added

- **pytest-recording** and vcr marks to a couple tests ([#166](https://github.com/stac-utils/stac-asset/pull/166))

## [0.3.1] - 2024-05-13

### Added
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ pre-commit install

### Testing

All network-touching tests are disabled by default, because we can't use [pytest-vcr](https://pytest-vcr.readthedocs.io/en/latest/) (<https://github.com/kevin1024/vcrpy/issues/597>), and repeatedly hitting the network during testing and CI is bad behavior.
To enable network-touching tests:
Some network-touching tests are disabled by default.
To enable these tests:

```shell
pytest --network-access
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dev = [
"pytest~=7.3",
"pytest-asyncio~=0.21",
"pytest-cov>=5.0",
"pytest-recording~=0.13.1",
"ruff==0.4.4",
"types-aiofiles~=23.1",
"types-python-dateutil~=2.9",
Expand Down
83 changes: 83 additions & 0 deletions tests/cassettes/test_http_client/test_href_exists.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
interactions:
- request:
body: null
headers: {}
method: HEAD
uri: https://github.com/stac-utils/stac-asset
response:
body:
string: ''
headers:
Accept-Ranges:
- bytes
Cache-Control:
- max-age=0, private, must-revalidate
Content-Encoding:
- gzip
Content-Security-Policy:
- 'default-src ''none''; base-uri ''self''; child-src github.com/assets-cdn/worker/
gist.github.com/assets-cdn/worker/; connect-src ''self'' uploads.github.com
www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com
github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com
github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com
api.githubcopilot.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com/v1/engines/copilot-codex/completions
*.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/
productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/
productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/
productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/
productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/
productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/
productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/
productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/
productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/
productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/
productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com
github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com
wss://alive.github.com; font-src github.githubassets.com; form-action ''self''
github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com;
frame-ancestors ''none''; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com;
img-src ''self'' data: github.githubassets.com media.githubusercontent.com
camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com
github-cloud.s3.amazonaws.com objects.githubusercontent.com secured-user-images.githubusercontent.com/
user-images.githubusercontent.com/ private-user-images.githubusercontent.com
opengraph.githubassets.com github-production-user-asset-6210df.s3.amazonaws.com
customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com
*.githubusercontent.com; manifest-src ''self''; media-src github.com user-images.githubusercontent.com/
secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com
github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src
github.githubassets.com; style-src ''unsafe-inline'' github.githubassets.com;
upgrade-insecure-requests; worker-src github.com/assets-cdn/worker/ gist.github.com/assets-cdn/worker/'
Content-Type:
- text/html; charset=utf-8
Date:
- Tue, 14 May 2024 18:04:45 GMT
Etag:
- W/"043b7d592713d70fc59a8c9f211afcd4"
Referrer-Policy:
- no-referrer-when-downgrade
Server:
- GitHub.com
Set-Cookie:
- _gh_sess=KP%2FY3PwFbLe4kWRGWrH%2Bal33IF3dhHZiVemE6owpJSTr%2FPsnGM9OpLURbODYFzLZDGGciBkDjT9nwNb%2BDANM7KONgWofB2YIDSr%2FXb5SyO4%2BEPD65JxAgcy4%2F1Czp9Kbvm1T45M3QDi3haDZi9AdlHSMThW4CvCSIxB1IUMrj1QXi9OgWHM5NDFtG8Fock53HJtAkxsvv93dNysUZrQfF4VWy9IFvB96c1nT2s4i7APtg0sStYjKqpZ895yp%2Ba0yjb5Oitri2dLzIXGCVhtf%2Bg%3D%3D--QKhVedGbufBfOIV%2B--QtW%2BUAKeGzzegbMJVstDBw%3D%3D;
Path=/; HttpOnly; Secure; SameSite=Lax
- _octo=GH1.1.872348540.1715709884; Path=/; Domain=github.com; Expires=Wed,
14 May 2025 18:04:44 GMT; Secure; SameSite=Lax
- logged_in=no; Path=/; Domain=github.com; Expires=Wed, 14 May 2025 18:04:44
GMT; HttpOnly; Secure; SameSite=Lax
Strict-Transport-Security:
- max-age=31536000; includeSubdomains; preload
Vary:
- X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, Accept-Encoding, Accept,
X-Requested-With
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- deny
X-GitHub-Request-Id:
- FC3E:250C6F:7C878C2:B40A3A9:6643A7BC
X-XSS-Protection:
- '0'
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
interactions:
- request:
body: null
headers: {}
method: GET
uri: https://planetarycomputer.microsoft.com/api/sas/v1/token/sentinel2l2a01/sentinel2-l2
response:
body:
string: '{"msft:expiry":"2024-05-14T19:00:49Z","token":"st=2024-05-13T18%3A15%3A49Z&se=2024-05-14T19%3A00%3A49Z&sp=rl&sv=2021-06-08&sr=c&skoid=957f55e4-97bf-4dce-ae04-ff8389f97c65&sktid=72f988bf-86f1-41af-91ab-2d7cd011db47&skt=2024-05-14T10%3A18%3A30Z&ske=2024-05-21T10%3A18%3A30Z&sks=b&skv=2021-06-08&sig=1%2BTZYindo7mFjt5oZLcgK97cm5PZ/iKr9Y8UIVJ49AE%3D"}'
headers:
Accept-Ranges:
- bytes
Connection:
- keep-alive
Content-Length:
- '347'
Content-Type:
- application/json
Date:
- Tue, 14 May 2024 18:15:49 GMT
Request-Context:
- appId=cid-v1:75161b1b-6883-4b66-9410-715040c44427
Strict-Transport-Security:
- max-age=15724800; includeSubDomains
X-Cache:
- CONFIG_NOCACHE
x-azure-ref:
- 20240514T181549Z-176fb699484x5zd7zyqyhxvx1n00000000bg0000000013em
status:
code: 200
message: OK
- request:
body: null
headers: {}
method: HEAD
uri: https://sentinel2l2a01.blob.core.windows.net/sentinel2-l2/48/X/VR/2023/05/24/S2B_MSIL2A_20230524T084609_N0509_R107_T48XVR_20230524T120352.SAFE/GRANULE/L2A_T48XVR_A032451_20230524T084603/QI_DATA/T48XVR_20230524T084609_PVI.tif?st=2024-05-13T18:15:49Z&se=2024-05-14T19:00:49Z&sp=rl&sv=2021-06-08&sr=c&skoid=957f55e4-97bf-4dce-ae04-ff8389f97c65&sktid=72f988bf-86f1-41af-91ab-2d7cd011db47&skt=2024-05-14T10:18:30Z&ske=2024-05-21T10:18:30Z&sks=b&skv=2021-06-08&sig=1%2BTZYindo7mFjt5oZLcgK97cm5PZ/iKr9Y8UIVJ49AE%3D
response:
body:
string: ''
headers:
Accept-Ranges:
- bytes
Access-Control-Allow-Origin:
- '*'
Access-Control-Expose-Headers:
- x-ms-request-id,Server,x-ms-version,Content-Type,Last-Modified,ETag,x-ms-creation-time,Content-MD5,x-ms-lease-status,x-ms-lease-state,x-ms-blob-type,x-ms-server-encrypted,x-ms-access-tier,x-ms-access-tier-inferred,Accept-Ranges,Content-Length,Date,Transfer-Encoding
Content-Length:
- '4096'
Content-MD5:
- AhcBUcRKwcVPYcaN4z/cPQ==
Content-Type:
- application/octet-stream
Date:
- Tue, 14 May 2024 18:15:50 GMT
Etag:
- '"0x8DB5C5106A61ECF"'
Last-Modified:
- Wed, 24 May 2023 12:18:47 GMT
Server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-access-tier:
- Hot
x-ms-access-tier-inferred:
- 'true'
x-ms-blob-type:
- BlockBlob
x-ms-creation-time:
- Wed, 24 May 2023 12:18:47 GMT
x-ms-lease-state:
- available
x-ms-lease-status:
- unlocked
x-ms-request-id:
- 3de1c11e-601e-0083-432a-a6f4cc000000
x-ms-server-encrypted:
- 'true'
x-ms-version:
- '2021-06-08'
status:
code: 200
message: OK
version: 1
148 changes: 148 additions & 0 deletions tests/cassettes/test_s3_client/test_href_exists.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
interactions:
- request:
body: null
headers:
Accept-Encoding:
- identity
User-Agent:
- aiobotocore/2.12.1 md/Botocore#1.34.51 ua/2.0 os/macos#23.4.0 md/arch#x86_64
lang/python#3.11.7 md/pyimpl#CPython cfg/retry-mode#adaptive botocore/1.34.51
amz-sdk-invocation-id:
- ebc034ad-e4fe-4070-ae27-e018ee92a4ec
amz-sdk-request:
- attempt=1
method: HEAD
uri: https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/42/L/TQ/2023/5/S2B_42LTQ_20230524_0_L2A/thumbnail.jpg
response:
body:
string: ''
headers:
Accept-Ranges:
- bytes
Content-Length:
- '6060'
Content-Type:
- image/jpeg
Date:
- Tue, 14 May 2024 18:14:17 GMT
Etag:
- '"fd5be8ff5885a647387fc9210704950d"'
Last-Modified:
- Wed, 24 May 2023 10:42:05 GMT
Server:
- AmazonS3
x-amz-id-2:
- mEWDTwXCtAkJO3+RxODkn81nWml1tFJMDavR9OIwHo9W3NYjj/+FKoCb8JeTVga9sz+170cr/mg=
x-amz-request-id:
- M04XGMNZ7RWW262Y
x-amz-server-side-encryption:
- AES256
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- identity
Host:
- does-not-exist.s3.us-west-2.amazonaws.com
User-Agent:
- aiobotocore/2.12.1 md/Botocore#1.34.51 ua/2.0 os/macos#23.4.0 md/arch#x86_64
lang/python#3.11.7 md/pyimpl#CPython cfg/retry-mode#adaptive botocore/1.34.51
amz-sdk-invocation-id:
- 8e695971-ee53-4019-95ed-2566e6c08271
amz-sdk-request:
- attempt=1
method: HEAD
uri: https://does-not-exist.s3.us-west-2.amazonaws.com/not-a-file
response:
body:
string: ''
headers:
Content-Type:
- application/xml
Date:
- Tue, 14 May 2024 18:14:16 GMT
Server:
- AmazonS3
x-amz-bucket-region:
- eu-west-1
x-amz-id-2:
- LykPIu7RSmG/dxQtmQpYIQMM8M4kNSoyj/YSWn+mKLT9uxhW9PKfom47AyHQJ7nLv/7n/klGK6U=
x-amz-request-id:
- 9N4DTCVGDBGMSY5W
status:
code: 301
message: Moved Permanently
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- identity
Host:
- does-not-exist.s3.us-west-2.amazonaws.com
User-Agent:
- aiobotocore/2.12.1 md/Botocore#1.34.51 ua/2.0 os/macos#23.4.0 md/arch#x86_64
lang/python#3.11.7 md/pyimpl#CPython cfg/retry-mode#adaptive botocore/1.34.51
amz-sdk-invocation-id:
- 8e695971-ee53-4019-95ed-2566e6c08271
amz-sdk-request:
- attempt=1
method: HEAD
uri: https://does-not-exist.s3.us-west-2.amazonaws.com/not-a-file
response:
body:
string: ''
headers:
Content-Type:
- application/xml
Date:
- Tue, 14 May 2024 18:14:16 GMT
Server:
- AmazonS3
x-amz-bucket-region:
- eu-west-1
x-amz-id-2:
- LykPIu7RSmG/dxQtmQpYIQMM8M4kNSoyj/YSWn+mKLT9uxhW9PKfom47AyHQJ7nLv/7n/klGK6U=
x-amz-request-id:
- 9N4DTCVGDBGMSY5W
status:
code: 301
message: Moved Permanently
- request:
body: null
headers:
Accept-Encoding:
- identity
User-Agent:
- aiobotocore/2.12.1 md/Botocore#1.34.51 ua/2.0 os/macos#23.4.0 md/arch#x86_64
lang/python#3.11.7 md/pyimpl#CPython cfg/retry-mode#adaptive botocore/1.34.51
amz-sdk-invocation-id:
- 8e695971-ee53-4019-95ed-2566e6c08271
amz-sdk-request:
- ttl=20240514T181516Z; attempt=2; max=11
method: HEAD
uri: https://does-not-exist.s3.eu-west-1.amazonaws.com/not-a-file
response:
body:
string: ''
headers:
Content-Type:
- application/xml
Date:
- Tue, 14 May 2024 18:14:17 GMT
Server:
- AmazonS3
x-amz-id-2:
- 1yzdcl560VVUPmN0328z2IyMqj4/eiE9rDB8rRp1NbF+II+7lbdVy+kRVpnZOLXcpimhaCIPyS8=
x-amz-request-id:
- 9N4AH413TFRGCT6Q
status:
code: 403
message: Forbidden
version: 1
1 change: 1 addition & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def test_download_item_s3_requester_pays(tmp_path: Path) -> None:
"thumbnail",
"--alternate-assets",
"s3",
"--fail-fast",
],
)
assert result.exit_code == 0
Expand Down
2 changes: 1 addition & 1 deletion tests/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from stac_asset import Config, HttpClient

pytestmark = [
pytest.mark.network_access,
pytest.mark.asyncio,
]


@pytest.mark.vcr
async def test_href_exists() -> None:
async with await HttpClient.from_config(Config()) as client:
assert await client.href_exists("https://github.com/stac-utils/stac-asset")
3 changes: 2 additions & 1 deletion tests/test_planetary_computer_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from stac_asset import Config, PlanetaryComputerClient

pytestmark = [
pytest.mark.network_access,
pytest.mark.asyncio,
]

Expand All @@ -15,13 +14,15 @@ def asset_href() -> str:
return "https://sentinel2l2a01.blob.core.windows.net/sentinel2-l2/48/X/VR/2023/05/24/S2B_MSIL2A_20230524T084609_N0509_R107_T48XVR_20230524T120352.SAFE/GRANULE/L2A_T48XVR_A032451_20230524T084603/QI_DATA/T48XVR_20230524T084609_PVI.tif"


@pytest.mark.network_access
async def test_download(tmp_path: Path, asset_href: str) -> None:
async with await PlanetaryComputerClient.from_config(Config()) as client:
await client.download_href(asset_href, tmp_path / "out.tif")

assert os.path.getsize(tmp_path / "out.tif") == 4096


@pytest.mark.vcr
async def test_href_exists(tmp_path: Path, asset_href: str) -> None:
async with await PlanetaryComputerClient.from_config(Config()) as client:
assert await client.href_exists(asset_href)

0 comments on commit a9c76c0

Please sign in to comment.