Skip to content

Commit

Permalink
Update and modify files for the project
Browse files Browse the repository at this point in the history
- Updated files:
  - pdm.lock
  - pyproject.toml
  - src/bee_py/bee.py
  - src/bee_py/utils/type.py
  - tests/unit/test_bee.py
  • Loading branch information
Aviksaikat committed Dec 15, 2023
1 parent 6917ce4 commit 1c5de33
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 48 deletions.
85 changes: 45 additions & 40 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ docstring-convention = "google"
[tool.mypy]
exclude = ["build/", "dist/", "docs/", "funky_experiments/*", "noxfile.py"]
check_untyped_defs = true
plugins = ["pydantic.mypy"]

[tool.mypy-pytest]
ignore_missing_imports = true
Expand Down
8 changes: 8 additions & 0 deletions src/bee_py/bee.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@
from bee_py.utils.eth import make_eth_address, make_hex_eth_address
from bee_py.utils.type import (
add_cid_conversion_function,
assert_address_prefix,
assert_all_tags_options,
assert_batch_id,
assert_collection_upload_options,
assert_data,
assert_directory,
assert_feed_type,
assert_file_data,
Expand Down Expand Up @@ -625,6 +627,9 @@ def get_all_tags(self, options: Optional[AllTagsOptions] = None) -> list[Tag]:
assert_all_tags_options(options)
assert_request_options(options)

if isinstance(options, dict):
options = AllTagsOptions.model_validate(options)

if options.offset and options.limit:
return tag_api.get_all_tags(self.__get_request_options_for_call(options), options.offset, options.limit)
elif options.offset:
Expand Down Expand Up @@ -954,6 +959,9 @@ def pss_send(
"""

assert_request_options(options)
assert_data(data)
assert_batch_id(postage_batch_id)
assert_address_prefix(target)

if not isinstance(topic, Topic) or not isinstance(topic, str):
msg = "topic has to be an string or Topic type!"
Expand Down
6 changes: 6 additions & 0 deletions src/bee_py/utils/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,9 @@ def assert_directory(directory: Any) -> None:
if directory == "":
msg = "directory must not be empty string!"
raise TypeError(msg)


def assert_data(value: Any) -> None:
if not isinstance(value, str) and not isinstance(value, bytes):
msg = "Data must be either string or bytes"
raise TypeError(msg)
16 changes: 8 additions & 8 deletions tests/unit/test_bee.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from bee_py.bee import Bee
from bee_py.feed.topic import make_topic_from_string

# from bee_py.feed.type import FeedType
from bee_py.types.type import (
CHUNK_SIZE,
Expand Down Expand Up @@ -191,7 +192,7 @@
(float("inf"), TypeError),
("ZZZf", TypeError),
("0x634f", TypeError),
("1236412", BeeArgumentError),
("1236412", TypeError),
]

public_key_assertions: list[tuple] = [
Expand All @@ -210,10 +211,10 @@
({}, TypeError),
(None, TypeError),
(None, TypeError),
(float("inf"), pydantic.ValidationError),
(float("-inf"), pydantic.ValidationError),
(float("nan"), pydantic.ValidationError),
(float("inf"), pydantic.ValidationError),
(float("inf"), TypeError),
(float("-inf"), TypeError),
(float("nan"), TypeError),
(float("inf"), TypeError),
]


Expand Down Expand Up @@ -614,6 +615,7 @@ def test_get_all_tags_invalid_limit(invalid_limit, expected_exception):
bee.get_all_tags({"limit": invalid_limit}) # type: ignore


# ! WHY god
@pytest.mark.parametrize(
"invalid_offset, expected_exception",
[
Expand Down Expand Up @@ -695,7 +697,6 @@ def test_pss_send_request_options_assertion(input_value, expected_error_type, te
bee.pss_send(test_batch_id, "topic", "123", "data", "", input_value)


#! Fix the errors
@pytest.mark.parametrize("input_value, expected_error_type", batch_id_assertion_data)
def test_pss_send_batch_id_assertion(input_value, expected_error_type):
bee = Bee(MOCK_SERVER_URL)
Expand All @@ -710,7 +711,6 @@ def test_pss_send_data_assertion(input_value, expected_error_type, test_batch_id
bee.pss_send(test_batch_id, "topic", "123", input_value)


#! Fix the errors
@pytest.mark.parametrize("input_value, expected_error_type", address_prefix_assertions)
def test_pss_send_address_prefix_assertion(input_value, expected_error_type, test_batch_id):
bee = Bee(MOCK_SERVER_URL)
Expand All @@ -725,7 +725,7 @@ def test_pss_send_public_key_assertion(input_value, expected_error_type, test_ba
bee.pss_send(test_batch_id, "topic", "123", "data", input_value)


#! Fix the errors
# ! Fix the errors
@pytest.mark.parametrize("input_value, expected_error_type", topic_assertions)
def test_pss_send_topic_assertion(input_value, expected_error_type, test_batch_id):
bee = Bee(MOCK_SERVER_URL)
Expand Down

0 comments on commit 1c5de33

Please sign in to comment.