1
1
import pytest
2
2
3
+ from django .contrib .contenttypes .models import ContentType
4
+
5
+ from datahub .company .test .factories import CompanyFactory
6
+ from datahub .documents .models import GenericDocument
3
7
from datahub .documents .serializers import (
4
8
GenericDocumentRetrieveSerializer ,
5
9
SharePointDocumentSerializer ,
12
16
assert_retrieved_generic_document ,
13
17
assert_retrieved_sharepoint_document ,
14
18
)
19
+ from datahub .investment .project .test .factories import InvestmentProjectFactory
15
20
16
21
17
22
pytestmark = pytest .mark .django_db
@@ -33,3 +38,39 @@ def test_serializing_instance_returns_expected_fields(self):
33
38
generic_document = CompanySharePointDocumentFactory ()
34
39
serializer = GenericDocumentRetrieveSerializer (generic_document )
35
40
assert_retrieved_generic_document (generic_document , serializer .data )
41
+
42
+ def test_serializer_raises_error_if_unsupported_document_type (self ):
43
+ unsupported_document = CompanySharePointDocumentFactory ()
44
+ unsupported_document_type = ContentType .objects .get_for_model (unsupported_document )
45
+
46
+ company = CompanyFactory ()
47
+ company_type = ContentType .objects .get_for_model (company )
48
+
49
+ generic_document = GenericDocument .objects .create (
50
+ document_type = unsupported_document_type ,
51
+ document_object_id = unsupported_document .id ,
52
+ related_object_type = company_type ,
53
+ related_object_id = company .id ,
54
+ )
55
+ with pytest .raises (Exception ):
56
+ serializer = GenericDocumentRetrieveSerializer (generic_document )
57
+ serializer .data
58
+
59
+ def test_serializer_raises_error_if_unsupported_related_object_type (self ):
60
+ document = SharePointDocumentFactory ()
61
+ document_type = ContentType .objects .get_for_model (document )
62
+
63
+ unsupported_related_object = InvestmentProjectFactory ()
64
+ unsupported_related_object_type = ContentType .objects .get_for_model (
65
+ unsupported_related_object ,
66
+ )
67
+
68
+ generic_document = GenericDocument .objects .create (
69
+ document_type = document_type ,
70
+ document_object_id = document .id ,
71
+ related_object_type = unsupported_related_object_type ,
72
+ related_object_id = unsupported_related_object .id ,
73
+ )
74
+ with pytest .raises (Exception ):
75
+ serializer = GenericDocumentRetrieveSerializer (generic_document )
76
+ serializer .data
0 commit comments