Skip to content

Commit

Permalink
Update and add missing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mplatypus committed Mar 8, 2025
1 parent 54b9e5a commit 89f8900
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 52 deletions.
69 changes: 46 additions & 23 deletions tests/hikari/impl/test_entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5538,12 +5538,13 @@ def test_max_age_when_zero(self, entity_factory_impl, invite_with_metadata_paylo

@pytest.fixture
def action_row_payload(self, button_payload):
return {"type": 1, "components": [button_payload]}
return {"type": 1, "id": 8394572, "components": [button_payload]}

@pytest.fixture
def button_payload(self, custom_emoji_payload):
return {
"type": 2,
"id": 9173652,
"label": "Click me!",
"style": 1,
"emoji": custom_emoji_payload,
Expand All @@ -5552,10 +5553,11 @@ def button_payload(self, custom_emoji_payload):
"disabled": True,
}

def test_deserialize__deserialize_button(self, entity_factory_impl, button_payload, custom_emoji_payload):
def test__deserialize_button(self, entity_factory_impl, button_payload, custom_emoji_payload):
button = entity_factory_impl._deserialize_button(button_payload)

assert button.type is component_models.ComponentType.BUTTON
assert button.id == 9173652
assert button.style is component_models.ButtonStyle.PRIMARY
assert button.label == "Click me!"
assert button.emoji == entity_factory_impl.deserialize_emoji(custom_emoji_payload)
Expand All @@ -5569,6 +5571,7 @@ def test_deserialize__deserialize_button_with_unset_fields(
button = entity_factory_impl._deserialize_button({"type": 2, "style": 5})

assert button.type is component_models.ComponentType.BUTTON
assert button.id is None
assert button.style is component_models.ButtonStyle.LINK
assert button.label is None
assert button.emoji is None
Expand All @@ -5580,6 +5583,7 @@ def test_deserialize__deserialize_button_with_unset_fields(
def select_menu_payload(self, custom_emoji_payload):
return {
"type": 5,
"id": 9830741,
"custom_id": "Not an ID",
"options": [
{
Expand All @@ -5600,6 +5604,7 @@ def test__deserialize_text_select_menu(self, entity_factory_impl, select_menu_pa
menu = entity_factory_impl._deserialize_text_select_menu(select_menu_payload)

assert menu.type is component_models.ComponentType.USER_SELECT_MENU
assert menu.id == 9830741
assert menu.custom_id == "Not an ID"

# SelectMenuOption
Expand All @@ -5622,6 +5627,8 @@ def test__deserialize_text_select_menu_partial(self, entity_factory_impl):
{"type": 3, "custom_id": "Not an ID", "options": [{"label": "Trans", "value": "very trans"}]}
)

assert menu.id is None

# SelectMenuOption
assert len(menu.options) == 1
option = menu.options[0]
Expand All @@ -5636,12 +5643,13 @@ def test__deserialize_text_select_menu_partial(self, entity_factory_impl):

@pytest.fixture
def text_input_payload(self):
return {"type": 4, "custom_id": "name", "value": "Wumpus"}
return {"type": 4, "id": 3904875, "custom_id": "name", "value": "Wumpus"}

def test__deserialize_text_input(self, entity_factory_impl, text_input_payload):
text_input = entity_factory_impl._deserialize_text_input(text_input_payload)

assert text_input.type == component_models.ComponentType.TEXT_INPUT
assert text_input.id == 3904875
assert text_input.custom_id == "name"
assert text_input.value == "Wumpus"

Expand All @@ -5653,47 +5661,41 @@ def media_payload(self):

@pytest.fixture
def text_display_payload(self):
return {"type": 10, "id": "text_display.id", "content": "A text display!"}
return {"type": 10, "id": 9840745, "content": "A text display!"}

@pytest.fixture
def thumbnail_payload(self, media_payload):
return {
"type": 11,
"id": "thumbnail.id",
"id": 9824133,
"media": media_payload,
"description": "A cool description.",
"spoiler": False,
}

@pytest.fixture
def section_payload(self, button_payload, text_display_payload):
return {"type": 9, "id": "section.id", "accessory": button_payload, "components": [text_display_payload]}
return {"type": 9, "id": 9478385, "accessory": button_payload, "components": [text_display_payload]}

@pytest.fixture
def media_gallery_item_payload(self, media_payload):
return {"media": media_payload, "description": "Gallery item description?", "spoiler": True}

@pytest.fixture
def media_gallery_payload(self, media_gallery_item_payload):
return {"type": 12, "id": "media_gallery.id", "items": [media_gallery_item_payload]}
return {"type": 12, "id": 9267351, "items": [media_gallery_item_payload]}

@pytest.fixture
def separator_payload(self):
return {"type": 14, "id": "separator.id", "spacing": 1, "divider": True}
return {"type": 14, "id": 4920478, "spacing": 1, "divider": True}

@pytest.fixture
def file_payload(self, media_payload):
return {"type": 13, "id": "file.id", "file": media_payload, "spoiler": False}
return {"type": 13, "id": 2407385, "file": media_payload, "spoiler": False}

@pytest.fixture
def container_payload(self, file_payload):
return {
"type": 17,
"id": "container.id",
"accent_color": 16757027,
"spoiler": True,
"components": [file_payload],
}
return {"type": 17, "id": 5830957, "accent_color": 16757027, "spoiler": True, "components": [file_payload]}

def test__deserialize_media(self, entity_factory_impl, media_payload):
media = entity_factory_impl._deserialize_media(media_payload)
Expand All @@ -5707,10 +5709,20 @@ def test__deserialize_action_row_component(self, entity_factory_impl, action_row

assert action_row.type == component_models.ComponentType.ACTION_ROW

assert action_row.id == 8394572
assert action_row.components == [entity_factory_impl._deserialize_button(button_payload)]

assert isinstance(action_row, component_models.ActionRowComponent)

def test__deserialize_action_row_component_with_unset_fields(
self, entity_factory_impl, action_row_payload, button_payload
):
del action_row_payload["id"]

action_row = entity_factory_impl._deserialize_action_row_component(action_row_payload)

assert action_row.id is None

def test__deserialize_action_row_component_with_unknown_component_type(
self, entity_factory_impl, action_row_payload
):
Expand All @@ -5726,7 +5738,7 @@ def test__deserialize_section_component(
section = entity_factory_impl._deserialize_section_component(section_payload)

assert section.type == component_models.ComponentType.SECTION
assert section.id == "section.id"
assert section.id == 9478385
assert section.accessory == entity_factory_impl._deserialize_button(button_payload)
assert section.components == [entity_factory_impl._deserialize_text_display_component(text_display_payload)]

Expand All @@ -5750,7 +5762,7 @@ def test__deserialize_thumbnail_component(self, entity_factory_impl, thumbnail_p
thumbnail = entity_factory_impl._deserialize_thumbnail_component(thumbnail_payload)

assert thumbnail.type == component_models.ComponentType.THUMBNAIL
assert thumbnail.id == "thumbnail.id"
assert thumbnail.id == 9824133
assert thumbnail.media == entity_factory_impl._deserialize_media(media_payload)
assert thumbnail.description == "A cool description."
assert thumbnail.spoiler is False
Expand All @@ -5772,7 +5784,7 @@ def test__deserialize_text_display_component(self, entity_factory_impl, text_dis
text_display = entity_factory_impl._deserialize_text_display_component(text_display_payload)

assert text_display.type == component_models.ComponentType.TEXT_DISPLAY
assert text_display.id == "text_display.id"
assert text_display.id == 9840745
assert text_display.content == "A text display!"

assert isinstance(text_display, component_models.TextDisplayComponent)
Expand All @@ -5790,15 +5802,18 @@ def test__deserialize_media_gallery_component(
media_gallery = entity_factory_impl._deserialize_media_gallery_component(media_gallery_payload)

assert media_gallery.type == component_models.ComponentType.MEDIA_GALLERY
assert media_gallery.id == 9267351
assert media_gallery.items == [entity_factory_impl._deserialize_media_gallery_item(media_gallery_item_payload)]

assert isinstance(media_gallery, component_models.MediaGalleryComponent)

def test__deserialize_media_gallery_component_with_unset_fields(self, entity_factory_impl, media_gallery_payload):
del media_gallery_payload["id"]
media_gallery_payload["items"] = []

media_gallery = entity_factory_impl._deserialize_media_gallery_component(media_gallery_payload)

assert media_gallery.id is None
assert media_gallery.items == []

def test__deserialize_media_gallery_item(self, entity_factory_impl, media_gallery_item_payload, media_payload):
Expand All @@ -5823,7 +5838,7 @@ def test__deserialize_separator_component(self, entity_factory_impl, separator_p
separator = entity_factory_impl._deserialize_separator_component(separator_payload)

assert separator.type == component_models.ComponentType.SEPARATOR
assert separator.id == "separator.id"
assert separator.id == 4920478
assert separator.spacing == component_models.SpacingType.SMALL
assert separator.divider is True

Expand All @@ -5844,7 +5859,7 @@ def test__deserialize_file_component(self, entity_factory_impl, file_payload, me
file = entity_factory_impl._deserialize_file_component(file_payload)

assert file.type == component_models.ComponentType.FILE
assert file.id == "file.id"
assert file.id == 2407385
assert file.file == entity_factory_impl._deserialize_media(media_payload)
assert file.spoiler is False

Expand All @@ -5863,7 +5878,7 @@ def test__deserialize_container_component(self, entity_factory_impl, container_p
container = entity_factory_impl._deserialize_container_component(container_payload)

assert container.type == component_models.ComponentType.CONTAINER
assert container.id == "container.id"
assert container.id == 5830957
assert container.accent_color == color_models.Color.from_hex_code("FFB123")
assert container.spoiler is True
assert container.components == [entity_factory_impl._deserialize_file_component(file_payload)]
Expand All @@ -5879,10 +5894,17 @@ def test__deserialize_container_component_with_unset_fields(self, entity_factory
container = entity_factory_impl._deserialize_container_component(container_payload)

assert container.id is None
assert container.accent_color is None
assert container.accent_color is undefined.UNDEFINED
assert container.spoiler is None
assert container.components == []

def test__deserialize_container_component_with_nullable_fields(self, entity_factory_impl, container_payload):
container_payload["accent_color"] = None

container = entity_factory_impl._deserialize_container_component(container_payload)

assert container.accent_color is None

def test__deserialize_container_component_with_unknown_component_type(self, entity_factory_impl, container_payload):
container_payload["components"] = [{"type": 9999}]

Expand Down Expand Up @@ -5939,6 +5961,7 @@ def test__deserialize_modal_components(self, entity_factory_impl, action_row_pay

assert modal_components[0] == component_models.ModalActionRowComponent(
type=component_models.ComponentType.ACTION_ROW,
id=8394572,
components=[entity_factory_impl._deserialize_text_input(text_input_payload)],
)

Expand Down
Loading

0 comments on commit 89f8900

Please sign in to comment.