Skip to content

Commit

Permalink
fix ninjs formatter type matching (#244)
Browse files Browse the repository at this point in the history
* fix ninjs formatter type matching

* fix style
  • Loading branch information
petrjasek authored May 20, 2024
1 parent ad5e093 commit c575b12
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
1 change: 0 additions & 1 deletion server/cp/output/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from .formatter.jimi import JimiFormatter # noqa
from .formatter.newsmlg2 import CPNewsMLG2Formatter # noqa
from .formatter.cp_ninjs_formatter import CPNINJSFormatter # noqa
from .formatter.semaphore import SemaphoreFormatter # noqa
from .formatter.jimi_2 import Jimi2Formatter # noqa
from .formatter.ninjs_formatter_2 import NINJSFormatter_2 # noqa
from .formatter.cp_ninjs_newsroom_formatter import CPNewsroomNinjsFormatter # noqa
Expand Down
1 change: 0 additions & 1 deletion server/cp/output/formatter/cp_ninjs_newsroom_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class CPNewsroomNinjsFormatter(NewsroomNinjsFormatter):
type = "cp newsroom ninjs"

def __init__(self):
self.format_type = "cp newsroom ninjs"
self.can_preview = False
self.can_export = False
self.internal_renditions = ["original", "viewImage", "baseImage"]
Expand Down
15 changes: 0 additions & 15 deletions server/cp/output/formatter/ninjs_formatter_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ class NINJSFormatter_2(Formatter):
)

def __init__(self):
self.format_type = "ninjs"
self.can_preview = True
self.can_export = True
self.internal_renditions = ["original"]
Expand Down Expand Up @@ -415,9 +414,6 @@ def _generate_renditions(self, article):
renditions["thumbnail"] = {"href": article["thumbnail"]}
return renditions

def can_format(self, format_type, article):
return format_type == self.format_type

def _get_type(self, article):
if article[ITEM_TYPE] == CONTENT_TYPE.PREFORMATTED:
return CONTENT_TYPE.TEXT
Expand Down Expand Up @@ -916,13 +912,6 @@ def _format_signal(self, signal):
scheme=SCHEME_MAP.get(scheme) or scheme,
)

def export(self, item):
if self.can_format(self.format_type, item):
sequence, formatted_doc = self.format(item, {"_id": "0"}, None)[0]
return formatted_doc.replace("''", "'")
else:
raise Exception()


class NINJS2Formatter(NINJSFormatter_2):
"""NINJS formatter v2
Expand All @@ -947,10 +936,6 @@ class NINJS2Formatter(NINJSFormatter_2):
"rewrite_of",
)

def __init__(self):
super().__init__()
self.format_type = "ninjs3"

def _transform_to_ninjs(self, article, subscriber, recursive=True):
ninjs = super()._transform_to_ninjs(article, subscriber, recursive)

Expand Down
10 changes: 10 additions & 0 deletions server/tests/output/formatter/cp_ninjs_formatter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ def test_subject_relevance(mock):
ninjs = formatter._transform_to_ninjs(item, {})
assert ninjs["subject"][0]["relevance"] == 54
assert ninjs["subject"][0]["creator"] == "Machine"


def test_author_email():
author_ref = {
"name": "John Doe",
}
user = {"email": "[email protected]"}
formatter = CPNINJSFormatter()
author = formatter._format_author(author_ref, user, job_titles_map={})
assert author.get("email") == user["email"]

0 comments on commit c575b12

Please sign in to comment.