Skip to content

Commit 8a35e10

Browse files
authored
Merge pull request #22 from GitGuardian/sofien/-/fix_previous_version
fix(models): fix PolicyBreak model
2 parents e7d92f0 + 60a539b commit 8a35e10

File tree

3 files changed

+82
-20
lines changed

3 files changed

+82
-20
lines changed

pygitguardian/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .client import GGClient
33

44

5-
__version__ = "1.3.2"
5+
__version__ = "1.3.3"
66
GGClient._version = __version__
77

88
__all__ = [

pygitguardian/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ def __init__(
216216
self,
217217
break_type: str,
218218
policy: str,
219+
validity: str,
219220
matches: List[Match],
220-
validity: Optional[str] = None,
221221
**kwargs: Any,
222222
) -> None:
223223
super().__init__()

tests/test_models.py

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
from typing import OrderedDict
22

3-
from pygitguardian.models import Document, DocumentSchema, Match, MatchSchema
3+
import pytest
4+
5+
from pygitguardian.models import (
6+
Document,
7+
DocumentSchema,
8+
HealthCheckResponseSchema,
9+
Match,
10+
MatchSchema,
11+
MultiScanResult,
12+
MultiScanResultSchema,
13+
PolicyBreak,
14+
PolicyBreakSchema,
15+
Quota,
16+
QuotaResponse,
17+
QuotaResponseSchema,
18+
QuotaSchema,
19+
ScanResult,
20+
ScanResultSchema,
21+
)
422

523

624
class TestModel:
@@ -14,26 +32,70 @@ def test_document_model(self):
1432
assert isinstance(document.to_dict(), dict)
1533
assert isinstance(str(document), str)
1634

17-
def test_schema_excludes(self):
35+
@pytest.mark.parametrize(
36+
"schema_klass, expected_klass, instance_data",
37+
[
38+
(DocumentSchema, OrderedDict, {"filename": "hello", "document": "hello"}),
39+
(
40+
HealthCheckResponseSchema,
41+
OrderedDict,
42+
{"detail": "hello", "status_code": 200},
43+
),
44+
(MatchSchema, Match, {"match": "hello", "type": "hello"}),
45+
(
46+
MultiScanResultSchema,
47+
MultiScanResult,
48+
{"scan_results": [], "type": "hello"},
49+
),
50+
(
51+
PolicyBreakSchema,
52+
PolicyBreak,
53+
{
54+
"type": "hello",
55+
"policy": "hello",
56+
"validity": "hey",
57+
"matches": [{"match": "hello", "type": "hello"}],
58+
},
59+
),
60+
(
61+
QuotaSchema,
62+
Quota,
63+
{
64+
"count": 1,
65+
"limit": 1,
66+
"remaining": 1,
67+
"since": "2021-04-18",
68+
},
69+
),
70+
(
71+
QuotaResponseSchema,
72+
QuotaResponse,
73+
{
74+
"content": {
75+
"count": 1,
76+
"limit": 1,
77+
"remaining": 1,
78+
"since": "2021-04-18",
79+
}
80+
},
81+
),
82+
(
83+
ScanResultSchema,
84+
ScanResult,
85+
{"policy_break_count": 1, "policy_breaks": [], "policies": []},
86+
),
87+
],
88+
)
89+
def test_schema_loads(self, schema_klass, expected_klass, instance_data):
1890
"""
19-
GIVEN a simple document and an extra field in dict format
91+
GIVEN the right kwargs and an extra field in dict format
2092
WHEN loading using the schema
2193
THEN the extra field should be excluded
94+
AND the result should be an instance of the expected class
2295
"""
23-
document = {"filename": "hello", "document": "hello", "extra": "field"}
24-
schema = DocumentSchema()
25-
26-
document_obj = schema.load(document)
27-
assert isinstance(document_obj, OrderedDict)
96+
schema = schema_klass()
2897

29-
def test_schema_loads(self):
30-
"""
31-
GIVEN a simple match and an extra field in dict format
32-
WHEN loading using the schema
33-
THEN the extra field should be excluded and the result should be a Match
34-
"""
35-
match = {"match": "hello", "type": "hello", "extra": "field"}
36-
schema = MatchSchema()
98+
data = {**instance_data, "field": "extra"}
3799

38-
match_obj = schema.load(match)
39-
assert isinstance(match_obj, Match)
100+
obj = schema.load(data)
101+
assert isinstance(obj, expected_klass)

0 commit comments

Comments
 (0)