From b16ca1427d92d94275f1fc3bdd2e724886b1ee9f Mon Sep 17 00:00:00 2001 From: Nick Moreton Date: Wed, 8 Dec 2021 17:20:17 +0000 Subject: [PATCH 1/3] refactor date getters if post_modified_gmt is not available in the XML return wp:post_date_gmt --- wagtail_wordpress_import/importers/wordpress.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wagtail_wordpress_import/importers/wordpress.py b/wagtail_wordpress_import/importers/wordpress.py index 8af5f174..41a6d212 100644 --- a/wagtail_wordpress_import/importers/wordpress.py +++ b/wagtail_wordpress_import/importers/wordpress.py @@ -357,10 +357,16 @@ def cleaned_first_published_at(self): return self.clean_date(self.node["wp:post_date_gmt"].strip()) def cleaned_last_published_at(self): - return self.clean_date(self.node["wp:post_modified_gmt"].strip()) + try: + return self.clean_date(self.node["wp:post_modified_gmt"].strip()) + except KeyError: + return self.cleaned_first_published_at() def cleaned_latest_revision_created_at(self): - return self.clean_date(self.node["wp:post_modified_gmt"].strip()) + try: + return self.clean_date(self.node["wp:post_modified_gmt"].strip()) + except KeyError: + return self.cleaned_first_published_at() def clean_date(self, value): """ From 4daec4fa1fcbd41f8f798ba246356df85f23dec8 Mon Sep 17 00:00:00 2001 From: Nick Moreton Date: Wed, 8 Dec 2021 17:57:22 +0000 Subject: [PATCH 2/3] alter xml fixture Item with title: Item two title is not currently used in other tests. Change the date fields to remove the wp:post_modified and post_modified_gmt --- wagtail_wordpress_import/test/fixtures/raw_xml.xml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/wagtail_wordpress_import/test/fixtures/raw_xml.xml b/wagtail_wordpress_import/test/fixtures/raw_xml.xml index 1a4f5784..a77e8a1b 100644 --- a/wagtail_wordpress_import/test/fixtures/raw_xml.xml +++ b/wagtail_wordpress_import/test/fixtures/raw_xml.xml @@ -161,10 +161,8 @@ Nihil hic munitissimus habendi senatus locus, nihil horum?.</blockquote> Lorem ipsum dolor sit amet 2 - 2010-07-13 12:16:46 - 2010-07-13 16:16:46 - 2010-07-13 12:16:46 - 2010-07-13 16:16:46 + 2010-01-13 12:00:00 + 2010-01-13 16:00:00 open open item-two-title From be81a9ba23d1569175cb54ef47569a0a4d3eee48 Mon Sep 17 00:00:00 2001 From: Nick Moreton Date: Wed, 8 Dec 2021 17:57:56 +0000 Subject: [PATCH 3/3] add a test for new date getters This test that the refactored date getters still return a date --- .../test/tests/test_wordpress_importer.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wagtail_wordpress_import/test/tests/test_wordpress_importer.py b/wagtail_wordpress_import/test/tests/test_wordpress_importer.py index abc519e8..c79bad04 100644 --- a/wagtail_wordpress_import/test/tests/test_wordpress_importer.py +++ b/wagtail_wordpress_import/test/tests/test_wordpress_importer.py @@ -137,6 +137,22 @@ def test_page_field_values_with_yoast_plugin_disbaled(self): "This page has a default description", ) + def test_page_field_values_if_no_post_date_modified(self): + page = self.imported_pages.get(title="Item two title") + print(page) + self.assertEqual(str(page.first_published_at.date()), "2010-01-13") + self.assertEqual(str(page.first_published_at.time()), "16:00:00") + self.assertEqual(str(page.last_published_at.date()), "2010-01-13") + self.assertEqual(str(page.last_published_at.time()), "16:00:00") + self.assertEqual( + str(page.latest_revision_created_at.date()), + "2010-01-13", + ) + self.assertEqual( + str(page.latest_revision_created_at.time()), + "16:00:00", + ) + IMPORTER_RUN_PARAMS_TEST_OVERRIDE_1 = { "app_for_pages": "example",