-
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.
Added Handler - execute command - test
- Loading branch information
Carlota de la Vega
committed
Jun 1, 2024
1 parent
54649b8
commit fab854c
Showing
4 changed files
with
74 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from src import server | ||
|
||
server = server.Server("localhost", 12345) | ||
server.start() | ||
if __name__ == "__main__": | ||
server = server.Server("localhost", 12345) | ||
server.start() |
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
Empty file.
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,65 @@ | ||
import os | ||
import unittest | ||
from unittest.mock import MagicMock | ||
|
||
from src.handler import Handler | ||
|
||
|
||
class TestHandler(unittest.TestCase): | ||
def test_execute_command_generate_number_success(self): | ||
# Arrange | ||
request = { | ||
"command": "generate_number", | ||
"text": "5" | ||
} | ||
expected_file_path = "./data/nums/drawn_number_5.png" | ||
handler = Handler(MagicMock()) | ||
|
||
# Act | ||
handler._execute_command(request) | ||
|
||
# Assert | ||
self.assertTrue(os.path.exists(expected_file_path)) | ||
|
||
# Clean up | ||
os.remove(expected_file_path) | ||
|
||
|
||
def test_execute_command_generate_number_error(self): | ||
# Arrange | ||
request = { | ||
"command": "generate_number", | ||
"text": "abc" | ||
} | ||
expected_response = { | ||
"status": "error", | ||
"message": "Error generating the image: invalid literal for int() with base 10: 'abc'" | ||
} | ||
handler = Handler(MagicMock()) | ||
|
||
# Act | ||
response = handler._execute_command(request) | ||
|
||
# Assert | ||
self.assertEqual(response, expected_response) | ||
|
||
def test_execute_command_unknown_command(self): | ||
# Arrange | ||
request = { | ||
"command": "unknown_command", | ||
"text": "5" | ||
} | ||
expected_response = { | ||
"status": "error", | ||
"message": "Unknown command: unknown_command" | ||
} | ||
handler = Handler(MagicMock()) | ||
|
||
# Act | ||
response = handler._execute_command(request) | ||
|
||
# Assert | ||
self.assertEqual(response, expected_response) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |