|
1 |
| -from unittest import TestCase |
| 1 | +from typing import OrderedDict |
2 | 2 |
|
3 |
| -from pygitguardian.models import Document |
| 3 | +from pygitguardian.models import Document, DocumentSchema, Match, MatchSchema |
4 | 4 |
|
5 | 5 |
|
6 |
| -class TestModel(TestCase): |
| 6 | +class TestModel: |
7 | 7 | def test_document_model(self):
|
| 8 | + """ |
| 9 | + GIVEN a simple document |
| 10 | + THEN base model methods should produce the appropriate types. |
| 11 | + """ |
8 | 12 | document = Document("hello", "hello")
|
9 |
| - self.assertIsInstance(document.to_json(), str) |
10 |
| - self.assertIsInstance(document.to_dict(), dict) |
11 |
| - self.assertIsInstance(str(document), str) |
| 13 | + assert isinstance(document.to_json(), str) |
| 14 | + assert isinstance(document.to_dict(), dict) |
| 15 | + assert isinstance(str(document), str) |
| 16 | + |
| 17 | + def test_schema_excludes(self): |
| 18 | + """ |
| 19 | + GIVEN a simple document and an extra field in dict format |
| 20 | + WHEN loading using the schema |
| 21 | + THEN the extra field should be excluded |
| 22 | + """ |
| 23 | + document = {"filename": "hello", "document": "hello", "extra": "field"} |
| 24 | + schema = DocumentSchema() |
| 25 | + |
| 26 | + document_obj = schema.load(document) |
| 27 | + assert isinstance(document_obj, OrderedDict) |
| 28 | + |
| 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() |
| 37 | + |
| 38 | + match_obj = schema.load(match) |
| 39 | + assert isinstance(match_obj, Match) |
0 commit comments