1
1
from typing import OrderedDict
2
2
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
+ )
4
22
5
23
6
24
class TestModel :
@@ -14,26 +32,70 @@ def test_document_model(self):
14
32
assert isinstance (document .to_dict (), dict )
15
33
assert isinstance (str (document ), str )
16
34
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 ):
18
90
"""
19
- GIVEN a simple document and an extra field in dict format
91
+ GIVEN the right kwargs and an extra field in dict format
20
92
WHEN loading using the schema
21
93
THEN the extra field should be excluded
94
+ AND the result should be an instance of the expected class
22
95
"""
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 ()
28
97
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" }
37
99
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