Skip to content

Commit

Permalink
test: update case
Browse files Browse the repository at this point in the history
  • Loading branch information
frankqianms committed Oct 14, 2024
1 parent 172e1d2 commit 1c987ed
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/apic-extension/azext_apic_extension/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,13 @@ def register_apic(cmd, api_location, resource_group, service_name, environment_i
except yaml.YAMLError as e:
logger.error("Error parsing data from %s: %s", api_location, e)
data = None
value = None
sys.exit(-1)
# If we could parse the content(json or yaml), set format to link
value = str(api_location) if data else None
custom_format = 'link' if data else 'inline'
except requests.exceptions.RequestException as e:
logger.error("Error fetching data from %s: %s", api_location, e)
logger.error("Error fetching data from invalid url %s: %s", api_location, e)
data = None
value = None
sys.exit(-1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: https://github.com/
response:
body:
string: '!!! The response body has been omitted from the recording because it
is larger than 128 KB. It will be replaced with blank content of 254700 bytes
while replay. <CTRL-REPLACE>254700'
headers:
accept-ranges:
- bytes
cache-control:
- max-age=0, private, must-revalidate
content-language:
- en-US
content-length:
- '181'
content-security-policy:
- 'default-src ''none''; base-uri ''self''; child-src github.com/assets-cdn/worker/
github.com/webpack/ github.com/assets/ 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
*.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com
objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com
proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.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 api.githubcopilot.com api.individual.githubcopilot.com
api.business.githubcopilot.com api.enterprise.githubcopilot.com github.githubassets.com
edge.fullstory.com rs.fullstory.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
www.youtube-nocookie.com; img-src ''self'' data: blob: github.githubassets.com
media.githubusercontent.com camo.githubusercontent.com identicons.github.com
avatars.githubusercontent.com private-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 github.githubassets.com;
script-src github.githubassets.com; style-src ''unsafe-inline'' github.githubassets.com;
upgrade-insecure-requests; worker-src github.com/assets-cdn/worker/ github.com/webpack/
github.com/assets/ gist.github.com/assets-cdn/worker/'
content-type:
- text/html; charset=utf-8
date:
- Mon, 14 Oct 2024 07:03:04 GMT
etag:
- W/"ad020a57719bd5469753cb724bbc94e8"
referrer-policy:
- origin-when-cross-origin, strict-origin-when-cross-origin
server:
- GitHub.com
set-cookie:
- _gh_sess=7%2FPNfXB8BbR%2BREv8ABIyCSrMFT7rlpsbV%2FNUfVueN0VcPL%2B92yly2YTkcbhGkILGUWNhPrrhZkrOvtSwOkmaS1KaiIT4RaOb%2FcFGq22ihX6C58Mhdz2ciCFdy7AkkNABfjT4DWwGzJWnKJbmODPWGL3eINYLQ0GL46haL2jVRiOWjlwBbXJXX8Nvu1CjUKLCdlq5VAz14ckYdo%2F8pCu%2FGl%2FW1vYOTKbMAtakWE6LEOGg7WIXNQbGjMY8s4n%2FDhxE7fZNEtPWmlLnQ80fwk3OwA%3D%3D--kSwx7NeUvvg9eq1G--eDsIDxRpKxLmOFN4sVYV2w%3D%3D;
Path=/; HttpOnly; Secure; SameSite=Lax
- _octo=GH1.1.852216255.1728889390; Path=/; Domain=github.com; Expires=Tue,
14 Oct 2025 07:03:10 GMT; Secure; SameSite=Lax
- logged_in=no; Path=/; Domain=github.com; Expires=Tue, 14 Oct 2025 07:03:10
GMT; HttpOnly; Secure; SameSite=Lax
strict-transport-security:
- max-age=31536000; includeSubdomains; preload
transfer-encoding:
- chunked
vary:
- X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, Accept-Language, Accept-Encoding,
Accept, X-Requested-With
x-content-type-options:
- nosniff
x-frame-options:
- deny
x-github-request-id:
- ED7B:349017:3EECDE:442464:670CC22E
x-xss-protection:
- '0'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- apic api show
Connection:
- keep-alive
ParameterSetName:
- -g -n --api-id
User-Agent:
- AZURECLI/2.63.0 azsdk-python-core/1.28.0 Python/3.11.9 (Windows-10-10.0.22631-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clirg000001/providers/Microsoft.ApiCenter/services/clitest000002/workspaces/default/apis/swaggerpetstore?api-version=2024-03-01
response:
body:
string: '{"code":"404"}'
headers:
api-supported-versions:
- 2023-07-01-preview, 2024-03-01, 2024-03-15-preview
cache-control:
- no-cache
content-length:
- '14'
content-type:
- application/json; charset=utf-8
date:
- Mon, 14 Oct 2024 07:03:11 GMT
expires:
- '-1'
pragma:
- no-cache
strict-transport-security:
- max-age=31536000; includeSubDomains
vary:
- Accept-Encoding
x-cache:
- CONFIG_NOCACHE
x-content-type-options:
- nosniff
x-ms-ratelimit-remaining-subscription-global-reads:
- '16498'
x-msedge-ref:
- 'Ref A: 7B855DB8582641E782BCABFAD944C700 Ref B: MAA201060516049 Ref C: 2024-10-14T07:03:10Z'
x-powered-by:
- ASP.NET
status:
code: 404
message: Not Found
version: 1
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ interactions:
content-type:
- text/plain; charset=utf-8
date:
- Mon, 14 Oct 2024 06:36:01 GMT
- Mon, 14 Oct 2024 07:03:30 GMT
referrer-policy:
- origin-when-cross-origin, strict-origin-when-cross-origin
server:
- GitHub.com
set-cookie:
- _gh_sess=6Bvugk9%2BdzKXY1UvKUXoc9utasA8ctNeuCG4FWITyZd5r492RP2G805R23PvgMJoq7ujd32vSsDhL5evFFaIXaZrSVPhNSP9iyuhKIKQdQ9nsAd%2BJBj6E4bJLLLCv6HyUrtM176PMbXcJh7d3eadecGmvJosGmIqUrg0CygUZma0XiY95enVkPtoFZcG2gZJ0xUCNIxBon4QjxzYtNN%2Fq7FkNtdsW2a9%2Bkv2vHx5IGQF7i5wNIhssJbVYD6uAoMOhZsElBp1%2F2B3lflh1ce7bw%3D%3D--ar%2BP7SI7LyQoGkeK--zdqvDQ1p7kKcumuF4mNvNg%3D%3D;
- _gh_sess=9A3%2B66QrReZRm2K75SZ2WOMGDT3amDH7DGBlLm6H5OTL8FX6eokB1uBFajbncCOfMPkvxXNdgWKOBuxhvrlXIMxG%2FCpzF8jpIGZI4XKOQsr6BxtRxkF7IEZphIu%2FtdHYdl65GcyFvl70cpVKUu5XZQISW4TcSV3VQMWcoLfqvzvnv4R9h6HMlWO5LG%2B%2F6DMnTJuL3kBhxKonLwLuQY7IwkXunvKbDsSKvbG8L2SCChWEYvEGLx1d5uuvcI3AQLkzZ0LiMWREx9rpe0SZu7JhEw%3D%3D--gEN6KNuujf3BD6Bo--NFujfW7a25jfb%2B1e48IddA%3D%3D;
Path=/; HttpOnly; Secure; SameSite=Lax
- _octo=GH1.1.1934795728.1728887761; Path=/; Domain=github.com; Expires=Tue,
14 Oct 2025 06:36:01 GMT; Secure; SameSite=Lax
- logged_in=no; Path=/; Domain=github.com; Expires=Tue, 14 Oct 2025 06:36:01
- _octo=GH1.1.902834683.1728889410; Path=/; Domain=github.com; Expires=Tue,
14 Oct 2025 07:03:30 GMT; Secure; SameSite=Lax
- logged_in=no; Path=/; Domain=github.com; Expires=Tue, 14 Oct 2025 07:03:30
GMT; HttpOnly; Secure; SameSite=Lax
strict-transport-security:
- max-age=31536000; includeSubdomains; preload
Expand All @@ -48,7 +48,7 @@ interactions:
x-frame-options:
- deny
x-github-request-id:
- BF36:213C0F:1D5B53E:20B6AD9:670CBBD1
- E258:2E630A:AFC347:C34E4E:670CC242
x-xss-protection:
- '0'
status:
Expand Down Expand Up @@ -84,7 +84,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Mon, 14 Oct 2024 06:36:02 GMT
- Mon, 14 Oct 2024 07:03:31 GMT
expires:
- '-1'
pragma:
Expand All @@ -100,7 +100,7 @@ interactions:
x-ms-ratelimit-remaining-subscription-global-reads:
- '16499'
x-msedge-ref:
- 'Ref A: DE650A4725C04952938521858943C701 Ref B: MAA201060516029 Ref C: 2024-10-14T06:36:02Z'
- 'Ref A: 9333EFAC9FF2415C84441AB64AE4966E Ref B: MAA201060515035 Ref C: 2024-10-14T07:03:30Z'
x-powered-by:
- ASP.NET
status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,33 @@ def test_register_with_invalid_spec_url(self):
self.kwargs.update({
'spec_url': 'https://github.com/invalidrepo'
})

# Capture the logs
with self.assertLogs(logger, level='ERROR') as log:
with self.assertRaises(SystemExit) as cm:
self.cmd('az apic api register -g {rg} -n {s} -l "{spec_url}"', expect_failure=True)
# Verify error message
self.assertIn("Error fetching data from invalid url https://github.com/invalidrepo:", log.output[0])
# Verify SystemExit code
self.assertEqual(cm.exception.code, -1)
# Verify the API is not registered
self.cmd('az apic api show -g {rg} -n {s} --api-id swaggerpetstore', expect_failure=True)

@ResourceGroupPreparer(name_prefix="clirg", location=TEST_REGION, random_name_length=32)
@ApicServicePreparer()
def test_register_using_spec_url_with_invalid_content(self):
# Set up an URL with invalid spec
self.kwargs.update({
'spec_url': 'https://github.com/'
})
# Capture the logs
with self.assertLogs(logger, level='ERROR') as log:
with self.assertRaises(SystemExit) as cm:
self.cmd('az apic api register -g {rg} -n {s} -l "{spec_url}"', expect_failure=True)
# Verify error message
self.assertIn("Error fetching data from https://github.com/invalidrepo:", log.output[0])
self.assertIn("Error parsing data from https://github.com/:", log.output[0])
# Verify SystemExit code
self.assertEqual(cm.exception.code, -1)
# Verify the API is not registered
self.cmd('az apic api show -g {rg} -n {s} --api-id swaggerpetstore', expect_failure=True)

@ResourceGroupPreparer(name_prefix="clirg", location=TEST_REGION, random_name_length=32)
Expand Down

0 comments on commit 1c987ed

Please sign in to comment.