Skip to content

Commit 441adfb

Browse files
authored
Rename StructuredText to RichText (contentful#38)
1 parent 19c9764 commit 441adfb

File tree

9 files changed

+854
-261
lines changed

9 files changed

+854
-261
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# CHANGELOG
22

33
## Unreleased
4+
### Changed
5+
* Renamed `StructuredText` to `RichText`.
46

57
## v1.10.2
68
### Added

contentful/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,8 @@ def _request_headers(self):
487487

488488
if self.authorization_as_header:
489489
headers['Authorization'] = 'Bearer {0}'.format(self.access_token)
490-
if self.gzip_encoded:
491-
headers['Accept-Encoding'] = 'gzip'
490+
491+
headers['Accept-Encoding'] = 'gzip' if self.gzip_encoded else 'identity'
492492

493493
return headers
494494

contentful/content_type_field_types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ def coerce(self, value, **kwargs):
144144
return json.loads(json.dumps(value))
145145

146146

147-
class StructuredTextField(BasicField):
147+
class RichTextField(BasicField):
148148
"""
149-
Coerces Structured Text fields and resolves includes for entries included.
149+
Coerces Rich Text fields and resolves includes for entries included.
150150
"""
151151

152152
def _coerce_link(self, value, includes=None, errors=None, resources=None, default_locale='en-US', locale=None):
@@ -215,7 +215,7 @@ def _coerce_block(self, value, includes=None, errors=None, resources=None, defau
215215
return value
216216

217217
def coerce(self, value, includes=None, errors=None, resources=None, default_locale='en-US', locale=None):
218-
"""Coerces Structured Text properly."""
218+
"""Coerces Rich Text properly."""
219219

220220
return self._coerce_block(
221221
value,

fixtures/fields/rich_text.yaml

Lines changed: 570 additions & 0 deletions
Large diffs are not rendered by default.

fixtures/fields/rich_text_lists_with_embeds.yaml

Lines changed: 260 additions & 0 deletions
Large diffs are not rendered by default.

fixtures/fields/structured_text.yaml

Lines changed: 0 additions & 118 deletions
This file was deleted.

fixtures/fields/structured_text_lists_with_embeds.yaml

Lines changed: 0 additions & 122 deletions
This file was deleted.

tests/client_test.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,12 @@ def test_unresolvable_entries_dont_get_included(self):
391391
entry = client.entry('1HR1QvURo4MoSqO0eqmUeO')
392392
self.assertEqual(len(entry.modules), 2)
393393

394-
@vcr.use_cassette('fixtures/fields/structured_text.yaml')
395-
def test_structured_text_field(self):
394+
@vcr.use_cassette('fixtures/fields/rich_text.yaml')
395+
def test_rich_text_field(self):
396396
client = Client(
397397
'jd7yc4wnatx3',
398-
'6256b8ef7d66805ca41f2728271daf27e8fa6055873b802a813941a0fe696248'
398+
'6256b8ef7d66805ca41f2728271daf27e8fa6055873b802a813941a0fe696248',
399+
gzip_encoded=False
399400
)
400401

401402
entry = client.entry('4BupPSmi4M02m0U48AQCSM')
@@ -410,8 +411,8 @@ def test_structured_text_field(self):
410411
embedded_entry_index += 1
411412
self.assertEqual(expected_entry_occurrances, 0)
412413

413-
@vcr.use_cassette('fixtures/fields/structured_text_lists_with_embeds.yaml')
414-
def test_structured_text_field_with_embeds_in_lists(self):
414+
@vcr.use_cassette('fixtures/fields/rich_text_lists_with_embeds.yaml')
415+
def test_rich_text_field_with_embeds_in_lists(self):
415416
client = Client(
416417
'jd7yc4wnatx3',
417418
'6256b8ef7d66805ca41f2728271daf27e8fa6055873b802a813941a0fe696248',

tests/content_type_field_types_test.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
LinkField,
1515
ArrayField,
1616
ObjectField,
17-
StructuredTextField
17+
RichTextField
1818
)
1919

2020

@@ -129,17 +129,17 @@ def test_object_field(self):
129129
self.assertEqual(object_field.coerce([{'foo': 'bar'}, {'baz': 'qux'}]), [{'foo': 'bar'}, {'baz': 'qux'}])
130130

131131

132-
class StructuredTextFieldTest(TestCase):
133-
def test_structured_text_field(self):
134-
st_field = StructuredTextField()
132+
class RichTextFieldTest(TestCase):
133+
def test_rich_text_field(self):
134+
rt_field = RichTextField()
135135

136-
self.assertEqual(repr(st_field), '<StructuredTextField>')
136+
self.assertEqual(repr(rt_field), '<RichTextField>')
137137

138-
# on empty or non structured text field will return the value as is
139-
self.assertEqual(st_field.coerce({}), {})
140-
self.assertEqual(st_field.coerce(123), 123)
138+
# on empty or non rich text field will return the value as is
139+
self.assertEqual(rt_field.coerce({}), {})
140+
self.assertEqual(rt_field.coerce(123), 123)
141141

142-
# on proper structured text field, but without embedded entries will return as is
142+
# on proper rich text field, but without embedded entries will return as is
143143
document = {
144144
"nodeType": "document",
145145
"content": [{
@@ -155,7 +155,7 @@ def test_structured_text_field(self):
155155
}]
156156
}]
157157
}
158-
self.assertEqual(st_field.coerce(document), document)
158+
self.assertEqual(rt_field.coerce(document), document)
159159

160160
# with embedded entries but with errors, will remove the node
161161
document = {
@@ -177,7 +177,7 @@ def test_structured_text_field(self):
177177

178178
errors = [{"details": {"id": "4JJ21pcEI0QSsea20g6K6K"}}]
179179

180-
self.assertEqual(st_field.coerce(document, errors=errors), {
180+
self.assertEqual(rt_field.coerce(document, errors=errors), {
181181
"nodeType": "document",
182182
"content": []
183183
})

0 commit comments

Comments
 (0)