Skip to content

Commit

Permalink
✅ tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
YousefEZ committed Dec 26, 2023
1 parent 2ce6777 commit d156c64
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 4 deletions.
12 changes: 12 additions & 0 deletions tests/routes/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,17 @@
},
"unknown_type": {
"type": "unknown"
},
"missing_colour": {
"type": "message",
"embed": {
"title": "Missing Colour",
"fields": [
{
"name": "Missing Colour",
"value": "Missing Colour"
}
]
}
}
}
2 changes: 2 additions & 0 deletions tests/routes/error.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@
</components>
</view>
</message>
<unknown key="unknown_type">
</unknown>
</discord>
22 changes: 21 additions & 1 deletion tests/routes/jinja-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
{% endfor %}
</value>
</field>
<footer>
</footer>
</embed>
</expansive>
<expansive page_number_key="%s" key="test4">
Expand All @@ -69,7 +71,7 @@
</field>
</embed>
</expansive>
<expansive key="test5">
<expansive page_number_key="%s" key="test5">
<timeout>150</timeout>
<embed>
<title>T</title>
Expand All @@ -81,6 +83,24 @@
{% for i in range(0, 6025) %}X{% endfor %}
</value>
</field>
<footer>
<text>T</text>
</footer>
</embed>
</expansive>
<expansive page_number_key="%s" key="test6">
<timeout>150</timeout>
<embed>
<title>Test Title</title>
<colour>teal</colour>
<field>
<name>%s</name>
<value>
{% for i in range(0, 1500) %}
T
{% endfor %}
</value>
</field>
</embed>
</expansive>
</discord>
8 changes: 7 additions & 1 deletion tests/unit/test_json_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ def test_message_type_error(self):
template = "tests/routes/error.json"

renderer: Renderer[ErrorEmbeds] = Renderer(Formatter(), template)
self.assertRaises(KeyError, renderer.render, "unknown_type")
self.assertRaises(TypeError, renderer.render, "unknown_type")

def test_missing_colour(self):
template = "tests/routes/error.json"

renderer: Renderer[ErrorEmbeds] = Renderer(Formatter(), template)
self.assertRaises(ValueError, renderer.render, "missing_colour")

@mock.patch("asyncio.get_running_loop")
def test_menu(self, mock_view: mock.mock.MagicMock):
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_qalib_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,16 @@ async def error(modal: discord.ui.Modal, interaction: discord.Interaction, excep
})
await qalib_modal.on_error(MockedInteraction(), Exception())
self.assertTrue(errored)

async def test_button_callback(self, *_: mock.mock.MagicMock):
invoked = False

async def callback(interaction: discord.Interaction):
nonlocal invoked
invoked = True

renderer: Renderer[str] = Renderer(Formatter(), "tests/routes/full_embeds.xml")
message = renderer.render("test_key2", keywords={"todays_date": datetime.datetime.now()},
callbacks={"button1": callback})
await message.view.children[0].callback(MockedInteraction())
self.assertTrue(invoked)
12 changes: 12 additions & 0 deletions tests/unit/test_xml_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ def test_emoji_error(self, _: mock.mock.MagicMock):
renderer: Renderer[ErrorEmbeds] = Renderer(Formatter(), path)
self.assertRaises(ValueError, renderer.render, "test1")

def test_unknown_type_error(self, _: mock.mock.MagicMock):
path = "tests/routes/error.xml"
renderer: Renderer[ErrorEmbeds] = Renderer(Formatter(), path)
self.assertRaises(TypeError, renderer.render, "unknown_type")

def test_element_error(self, _: mock.mock.MagicMock):
path = "tests/routes/error.xml"
renderer: Renderer[ErrorEmbeds] = Renderer(Formatter(), path)
Expand Down Expand Up @@ -154,6 +159,13 @@ def test_expansive_with_static_elements(self, _: mock.mock.MagicMock):
message = renderer.render("test5")
self.assertEqual(len(message), 2)

def test_expansive_no_footer(self, _: mock.mock.MagicMock):
template = "tests/routes/jinja-test.xml"

renderer: Renderer[JinjaEmbeds] = Renderer(Jinja2(), template)
message = renderer.render("test6")
self.assertEqual(len(message), 2)

def test_expansive_message_with_timeout(self, _: mock.mock.MagicMock):
renderer: Renderer[JinjaEmbeds] = Renderer(Jinja2(), "tests/routes/jinja-test.xml")
message = renderer.render("test4")
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"message_reference_test3",
]

ErrorEmbeds = Literal["test1", "test2", "menu_type", "unknown_type"]
JinjaEmbeds = Literal["test1", "test2", "test3", "test4", "test5"]
ErrorEmbeds = Literal["test1", "test2", "menu_type", "unknown_type", "missing_colour"]
JinjaEmbeds = Literal["test1", "test2", "test3", "test4", "test5", "test6"]
Menus = Literal["Menu1", "Menu2", "Menu3", "Menu4"]
Modals = Literal["modal1", "modal2"]
CompleteJSONMessages = Literal[
Expand Down

0 comments on commit d156c64

Please sign in to comment.