Skip to content

Commit 766b99c

Browse files
committed
Hotfix marshmallow
1 parent 7e9fbd0 commit 766b99c

8 files changed

Lines changed: 39 additions & 28 deletions

File tree

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
"""Widget schema class."""
22

3-
from marshmallow import Schema
4-
53
from api.models.widget_documents import WidgetDocuments as WidgetDocumentModel
64

5+
from .base_schema import BaseSchema
6+
77

8-
class WidgetDocumentsSchema(Schema):
8+
class WidgetDocumentsSchema(BaseSchema):
99
"""Widget Documents schema."""
1010

11-
class Meta: # pylint: disable=too-few-public-methods
11+
class Meta(BaseSchema.Meta): # pylint: disable=too-few-public-methods
1212
"""Exclude unknown fields in the deserialized output."""
1313

1414
model = WidgetDocumentModel
15+
include_fk = True
1516
fields = ('id', 'title', 'type', 'parent_document_id', 'url', 'sort_index', 'is_uploaded')

api/src/api/schemas/widget_image.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515

1616
from api.models.widget_image import WidgetImage as WidgetImageModel
1717

18-
from marshmallow import Schema
18+
from .base_schema import BaseSchema
1919

2020

21-
class WidgetImageSchema(Schema):
21+
class WidgetImageSchema(BaseSchema):
2222
"""This is the schema for the image model."""
2323

24-
class Meta: # pylint: disable=too-few-public-methods
24+
class Meta(BaseSchema.Meta): # pylint: disable=too-few-public-methods
2525
"""Images all of the Widget Image fields to a default schema."""
2626

2727
model = WidgetImageModel
28+
include_fk = True
2829
fields = (
2930
'id',
3031
'widget_id',

api/src/api/schemas/widget_listening.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515

1616
from api.models.widget_listening import WidgetListening as WidgetListeningModel
1717

18-
from marshmallow import Schema
18+
from .base_schema import BaseSchema
1919

2020

21-
class WidgetListeningSchema(Schema): # pylint: disable=too-many-ancestors, too-few-public-methods
21+
class WidgetListeningSchema(BaseSchema): # pylint: disable=too-many-ancestors, too-few-public-methods
2222
"""This is the schema for the widget listening model."""
2323

24-
class Meta: # pylint: disable=too-few-public-methods
24+
class Meta(BaseSchema.Meta): # pylint: disable=too-few-public-methods
2525
"""All of the fields in the Widget Listening schema."""
2626

2727
model = WidgetListeningModel
28+
include_fk = True
2829
fields = ('id', 'engagement_id', 'widget_id', 'description')

api/src/api/schemas/widget_map.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515

1616
from api.models.widget_map import WidgetMap as WidgetMapModel
1717

18-
from marshmallow import Schema
18+
from .base_schema import BaseSchema
1919

2020

21-
class WidgetMapSchema(Schema): # pylint: disable=too-many-ancestors, too-few-public-methods
21+
class WidgetMapSchema(BaseSchema): # pylint: disable=too-many-ancestors, too-few-public-methods
2222
"""This is the schema for the map model."""
2323

24-
class Meta: # pylint: disable=too-few-public-methods
24+
class Meta(BaseSchema.Meta): # pylint: disable=too-few-public-methods
2525
"""Maps all of the Widget Map fields to a default schema."""
2626

2727
model = WidgetMapModel
28+
include_fk = True
2829
fields = ('id', 'widget_id', 'engagement_id', 'marker_label', 'latitude', 'longitude', 'geojson', 'file_name')

api/src/api/schemas/widget_poll.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
"""Schema for Widget Poll."""
22
from api.models.widget_poll import Poll as PollModel
33
from api.models.poll_answers import PollAnswer as PollAnswerModel
4-
from marshmallow import Schema
54
from marshmallow_sqlalchemy.fields import Nested
5+
from .base_schema import BaseSchema
66

77

8-
class PollAnswerSchema(Schema):
8+
class PollAnswerSchema(BaseSchema):
99
"""
1010
Schema for serializing and deserializing Poll Answer data.
1111
1212
This schema is used to represent poll answers in a structured format,
1313
facilitating operations like loading from and dumping to JSON.
1414
"""
1515

16-
class Meta:
16+
class Meta(BaseSchema.Meta):
1717
"""Meta class for PollAnswerSchema options."""
1818

1919
model = PollAnswerModel # The model representing Poll Answer.
20+
include_fk = True
2021
fields = ('id', 'answer_text', 'poll_id') # Fields to include in the schema.
2122

2223

23-
class WidgetPollSchema(Schema):
24+
class WidgetPollSchema(BaseSchema):
2425
"""
2526
Schema for serializing and deserializing Widget Poll data.
2627
2728
This schema is designed to handle Widget Poll data, enabling easy conversion
2829
between Python objects and JSON representation, specifically for Widget Polls.
2930
"""
3031

31-
class Meta:
32+
class Meta(BaseSchema.Meta):
3233
"""Meta class for WidgetPollSchema options."""
3334

3435
model = PollModel # The model representing Widget Poll.
36+
include_fk = True
3537
fields = ('id', 'title', 'description', 'status', 'widget_id', 'engagement_id', 'answers')
3638

3739
answers = Nested(PollAnswerSchema, many=True)

api/src/api/schemas/widget_timeline.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,29 @@
1616
from api.models.widget_timeline import WidgetTimeline as WidgetTimelineModel
1717
from api.models.timeline_event import TimelineEvent as TimelineEventModel
1818

19-
from marshmallow import Schema
2019
from marshmallow_sqlalchemy.fields import Nested
20+
from .base_schema import BaseSchema
2121

2222

23-
class TimelineEventSchema(Schema): # pylint: disable=too-many-ancestors, too-few-public-methods
23+
class TimelineEventSchema(BaseSchema): # pylint: disable=too-many-ancestors, too-few-public-methods
2424
"""This is the schema for the timeline event model."""
2525

26-
class Meta: # pylint: disable=too-few-public-methods
26+
class Meta(BaseSchema.Meta): # pylint: disable=too-few-public-methods
2727
"""All of the fields in the Timeline Event schema."""
2828

2929
model = TimelineEventModel
30+
include_fk = True
3031
fields = ('id', 'engagement_id', 'widget_id', 'timeline_id', 'description', 'time', 'position', 'status')
3132

3233

33-
class WidgetTimelineSchema(Schema): # pylint: disable=too-many-ancestors, too-few-public-methods
34+
class WidgetTimelineSchema(BaseSchema): # pylint: disable=too-many-ancestors, too-few-public-methods
3435
"""This is the schema for the widget timeline model."""
3536

36-
class Meta: # pylint: disable=too-few-public-methods
37+
class Meta(BaseSchema.Meta): # pylint: disable=too-few-public-methods
3738
"""All of the fields in the Widget Timeline schema."""
3839

3940
model = WidgetTimelineModel
41+
include_fk = True
4042
fields = ('id', 'engagement_id', 'widget_id', 'title', 'description', 'events')
4143

4244
events = Nested(TimelineEventSchema, many=True)

api/src/api/schemas/widget_video.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515

1616
from api.models.widget_video import WidgetVideo as WidgetVideoModel
1717

18-
from marshmallow import Schema
18+
from .base_schema import BaseSchema
1919

2020

21-
class WidgetVideoSchema(Schema): # pylint: disable=too-many-ancestors, too-few-public-methods
21+
class WidgetVideoSchema(BaseSchema): # pylint: disable=too-many-ancestors, too-few-public-methods
2222
"""This is the schema for the video model."""
2323

24-
class Meta: # pylint: disable=too-few-public-methods
24+
class Meta(BaseSchema.Meta): # pylint: disable=too-few-public-methods
2525
"""Videos all of the Widget Video fields to a default schema."""
2626

2727
model = WidgetVideoModel
28+
include_fk = True
2829
fields = ('id', 'widget_id', 'engagement_id', 'video_url', 'description')

api/tests/unit/services/test_engagement.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ def test_patch_engagement(session, monkeypatch): # pylint:disable=unused-argume
104104
assert updated_engagement_record.created_date.strftime(date_format) == engagement_edits.get('created_date')
105105

106106

107-
def test_delete_success(session, mocker):
107+
def test_delete_success(session, mocker, monkeypatch):
108108
"""Assert that an engagement can be deleted."""
109+
monkeypatch.setenv('ENV', 'dev')
109110
eng = factory_engagement_model(status=Status.Draft.value)
110111
db.session.add(eng)
111112
db.session.commit()
@@ -116,8 +117,9 @@ def test_delete_success(session, mocker):
116117
assert isinstance(result, dict) and result.get('id') == eid
117118

118119

119-
def test_delete_failure_engagement_published(session, mocker):
120+
def test_delete_failure_engagement_published(session, mocker, monkeypatch):
120121
"""Assert that an engagement cannot be deleted if it is published."""
122+
monkeypatch.setenv('ENV', 'dev')
121123
eng = factory_engagement_model(status=Status.Published.value)
122124
db.session.add(eng)
123125
db.session.commit()

0 commit comments

Comments
 (0)