-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from jjjermiah/46-feature-get_collection_descr…
…iptions feat: add getCollectionDescriptions method, with tests, and updated d…
- Loading branch information
Showing
6 changed files
with
173 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .nbia_endpoints import NBIA_ENDPOINTS | ||
from .md5 import validateMD5 | ||
|
||
__all__ = ["NBIA_ENDPOINTS", "validateMD5"] | ||
from .parsers import convertMillis, clean_html | ||
__all__ = ["NBIA_ENDPOINTS", "validateMD5", "convertMillis", "clean_html"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from bs4 import BeautifulSoup | ||
from datetime import datetime | ||
|
||
|
||
def clean_html(html_string: str) -> str: | ||
""" | ||
Cleans the given HTML string by removing HTML tags and replacing special characters. | ||
Args: | ||
html_string (str): The input HTML string to be cleaned. | ||
Returns: | ||
str: The cleaned text content without HTML tags and special characters. | ||
""" | ||
assert isinstance(html_string, str), "The input must be a string" | ||
assert html_string != "", "The input string cannot be empty" | ||
soup = BeautifulSoup(html_string, 'html.parser') | ||
text_content = soup.get_text(separator=' ', strip=True) | ||
text_content = text_content.replace('\xa0', ' ') | ||
return text_content | ||
|
||
|
||
from datetime import datetime | ||
|
||
def convertMillis(millis: int) -> str: | ||
""" | ||
Convert milliseconds to a formatted date string. | ||
Args: | ||
millis (int): The number of milliseconds to convert. | ||
Returns: | ||
str: The formatted date string in the format 'YYYY-MM-DD'. | ||
Raises: | ||
AssertionError: If the input is not an integer. | ||
""" | ||
assert isinstance(millis, int), "The input must be an integer" | ||
return datetime.fromtimestamp(millis / 1000.0).strftime('%Y-%m-%d') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
from numpy import exp | ||
from src.nbiatoolkit.utils.parsers import clean_html, convertMillis | ||
from datetime import datetime | ||
import pytest | ||
def test_clean_html_valid_input(): | ||
# Test case for valid input with HTML tags and special characters | ||
html_string = "<p>This is <b>bold</b> text with special characters: & < ></p>" | ||
expected_output = "This is bold text with special characters: & < >" | ||
assert clean_html(html_string) == expected_output | ||
|
||
def test_clean_html_empty_input(): | ||
# Test case for empty input string | ||
html_string = "" | ||
expected_output = "" | ||
with pytest.raises(AssertionError) as e: | ||
clean_html(html_string) | ||
|
||
def test_clean_html_no_html_tags(): | ||
# Test case for input string without any HTML tags | ||
html_string = "This is a plain text without any HTML tags" | ||
expected_output = "This is a plain text without any HTML tags" | ||
assert clean_html(html_string) == expected_output | ||
|
||
def test_clean_html_special_characters_only(): | ||
# Test case for input string with only special characters | ||
html_string = "& < >" | ||
expected_output = "& < >" | ||
assert clean_html(html_string) == expected_output | ||
|
||
|
||
def test_convertMillis_valid_input(): | ||
# Test case for valid input | ||
target_date = datetime(2021, 9, 1) | ||
millis = int(target_date.timestamp() * 1000) | ||
expected_output = "2021-09-01" | ||
assert convertMillis(millis) == expected_output | ||
|
||
def test_convertMillis_invalid_input(): | ||
# Test case for invalid input | ||
millis = "1630444800000" # Invalid input: string instead of integer | ||
try: | ||
convertMillis(millis) # type: ignore | ||
assert False, "Expected AssertionError" | ||
except AssertionError as e: | ||
assert str(e) == "The input must be an integer" |