|
1 | 1 | import json
|
2 |
| -from typing import Dict, List, Optional, Type |
| 2 | +from datetime import date |
| 3 | +from typing import Any, Dict, List, Optional, Type |
3 | 4 | from unittest.mock import Mock, patch
|
4 | 5 |
|
5 | 6 | import pytest
|
|
13 | 14 | DOCUMENT_SIZE_THRESHOLD_BYTES,
|
14 | 15 | MULTI_DOCUMENT_LIMIT,
|
15 | 16 | )
|
16 |
| -from pygitguardian.models import Detail, MultiScanResult, ScanResult |
| 17 | +from pygitguardian.models import Detail, MultiScanResult, QuotaResponse, ScanResult |
17 | 18 |
|
18 | 19 | from .conftest import base_uri, my_vcr
|
19 | 20 |
|
@@ -432,7 +433,7 @@ def test_content_not_ok():
|
432 | 433 | def test_content_scan(
|
433 | 434 | client: GGClient,
|
434 | 435 | name: str,
|
435 |
| - to_scan: Dict[str, str], |
| 436 | + to_scan: Dict[str, Any], |
436 | 437 | has_secrets: bool,
|
437 | 438 | has_policy_breaks: bool,
|
438 | 439 | policy_break_count: int,
|
@@ -505,7 +506,7 @@ def test_assert_content_type(client: GGClient):
|
505 | 506 | def test_extra_headers(
|
506 | 507 | request_mock: Mock,
|
507 | 508 | client: GGClient,
|
508 |
| - session_headers: Dict[str, str], |
| 509 | + session_headers: Any, |
509 | 510 | extra_headers: Optional[Dict[str, str]],
|
510 | 511 | expected_headers: Dict[str, str],
|
511 | 512 | ):
|
@@ -534,3 +535,23 @@ def test_extra_headers(
|
534 | 535 | assert request_mock.called
|
535 | 536 | _, kwargs = request_mock.call_args
|
536 | 537 | assert expected_headers == kwargs["headers"]
|
| 538 | + |
| 539 | + |
| 540 | +def test_quota_overview(client: GGClient): |
| 541 | + with my_vcr.use_cassette("quota.yaml"): |
| 542 | + quota_response = client.quota_overview() |
| 543 | + assert type(repr(quota_response)) == str |
| 544 | + assert type(str(quota_response)) == str |
| 545 | + assert quota_response.status_code == 200 |
| 546 | + if isinstance(quota_response, QuotaResponse): |
| 547 | + assert quota_response.content.limit == 5000 |
| 548 | + assert quota_response.content.count == 2 |
| 549 | + assert quota_response.content.remaining == 4998 |
| 550 | + assert quota_response.content.since == date(2021, 4, 18) |
| 551 | + else: |
| 552 | + pytest.fail("returned should be a QuotaResponse") |
| 553 | + |
| 554 | + assert type(quota_response.to_dict()) == dict |
| 555 | + quota_response_json = quota_response.to_json() |
| 556 | + assert type(quota_response_json) == str |
| 557 | + assert type(json.loads(quota_response_json)) == dict |
0 commit comments