Skip to content

Commit c8fde60

Browse files
committed
fix(tests): make some tests more robust
- Do not hard-code exact versions, match them with regex - Do not hard-code values for quota (except limit for now)
1 parent 60449eb commit c8fde60

File tree

3 files changed

+51
-62
lines changed

3 files changed

+51
-62
lines changed

tests/cassettes/quota.yaml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,50 @@ interactions:
99
Connection:
1010
- keep-alive
1111
User-Agent:
12-
- pygitguardian/1.1.3 (Linux;py3.9.5)
12+
- pygitguardian/1.3.4 (Linux;py3.8.10)
1313
method: GET
1414
uri: https://api.gitguardian.com/v1/quotas
1515
response:
1616
body:
17-
string: '{"content": {"count": 2,"limit": 5000,"remaining": 4998,"since": "2021-04-18"}}'
17+
string: '{"content":{"count":1092,"limit":10000,"remaining":8908,"since":"2022-05-31"}}'
1818
headers:
1919
Access-Control-Expose-Headers:
2020
- X-App-Version
21+
Allow:
22+
- GET, HEAD, OPTIONS
2123
Connection:
2224
- keep-alive
2325
Content-Length:
24-
- '79'
26+
- '78'
2527
Content-Type:
2628
- application/json
2729
Date:
28-
- Wed, 19 May 2021 15:57:19 GMT
30+
- Thu, 30 Jun 2022 10:29:43 GMT
2931
Referrer-Policy:
30-
- same-origin
32+
- strict-origin-when-cross-origin
3133
Server:
3234
- nginx
35+
Set-Cookie:
36+
- AWSALB=VrB3AmmOenUGpcQmmBHpD0IPTpDMLjk+9jYaMY0CHng7krkcm7W6MOcLTgFUARmhhvAFbzeiLnNXuClqxjvf42e/qfYZkv5fRm35bkE69HfBN8CGjcv+8uCCW40a;
37+
Expires=Thu, 07 Jul 2022 10:29:43 GMT; Path=/
38+
- AWSALBCORS=VrB3AmmOenUGpcQmmBHpD0IPTpDMLjk+9jYaMY0CHng7krkcm7W6MOcLTgFUARmhhvAFbzeiLnNXuClqxjvf42e/qfYZkv5fRm35bkE69HfBN8CGjcv+8uCCW40a;
39+
Expires=Thu, 07 Jul 2022 10:29:43 GMT; Path=/; SameSite=None; Secure
3340
Strict-Transport-Security:
3441
- max-age=31536000; includeSubDomains
42+
Vary:
43+
- Cookie
3544
X-App-Version:
36-
- 1.26.0-rc.4
45+
- v2.8.1
46+
X-Content-Type-Options:
47+
- nosniff
48+
- nosniff
49+
X-Frame-Options:
50+
- DENY
51+
- SAMEORIGIN
3752
X-Secrets-Engine-Version:
38-
- 2.43.0
53+
- 2.70.0
54+
X-XSS-Protection:
55+
- 1; mode=block
3956
status:
4057
code: 200
4158
message: OK

tests/cassettes/test_health_check.yaml

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,77 +9,50 @@ interactions:
99
Connection:
1010
- keep-alive
1111
User-Agent:
12-
- pygitguardian/1.1.0 (Linux;py3.8.3)
12+
- pygitguardian/1.3.4 (Linux;py3.8.10)
1313
method: GET
1414
uri: https://api.gitguardian.com/v1/health
1515
response:
1616
body:
1717
string: '{"detail":"Valid API key."}'
1818
headers:
19+
Access-Control-Expose-Headers:
20+
- X-App-Version
1921
Allow:
20-
- OPTIONS, GET
22+
- GET, HEAD, OPTIONS
2123
Connection:
2224
- keep-alive
2325
Content-Length:
2426
- '27'
2527
Content-Type:
2628
- application/json
2729
Date:
28-
- Fri, 19 Jun 2020 13:32:39 GMT
30+
- Thu, 30 Jun 2022 10:29:31 GMT
31+
Referrer-Policy:
32+
- strict-origin-when-cross-origin
2933
Server:
3034
- nginx
35+
Set-Cookie:
36+
- AWSALB=ZAU9JIicUlzJUNwRc9mylRpa+xGHlXk7K6hR4AXPyVGxpv6RzWENXH+X6DekAaXLAqGr8GCssUXwqYsvRjfFPtGZd53wkfYQJmrmBAMw1ZNexucrzoXCmEycJsHU;
37+
Expires=Thu, 07 Jul 2022 10:29:31 GMT; Path=/
38+
- AWSALBCORS=ZAU9JIicUlzJUNwRc9mylRpa+xGHlXk7K6hR4AXPyVGxpv6RzWENXH+X6DekAaXLAqGr8GCssUXwqYsvRjfFPtGZd53wkfYQJmrmBAMw1ZNexucrzoXCmEycJsHU;
39+
Expires=Thu, 07 Jul 2022 10:29:31 GMT; Path=/; SameSite=None; Secure
40+
Strict-Transport-Security:
41+
- max-age=31536000; includeSubDomains
3142
Vary:
3243
- Cookie
33-
X-Content-Type-Options:
34-
- nosniff
35-
X-Frame-Options:
36-
- DENY
3744
X-App-Version:
38-
- 1.26.0-rc.4
39-
X-Secrets-Engine-Version:
40-
- 2.43.0
41-
status:
42-
code: 200
43-
message: OK
44-
- request:
45-
body: null
46-
headers:
47-
Accept:
48-
- '*/*'
49-
Accept-Encoding:
50-
- gzip, deflate
51-
Connection:
52-
- keep-alive
53-
User-Agent:
54-
- pygitguardian/1.1.0 (Linux;py3.8.3)
55-
method: GET
56-
uri: https://api.gitguardian.com/v1/health
57-
response:
58-
body:
59-
string: '{"detail":"Valid API key."}'
60-
headers:
61-
Allow:
62-
- OPTIONS, GET
63-
Connection:
64-
- keep-alive
65-
Content-Length:
66-
- '27'
67-
Content-Type:
68-
- application/json
69-
Date:
70-
- Fri, 19 Jun 2020 14:58:35 GMT
71-
Server:
72-
- nginx
73-
Vary:
74-
- Cookie
45+
- v2.8.1
7546
X-Content-Type-Options:
7647
- nosniff
48+
- nosniff
7749
X-Frame-Options:
7850
- DENY
79-
X-App-Version:
80-
- 1.26.0-rc.4
51+
- SAMEORIGIN
8152
X-Secrets-Engine-Version:
82-
- 2.43.0
53+
- 2.70.0
54+
X-XSS-Protection:
55+
- 1; mode=block
8356
status:
8457
code: 200
8558
message: OK

tests/test_client.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import re
23
from collections import OrderedDict
34
from datetime import date
45
from typing import Any, Dict, List, Optional, Type
@@ -264,10 +265,8 @@ def test_health_check(client: GGClient):
264265
health = client.health_check()
265266
assert health.status_code == 200
266267
assert health.detail == "Valid API key."
267-
assert str(health) == (
268-
"detail:Valid API key., status_code:200, "
269-
"app version:1.26.0-rc.4, secrets engine version:2.43.0"
270-
)
268+
assert re.match(r"^v\d+\.\d+\.\d+([-0-9.rc])?$", health.app_version)
269+
assert re.match(r"^\d+\.\d+\.\d+$", health.secrets_engine_version)
271270
assert bool(health)
272271
assert health.success
273272

@@ -556,10 +555,10 @@ def test_quota_overview(client: GGClient):
556555
assert type(str(quota_response)) == str
557556
assert quota_response.status_code == 200
558557
if isinstance(quota_response, QuotaResponse):
559-
assert quota_response.content.limit == 5000
560-
assert quota_response.content.count == 2
561-
assert quota_response.content.remaining == 4998
562-
assert quota_response.content.since == date(2021, 4, 18)
558+
content = quota_response.content
559+
assert content.count + content.remaining == content.limit
560+
assert content.limit == 10000
561+
assert 2021 <= content.since.year <= date.today().year
563562
else:
564563
pytest.fail("returned should be a QuotaResponse")
565564

0 commit comments

Comments
 (0)