Skip to content

Commit

Permalink
WCM-285: replace overscrolling model field with existing date_created
Browse files Browse the repository at this point in the history
  • Loading branch information
stollero committed Sep 24, 2024
1 parent 0941314 commit b5c5a59
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 108 deletions.
9 changes: 2 additions & 7 deletions core/src/zeit/connector/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ class DevelopmentCommonMetadata:
access = mapped_column(Unicode, index=True, info={'namespace': 'document', 'name': 'access'})


class DevelopmentZeitWeb:
overscrolling_enabled = mapped_column(
Boolean, info={'namespace': 'document', 'name': 'overscrolling'}
)


class ContentBase:
__abstract__ = True
__tablename__ = 'properties'
Expand Down Expand Up @@ -229,6 +223,8 @@ def from_webdav(self, props):
continue
if ns == INTERNAL_PROPERTY:
continue
if isinstance(v, datetime):
continue
unsorted[ns.replace(self.NS, '', 1)][k] = v
self.unsorted = unsorted

Expand Down Expand Up @@ -299,7 +295,6 @@ class DevelopmentContent(
PublishInfo,
SemanticChange,
DevelopmentCommonMetadata,
DevelopmentZeitWeb,
):
lock_class = 'LockWithMetadataColumns'

Expand Down
20 changes: 13 additions & 7 deletions core/src/zeit/connector/tests/test_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,23 +889,29 @@ class ContractZopeSQL(
class ContractProperties:
def setUp(self):
super().setUp()
FEATURE_TOGGLES.set('read_metadata_columns', 'True')
FEATURE_TOGGLES.set('write_metadata_columns', 'True')
FEATURE_TOGGLES.set('read_metadata_columns', True)
FEATURE_TOGGLES.set('write_metadata_columns', True)
self.repository['testcontent'] = ExampleContentType()

def test_converts_scalar_types_on_read(self):
example_date = datetime(2010, 1, 1, 0, 0, tzinfo=pytz.UTC)
self.repository.connector.changeProperties(
'http://xml.zeit.de/testcontent',
{('overscrolling', 'http://namespaces.zeit.de/CMS/document'): True},
{('date_created', 'http://namespaces.zeit.de/CMS/document'): example_date},
)
self.assertEqual(
example_date,
zeit.cms.workflow.interfaces.IModified(self.repository['testcontent']).date_created,
)
self.assertIs(True, self.repository['testcontent'].overscrolling)

def test_converts_scalar_types_on_write(self):
example_date = datetime(2010, 1, 1, 0, 0, tzinfo=pytz.UTC)
with checked_out(self.repository['testcontent']) as co:
co.overscrolling = True
zeit.cms.workflow.interfaces.IModified(co).date_created = example_date
resource = self.repository.connector['http://xml.zeit.de/testcontent']
self.assertIs(
True, resource.properties[('overscrolling', 'http://namespaces.zeit.de/CMS/document')]
self.assertEqual(
example_date,
resource.properties[('date_created', 'http://namespaces.zeit.de/CMS/document')],
)


Expand Down
94 changes: 0 additions & 94 deletions core/src/zeit/connector/tests/test_postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,100 +356,6 @@ def test_search_looks_in_columns_or_unsorted_depending_on_toggle(self):
self.assertEqual(res.id, unique_id)


class ChannelsColumnTest(zeit.connector.testing.SQLTest):
layer = zeit.connector.testing.SQL_CONTENT_LAYER

def setUp(self):
super().setUp()
FEATURE_TOGGLES.set('read_metadata_columns', True)
FEATURE_TOGGLES.set('write_metadata_columns', True)

def _make_resource(self, channels):
res = self.add_resource('foo', properties={('channels', DOCUMENT_SCHEMA_NS): channels})
return self.connector._get_content(res.id)

def assert_channels(self, channels, expected_channels, expected_dav_channels):
self.assertEqual(channels, expected_channels)
res = self.connector['http://xml.zeit.de/testing/foo']
self.assertEqual(expected_dav_channels, res.properties[('channels', DOCUMENT_SCHEMA_NS)])

def test_modify_channels(self):
content = self._make_resource('channel1;channel2 sub1 sub2')
self.assertEqual(content.channels, {'channel1': [], 'channel2': ['sub1', 'sub2']})
self.connector.changeProperties(
content.uniqueid, {('channels', DOCUMENT_SCHEMA_NS): 'channel2'}
)
content = self.connector._get_content(content.uniqueid)
self.assertEqual(content.channels, {'channel2': []})

def test_empty_input(self):
channels = ''
content = self._make_resource(channels)
self.assert_channels(content.channels, {}, channels)

def test_single_channel(self):
channels = 'channel1'
content = self._make_resource(channels)
self.assert_channels(content.channels, {'channel1': []}, channels)

def test_multiple_channels(self):
channels = 'channel1;channel2;channel3'
content = self._make_resource(channels)
self.assert_channels(
content.channels, {'channel1': [], 'channel2': [], 'channel3': []}, channels
)

def test_single_channel_with_subchannels(self):
channels = 'channel1 sub1 sub2'
content = self._make_resource(channels)
self.assert_channels(content.channels, {'channel1': ['sub1', 'sub2']}, channels)

def test_same_channel_with_subchannels(self):
channels = 'channel1 sub1;channel1 sub2 sub3;channel1 sub4'
content = self._make_resource(channels)
self.assert_channels(
content.channels,
{'channel1': ['sub1', 'sub2', 'sub3', 'sub4']},
'channel1 sub1 sub2 sub3 sub4',
)

def test_multiple_channels_with_subchannels(self):
channels = 'channel1 sub1;channel2 sub2 sub3;channel3 sub4'
content = self._make_resource(channels)
self.assert_channels(
content.channels,
{'channel1': ['sub1'], 'channel2': ['sub2', 'sub3'], 'channel3': ['sub4']},
channels,
)

def test_whitespace_handling(self):
channels = ' channel1 sub1 ; channel2 sub2 sub3 ; channel3 sub4 '
content = self._make_resource(channels)
self.assert_channels(
content.channels,
{'channel1': ['sub1'], 'channel2': ['sub2', 'sub3'], 'channel3': ['sub4']},
'channel1 sub1;channel2 sub2 sub3;channel3 sub4',
)

def test_trailing_semicolon(self):
channels = 'channel1;channel2;'
content = self._make_resource(channels)
self.assert_channels(content.channels, {'channel1': [], 'channel2': []}, channels[:-1])

def test_leading_semicolon(self):
channels = ';channel1;channel2'
content = self._make_resource(channels)
self.assert_channels(content.channels, {'channel1': [], 'channel2': []}, channels[1:])

def test_multiple_semicolons(self):
content = self._make_resource('channel1;;channel2;;;channel3')
self.assert_channels(
content.channels,
{'channel1': [], 'channel2': [], 'channel3': []},
'channel1;channel2;channel3',
)


class WorkflowColumnsTest(zeit.connector.testing.SQLTest):
layer = zeit.connector.testing.SQL_CONTENT_LAYER

Expand Down

0 comments on commit b5c5a59

Please sign in to comment.