Skip to content

Commit

Permalink
Use format=None to return raw Python data structure (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Nov 17, 2024
2 parents 861e20f + eeb7af8 commit 186340a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/norwegianblue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def error_404_text(product: str, suggestion: str) -> str:

def norwegianblue(
product: str = "all",
format: str = "pretty",
format: str | None = "pretty",
color: str = "yes",
show_title: bool = False,
) -> str:
) -> str | list[dict]:
"""Call the API and return result"""
if format == "md":
format = "markdown"
Expand Down Expand Up @@ -85,6 +85,9 @@ def norwegianblue(

data: list[dict] = list(res)

if format is None:
return data

if product == "all":
return "\n".join(data)

Expand Down
24 changes: 24 additions & 0 deletions tests/test_norwegianblue.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,30 @@ def test_norwegianblue_formats(
# Assert
assert output.strip() == expected.strip()

@freeze_time("2023-11-23")
@respx.mock
def test_norwegianblue_no_format(self) -> None:
# Arrange
mocked_url = "https://endoflife.date/api/ubuntu.json"
mocked_response = SAMPLE_RESPONSE_JSON_UBUNTU
test_format = None

# Act
respx.get(mocked_url).respond(content=mocked_response)
output = norwegianblue.norwegianblue(product="ubuntu", format=test_format)

# Assert
assert output[0] == {
"cycle": "22.04",
"codename": "Jammy Jellyfish",
"support": "2027-04-02",
"eol": "2032-04-01",
"lts": True,
"latest": "22.04",
"link": "https://wiki.ubuntu.com/JammyJellyfish/ReleaseNotes/",
"releaseDate": "2022-04-21",
}

@mock.patch.dict(os.environ, {"NO_COLOR": "TRUE"})
@respx.mock
@pytest.mark.parametrize(
Expand Down

0 comments on commit 186340a

Please sign in to comment.