diff --git a/importers/jchat_importer.py b/importers/jchat_importer.py index 5933c804c..1ca0272a1 100644 --- a/importers/jchat_importer.py +++ b/importers/jchat_importer.py @@ -140,9 +140,11 @@ def _read_message_div(self, div, data_store, datafile, change_id): platform_element = text_blocks[0][1] msg_content_element = text_blocks[0][2:] - if time_element is None: + if not text_blocks[0] or len(text_blocks[0]) < 3: self.errors.append( - {self.error_type: f"Unable to read message {msg_id}. No timestamp provided"} + { + self.error_type: f"Unable to read message {msg_id}. Not enough parts (expecting timestamp, platform, message)" + } ) return @@ -150,23 +152,13 @@ def _read_message_div(self, div, data_store, datafile, change_id): timestamp = self.parse_timestamp(time_string, msg_id) time_element.record(self.name, "timestamp", timestamp) - if platform_element is None: - self.errors.append( - {self.error_type: f"Unable to read message {msg_id}. No platform provided"} - ) - return platform_quad = platform_element.text[0:4] platform_element.record(self.name, "platform", platform_quad) # Match on quadgraphs platform = self.get_cached_platform_from_quad(data_store, platform_quad, change_id) - if not msg_content_element: - self.errors.append( - {self.error_type: f"Unable to read message {msg_id}. No message provided"} - ) - return msg_content = self.parse_message_content(msg_content_element) - print(msg_content) + if not msg_content: self.errors.append({self.error_type: f"Unable to parse JChat message {msg_id}."}) return diff --git a/tests/test_load_jchat.py b/tests/test_load_jchat.py index d95def3ff..97832efe7 100644 --- a/tests/test_load_jchat.py +++ b/tests/test_load_jchat.py @@ -539,7 +539,7 @@ def test_invalid_missing_timestamp(self): check_errors_for_file_contents( html_string, - "Unable to read message 34544=34534. No timestamp provided", + "Unable to read message 34544=34534. Not enough parts (expecting timestamp, platform, message)", importer, "no_timestamp.html", ) @@ -590,7 +590,7 @@ def test_invalid_missing_platform(self): check_errors_for_file_contents( html_string, - "Unable to read message 34544=34534. No platform provided", + "Unable to read message 34544=34534. Not enough parts (expecting timestamp, platform, message)", importer, "no_platform.html", ) @@ -615,7 +615,7 @@ def test_invalid_missing_message(self): check_errors_for_file_contents( html_string, - "Unable to read message 34544=34534. No message provided", + "Unable to read message 34544=34534. Not enough parts (expecting timestamp, platform, message)", importer, "no_message", ) @@ -640,7 +640,10 @@ def test_empty_message(self): importer = JChatImporter() check_errors_for_file_contents( - html_string, "Unable to parse JChat message 34544=34534.", importer, "no_message" + html_string, + "Unable to read message 34544=34534. Not enough parts (expecting timestamp, platform, message)", + importer, + "no_message", ) @staticmethod