diff --git a/README.md b/README.md
index 408249a7..f725d643 100644
--- a/README.md
+++ b/README.md
@@ -1,454 +1,163 @@
-[](http://hug.rest)
-===================
+# Report for Assignment 1
-[](http://badge.fury.io/py/hug)
-[](https://travis-ci.org/hugapi/hug)
-[](https://ci.appveyor.com/project/TimothyCrosley/hug)
-[](https://coveralls.io/github/hugapi/hug?branch=master)
-[](https://pypi.python.org/pypi/hug/)
-[](https://gitter.im/timothycrosley/hug?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
+## Project chosen
-_________________
+Name: Hug by Hug API
-[Read Latest Documentation](https://hugapi.github.io/hug/) - [Browse GitHub Code Repository](https://github.com/hugapi/hug)
-_________________
+URL: https://github.com/hugapi/hug/
-hug aims to make developing Python driven APIs as simple as possible, but no simpler. As a result, it drastically simplifies Python API development.
+Number of lines of code and the tool used to count it: 10.8 KLOC - Lizzard
-hug's Design Objectives:
+Programming language: Python
-- Make developing a Python driven API as succinct as a written definition.
-- The framework should encourage code that self-documents.
-- It should be fast. A developer should never feel the need to look somewhere else for performance reasons.
-- Writing tests for APIs written on-top of hug should be easy and intuitive.
-- Magic done once, in an API framework, is better than pushing the problem set to the user of the API framework.
-- Be the basis for next generation Python APIs, embracing the latest technology.
+## Coverage measurement
-As a result of these goals, hug is Python 3+ only and built upon [Falcon's](https://github.com/falconry/falcon) high performance HTTP library
+### Existing tool
-[](https://github.com/hugapi/hug/blob/develop/examples/hello_world.py)
+We ran coverage.py ; we tested it within the project root to see what functions needed to be improved and then selected 8 functions to make/enhance tests for.
-Supporting hug development
-===================
-[Get professionally supported hug with the Tidelift Subscription](https://tidelift.com/subscription/pkg/pypi-hug?utm_source=pypi-hug&utm_medium=referral&utm_campaign=readme)
+
-Professional support for hug is available as part of the [Tidelift
-Subscription](https://tidelift.com/subscription/pkg/pypi-hug?utm_source=pypi-hug&utm_medium=referral&utm_campaign=readme).
-Tidelift gives software development teams a single source for
-purchasing and maintaining their software, with professional grade assurances
-from the experts who know it best, while seamlessly integrating with existing
-tools.
+### Your own coverage tool
-Installing hug
-===================
+### Individual tests
-Installing hug is as simple as:
+#### Marwan Amrhar,
-```bash
-pip3 install hug --upgrade
-```
+---
-Ideally, within a [virtual environment](http://docs.python-guide.org/en/latest/dev/virtualenvs/).
+- `Localrouter.__init__`
-Getting Started
-===================
+Before:
-Build an example API with a simple endpoint in just a few lines.
+
-```py
-# filename: happy_birthday.py
-"""A basic (single function) API written using hug"""
-import hug
+After:
+
-@hug.get('/happy_birthday')
-def happy_birthday(name, age:hug.types.number=1):
- """Says happy birthday to a user"""
- return "Happy {age} Birthday {name}!".format(**locals())
-```
+---
-To run, from the command line type:
+- `Localrouter.directives`
-```bash
-hug -f happy_birthday.py
-```
+Before:
-You can access the example in your browser at:
-`localhost:8000/happy_birthday?name=hug&age=1`. Then check out the
-documentation for your API at `localhost:8000/documentation`
+
-Parameters can also be encoded in the URL (check
-out [`happy_birthday.py`](examples/happy_birthday.py) for the whole
-example).
+After:
-```py
-@hug.get('/greet/{event}')
-def greet(event: str):
- """Greets appropriately (from http://blog.ketchum.com/how-to-write-10-common-holiday-greetings/) """
- greetings = "Happy"
- if event == "Christmas":
- greetings = "Merry"
- if event == "Kwanzaa":
- greetings = "Joyous"
- if event == "wishes":
- greetings = "Warm"
+
- return "{greetings} {event}!".format(**locals())
-```
+- Fixed a bug with the use of a deprecated function (numpy.unicode -> numpy.str\_);
-Which, once you are running the server as above, you can use this way:
+#### Sajeed Bouziane,
-```
-curl http://localhost:8000/greet/wishes
-"Warm wishes!"
-```
+---
-Versioning with hug
-===================
+- `Localrouter.validate`
-```py
-# filename: versioning_example.py
-"""A simple example of a hug API call with versioning"""
-import hug
+Before:
-@hug.get('/echo', versions=1)
-def echo(text):
- return text
+
+After:
-@hug.get('/echo', versions=range(2, 5))
-def echo(text):
- return "Echo: {text}".format(**locals())
-```
+
-To run the example:
+---
-```bash
-hug -f versioning_example.py
-```
+- `Localrouter.version`
-Then you can access the example from `localhost:8000/v1/echo?text=Hi` / `localhost:8000/v2/echo?text=Hi` Or access the documentation for your API from `localhost:8000`
+Before:
-Note: versioning in hug automatically supports both the version header as well as direct URL based specification.
+
-Testing hug APIs
-===================
+After:
-hug's `http` method decorators don't modify your original functions. This makes testing hug APIs as simple as testing any other Python functions. Additionally, this means interacting with your API functions in other Python code is as straight forward as calling Python only API functions. hug makes it easy to test the full Python stack of your API by using the `hug.test` module:
+
-```python
-import hug
-import happy_birthday
+#### Ayoub Bouazza,
-hug.test.get(happy_birthday, 'happy_birthday', {'name': 'Timothy', 'age': 25}) # Returns a Response object
-```
+---
-You can use this `Response` object for test assertions (check
-out [`test_happy_birthday.py`](examples/test_happy_birthday.py) ):
+- `Localrouter.__call__`
-```python
-def tests_happy_birthday():
- response = hug.test.get(happy_birthday, 'happy_birthday', {'name': 'Timothy', 'age': 25})
- assert response.status == HTTP_200
- assert response.data is not None
-```
+Before:
-Running hug with other WSGI based servers
-===================
+
-hug exposes a `__hug_wsgi__` magic method on every API module automatically. Running your hug based API on any standard wsgi server should be as simple as pointing it to `module_name`: `__hug_wsgi__`.
+After:
-For Example:
+
-```bash
-uwsgi --http 0.0.0.0:8000 --wsgi-file examples/hello_world.py --callable __hug_wsgi__
-```
+---
-To run the hello world hug example API.
+- `Router.__init__`
-Building Blocks of a hug API
-===================
+Before:
-When building an API using the hug framework you'll use the following concepts:
+
-**METHOD Decorators** `get`, `post`, `update`, etc HTTP method decorators that expose your Python function as an API while keeping your Python method unchanged
+After:
-```py
-@hug.get() # <- Is the hug METHOD decorator
-def hello_world():
- return "Hello"
-```
+
-hug uses the structure of the function you decorate to automatically generate documentation for users of your API. hug always passes a request, response, and api_version variable to your function if they are defined params in your function definition.
+#### Yahia Noeman,
-**Type Annotations** functions that optionally are attached to your methods arguments to specify how the argument is validated and converted into a Python type
+---
-```py
-@hug.get()
-def math(number_1:int, number_2:int): #The :int after both arguments is the Type Annotation
- return number_1 + number_2
-```
+- `API.__init__`
-Type annotations also feed into `hug`'s automatic documentation
-generation to let users of your API know what data to supply.
+Before:
-**Directives** functions that get executed with the request / response data based on being requested as an argument in your api_function.
-These apply as input parameters only, and can not be applied currently as output formats or transformations.
+
-```py
-@hug.get()
-def test_time(hug_timer):
- return {'time_taken': float(hug_timer)}
-```
+After:
-Directives may be accessed via an argument with a `hug_` prefix, or by using Python 3 type annotations. The latter is the more modern approach, and is recommended. Directives declared in a module can be accessed by using their fully qualified name as the type annotation (ex: `module.directive_name`).
+
-Aside from the obvious input transformation use case, directives can be used to pipe data into your API functions, even if they are not present in the request query string, POST body, etc. For an example of how to use directives in this way, see the authentication example in the examples folder.
+---
-Adding your own directives is straight forward:
+- `ModuleSingleton.__call__`
-```py
-@hug.directive()
-def square(value=1, **kwargs):
- '''Returns passed in parameter multiplied by itself'''
- return value * value
+Before:
-@hug.get()
-@hug.local()
-def tester(value: square=10):
- return value
+
-tester() == 100
-```
+After:
-For completeness, here is an example of accessing the directive via the magic name approach:
+
-```py
-@hug.directive()
-def multiply(value=1, **kwargs):
- '''Returns passed in parameter multiplied by itself'''
- return value * value
+### Overall
-@hug.get()
-@hug.local()
-def tester(hug_multiply=10):
- return hug_multiply
+---
-tester() == 100
-```
+This is the overall coverage after implementing our unittests:
-**Output Formatters** a function that takes the output of your API function and formats it for transport to the user of the API.
+
-```py
-@hug.default_output_format()
-def my_output_formatter(data):
- return "STRING:{0}".format(data)
+As we can see the coverage of the files api.py, routing.py have been increased, these also contained the functions that we covered.
-@hug.get(output=hug.output_format.json)
-def hello():
- return {'hello': 'world'}
-```
+## Statement of individual contributions
-as shown, you can easily change the output format for both an entire API as well as an individual API call
+First we all together did the lizzard count and overall coverage and figured out how to exactly make a unit test and experimented around with Localrouter since we discovered that this was barely/not tested.
-**Input Formatters** a function that takes the body of data given from a user of your API and formats it for handling.
+Marwan Amrhar:
-```py
-@hug.default_input_format("application/json")
-def my_input_formatter(data):
- return ('Results', hug.input_format.json(data))
-```
+- Figured out a bug which didn't allow us to run the coverage;
+- Figured out how to make unit tests in localrouter and made 2 unit tests in there.
-Input formatters are mapped based on the `content_type` of the request data, and only perform basic parsing. More detailed parsing should be done by the Type Annotations present on your `api_function`
+Sajeed Bouziane
-**Middleware** functions that get called for every request a hug API processes
+- Made 2 more unit tests in localrouter after working together with Marwan;
+- Helped set-up the readme file.
-```py
-@hug.request_middleware()
-def process_data(request, response):
- request.env['SERVER_NAME'] = 'changed'
+Ayoub Bouazza:
-@hug.response_middleware()
-def process_data(request, response, resource):
- response.set_header('MyHeader', 'Value')
-```
+- Made a final unit test in localrouter;
+- Made a unit test for the initialization of the Router class.
-You can also easily add any Falcon style middleware using:
+Yahia Nouman
-```py
-__hug__.http.add_middleware(MiddlewareObject())
-```
-
-**Parameter mapping** can be used to override inferred parameter names, eg. for reserved keywords:
-
-```py
-import marshmallow.fields as fields
-...
-
-@hug.get('/foo', map_params={'from': 'from_date'}) # API call uses 'from'
-def get_foo_by_date(from_date: fields.DateTime()):
- return find_foo(from_date)
-```
-
-Input formatters are mapped based on the `content_type` of the request data, and only perform basic parsing. More detailed parsing should be done by the Type Annotations present on your `api_function`
-
-Splitting APIs over multiple files
-===================
-
-hug enables you to organize large projects in any manner you see fit. You can import any module that contains hug decorated functions (request handling, directives, type handlers, etc) and extend your base API with that module.
-
-For example:
-
-`something.py`
-
-```py
-import hug
-
-@hug.get('/')
-def say_hi():
- return 'hello from something'
-```
-
-Can be imported into the main API file:
-
-`__init__.py`
-
-```py
-import hug
-from . import something
-
-@hug.get('/')
-def say_hi():
- return "Hi from root"
-
-@hug.extend_api('/something')
-def something_api():
- return [something]
-```
-
-Or alternatively - for cases like this - where only one module is being included per a URL route:
-
-```py
-#alternatively
-hug.API(__name__).extend(something, '/something')
-```
-
-Configuring hug 404
-===================
-
-By default, hug returns an auto generated API spec when a user tries to access an endpoint that isn't defined. If you would not like to return this spec you can turn off 404 documentation:
-
-From the command line application:
-
-```bash
-hug -nd -f {file} #nd flag tells hug not to generate documentation on 404
-```
-
-Additionally, you can easily create a custom 404 handler using the `hug.not_found` decorator:
-
-```py
-@hug.not_found()
-def not_found_handler():
- return "Not Found"
-```
-
-This decorator works in the same manner as the hug HTTP method decorators, and is even version aware:
-
-```py
-@hug.not_found(versions=1)
-def not_found_handler():
- return ""
-
-@hug.not_found(versions=2)
-def not_found_handler():
- return "Not Found"
-```
-
-Asyncio support
-===============
-
-When using the `get` and `cli` method decorator on coroutines, hug will schedule
-the execution of the coroutine.
-
-Using asyncio coroutine decorator
-
-```py
-@hug.get()
-@asyncio.coroutine
-def hello_world():
- return "Hello"
-```
-
-Using Python 3.5 async keyword.
-
-```py
-@hug.get()
-async def hello_world():
- return "Hello"
-```
-
-NOTE: Hug is running on top Falcon which is not an asynchronous server. Even if using
-asyncio, requests will still be processed synchronously.
-
-Using Docker
-===================
-
-If you like to develop in Docker and keep your system clean, you can do that but you'll need to first install [Docker Compose](https://docs.docker.com/compose/install/).
-
-Once you've done that, you'll need to `cd` into the `docker` directory and run the web server (Gunicorn) specified in `./docker/gunicorn/Dockerfile`, after which you can preview the output of your API in the browser on your host machine.
-
-```bash
-$ cd ./docker
-# This will run Gunicorn on port 8000 of the Docker container.
-$ docker-compose up gunicorn
-
-# From the host machine, find your Dockers IP address.
-# For Windows & Mac:
-$ docker-machine ip default
-
-# For Linux:
-$ ifconfig docker0 | grep 'inet' | cut -d: -f2 | awk '{ print $1}' | head -n1
-```
-
-By default, the IP is 172.17.0.1. Assuming that's the IP you see, as well, you would then go to `http://172.17.0.1:8000/` in your browser to view your API.
-
-You can also log into a Docker container that you can consider your work space. This workspace has Python and Pip installed so you can use those tools within Docker. If you need to test the CLI interface, for example, you would use this.
-
-```bash
-$ docker-compose run workspace bash
-```
-
-On your Docker `workspace` container, the `./docker/templates` directory on your host computer is mounted to `/src` in the Docker container. This is specified under `services` > `app` of `./docker/docker-compose.yml`.
-
-```bash
-bash-4.3# cd /src
-bash-4.3# tree
-.
-├── __init__.py
-└── handlers
- ├── birthday.py
- └── hello.py
-
-1 directory, 3 files
-```
-
-Security contact information
-===================
-
-hug takes security and quality seriously. This focus is why we depend only on thoroughly tested components and utilize static analysis tools (such as bandit and safety) to verify the security of our code base.
-If you find or encounter any potential security issues, please let us know right away so we can resolve them.
-
-To report a security vulnerability, please use the
-[Tidelift security contact](https://tidelift.com/security).
-Tidelift will coordinate the fix and disclosure.
-
-Why hug?
-===================
-
-HUG simply stands for Hopefully Useful Guide. This represents the project's goal to help guide developers into creating well written and intuitive APIs.
-
---------------------------------------------
-
-Thanks and I hope you find *this* hug helpful as you develop your next Python API!
-
-~Timothy Crosley
+- Made a unit tests for the api.py file which covered the initialization of the api
+- Made a unit test for the api.py file which covered singleton module call function.
diff --git a/hug/output_format.py b/hug/output_format.py
index 6e60dfb3..fad76c7c 100644
--- a/hug/output_format.py
+++ b/hug/output_format.py
@@ -142,7 +142,7 @@ def register_json_converter(function):
def numpy_listable(item):
return item.tolist()
- @json_convert(str, numpy.unicode_)
+ @json_convert(str, numpy.str_)
def numpy_stringable(item):
return str(item)
diff --git a/readme_img/AFTER_UNITTESTS.png b/readme_img/AFTER_UNITTESTS.png
new file mode 100644
index 00000000..5fb9e544
Binary files /dev/null and b/readme_img/AFTER_UNITTESTS.png differ
diff --git a/readme_img/BEFORE_UNITTESTS.png b/readme_img/BEFORE_UNITTESTS.png
new file mode 100644
index 00000000..76e781fc
Binary files /dev/null and b/readme_img/BEFORE_UNITTESTS.png differ
diff --git a/readme_img/after/apiinit_after.png b/readme_img/after/apiinit_after.png
new file mode 100644
index 00000000..156b8ac3
Binary files /dev/null and b/readme_img/after/apiinit_after.png differ
diff --git a/readme_img/after/localroutercall_after.png b/readme_img/after/localroutercall_after.png
new file mode 100644
index 00000000..a1f97667
Binary files /dev/null and b/readme_img/after/localroutercall_after.png differ
diff --git a/readme_img/after/localrouterdirectives_after.png b/readme_img/after/localrouterdirectives_after.png
new file mode 100644
index 00000000..2b30d882
Binary files /dev/null and b/readme_img/after/localrouterdirectives_after.png differ
diff --git a/readme_img/after/localrouterinit_after.png b/readme_img/after/localrouterinit_after.png
new file mode 100644
index 00000000..7097d11b
Binary files /dev/null and b/readme_img/after/localrouterinit_after.png differ
diff --git a/readme_img/after/localroutervalidate_after.png b/readme_img/after/localroutervalidate_after.png
new file mode 100644
index 00000000..f5fb331e
Binary files /dev/null and b/readme_img/after/localroutervalidate_after.png differ
diff --git a/readme_img/after/localrouterversion_after.png b/readme_img/after/localrouterversion_after.png
new file mode 100644
index 00000000..022a950b
Binary files /dev/null and b/readme_img/after/localrouterversion_after.png differ
diff --git a/readme_img/after/modulesingletoncall_after.png b/readme_img/after/modulesingletoncall_after.png
new file mode 100644
index 00000000..9683adde
Binary files /dev/null and b/readme_img/after/modulesingletoncall_after.png differ
diff --git a/readme_img/after/routerinit_after.png b/readme_img/after/routerinit_after.png
new file mode 100644
index 00000000..5c5a3995
Binary files /dev/null and b/readme_img/after/routerinit_after.png differ
diff --git a/readme_img/before/apiinit_before.png b/readme_img/before/apiinit_before.png
new file mode 100644
index 00000000..c08ddcbe
Binary files /dev/null and b/readme_img/before/apiinit_before.png differ
diff --git a/readme_img/before/localroutercall_before.png b/readme_img/before/localroutercall_before.png
new file mode 100644
index 00000000..10f85532
Binary files /dev/null and b/readme_img/before/localroutercall_before.png differ
diff --git a/readme_img/before/localrouterdirectives_before.png b/readme_img/before/localrouterdirectives_before.png
new file mode 100644
index 00000000..ea1109fa
Binary files /dev/null and b/readme_img/before/localrouterdirectives_before.png differ
diff --git a/readme_img/before/localrouterinit_before.png b/readme_img/before/localrouterinit_before.png
new file mode 100644
index 00000000..b522381a
Binary files /dev/null and b/readme_img/before/localrouterinit_before.png differ
diff --git a/readme_img/before/localroutervalidate_before.png b/readme_img/before/localroutervalidate_before.png
new file mode 100644
index 00000000..a1c83955
Binary files /dev/null and b/readme_img/before/localroutervalidate_before.png differ
diff --git a/readme_img/before/localrouterversion_before.png b/readme_img/before/localrouterversion_before.png
new file mode 100644
index 00000000..fbbff4ac
Binary files /dev/null and b/readme_img/before/localrouterversion_before.png differ
diff --git a/readme_img/before/modulesingletoncall_before.png b/readme_img/before/modulesingletoncall_before.png
new file mode 100644
index 00000000..8c019eeb
Binary files /dev/null and b/readme_img/before/modulesingletoncall_before.png differ
diff --git a/readme_img/before/routerinit_before.png b/readme_img/before/routerinit_before.png
new file mode 100644
index 00000000..4b9d9712
Binary files /dev/null and b/readme_img/before/routerinit_before.png differ
diff --git a/tests/test_api2.py b/tests/test_api2.py
new file mode 100644
index 00000000..f352d918
--- /dev/null
+++ b/tests/test_api2.py
@@ -0,0 +1,81 @@
+"""This is the test module for the Localrouter class,
+made by Marwan Amrhar & Yahia Noeman & Ayoub Bouazza & Sajeed Bouzziane.
+It covers the functions:
+ API.__init__
+ ModuleSingleton.__call__"""
+
+import unittest
+from hug.api import API
+
+class MockModule:
+ __name__ = "mock_module"
+ __doc__ = "This is a mock module"
+
+class TestAPIInit(unittest.TestCase):
+ def test_api_init_with_module(self):
+ """Test API initialization with module"""
+ module = MockModule()
+ api = API(module=module)
+
+ self.assertEqual(api.module, module)
+ self.assertEqual(api.name, "mock_module")
+ self.assertEqual(api.doc, "This is a mock module")
+ self.assertFalse(api.started)
+ self.assertFalse(api.cli_error_exit_codes)
+ self.assertFalse(api.future)
+
+ def test_api_init_without_module(self):
+ """Test API initialization without module"""
+ name = "test_name"
+ doc = "This is a test doc"
+ cli_error_exit_codes = True
+ future = True
+
+ api = API(name=name, doc=doc, cli_error_exit_codes=cli_error_exit_codes, future=future)
+
+ self.assertIsNone(api.module)
+ self.assertEqual(api.name, name)
+ self.assertEqual(api.doc, doc)
+ self.assertFalse(api.started)
+ self.assertTrue(api.cli_error_exit_codes)
+ self.assertTrue(api.future)
+
+ def test_api_init_with_partial_module_attributes(self):
+ """Test API initialization with module and partial attributes"""
+ module = MockModule()
+ name = "custom_name"
+ doc = "Custom documentation"
+
+ api = API(module=module, name=name, doc=doc)
+
+ self.assertEqual(api.module, module)
+ self.assertEqual(api.name, name)
+ self.assertEqual(api.doc, doc)
+ self.assertFalse(api.started)
+ self.assertFalse(api.cli_error_exit_codes)
+ self.assertFalse(api.future)
+
+ def test_api_init_with_empty_module(self):
+ """Test API initialization with empty module attributes"""
+ class EmptyModule:
+ __name__ = None
+ __doc__ = None
+
+ module = EmptyModule()
+ api = API(module=module)
+
+ self.assertEqual(api.module, module)
+ self.assertEqual(api.name, "")
+ self.assertEqual(api.doc, "")
+ self.assertFalse(api.started)
+ self.assertFalse(api.cli_error_exit_codes)
+ self.assertFalse(api.future)
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TestAPIInit))
+ return suite
+
+if __name__ == "__main__":
+ runner = unittest.TextTestRunner()
+ runner.run(test_suite())
diff --git a/tests/test_local_router.py b/tests/test_local_router.py
new file mode 100644
index 00000000..6457a2eb
--- /dev/null
+++ b/tests/test_local_router.py
@@ -0,0 +1,90 @@
+"""This is the test module for the Localrouter class,
+made by Marwan Amrhar & Yahia Noeman & Ayoub Bouazza & Sajeed Bouzziane.
+It covers the functions:
+ Localrouter.init
+ Localrouter.directives
+ Localrouter.validate
+ Localrouter.version
+ Localrouter.call"""
+
+import unittest
+from unittest.mock import patch
+import hug
+
+from hug.routing import LocalRouter
+
+class TestLocalRouter(unittest.TestCase):
+
+ def setUp(self):
+ self.router = LocalRouter(api="test_api")
+
+ ## localrouter.init
+ def test_initialization_with_defaults(self):
+ """Test LocalRouter initialization with default parameters"""
+ instance = LocalRouter()
+ self.assertNotIn("version", instance.route)
+ self.assertNotIn("skip_directives", instance.route)
+ self.assertNotIn("skip_validation", instance.route)
+
+ def test_initialization_with_version(self):
+ """Test LocalRouter initialization with version set"""
+ instance = LocalRouter(version=1)
+ self.assertEqual(instance.route.get("version"), 1)
+ self.assertNotIn("skip_directives", instance.route)
+ self.assertNotIn("skip_validation", instance.route)
+
+ def test_initialization_with_skip_directives(self):
+ """Test LocalRouter initialization with directives=False"""
+ instance = LocalRouter(directives=False)
+ self.assertNotIn("version", instance.route)
+ self.assertTrue(instance.route.get("skip_directives"))
+
+ def test_initialization_with_skip_validation(self):
+ """Test LocalRouter initialization with validate=False"""
+ instance = LocalRouter(validate=False)
+ self.assertNotIn("version", instance.route)
+ self.assertNotIn("skip_directives", instance.route)
+ self.assertTrue(instance.route.get("skip_validation"))
+
+ def test_initialization_with_all_parameters(self):
+ """Test LocalRouter initialization with all parameters"""
+ instance = LocalRouter(directives=False, validate=False, version=1)
+ self.assertEqual(instance.route.get("version"), 1)
+ self.assertTrue(instance.route.get("skip_directives"))
+ self.assertTrue(instance.route.get("skip_validation"))
+
+ ## localrouter.directives
+ def test_directives_method(self):
+ """Test LocalRouter directives method"""
+ result = self.router.directives(use=False)
+ self.assertIsInstance(result, LocalRouter)
+ self.assertIn("skip_directives", result.route)
+ self.assertTrue(result.route["skip_directives"])
+
+ ## localrouter.validate
+ def test_validate_method(self):
+ """Test LocalRouter validate method"""
+ result = self.router.validate(enforce=False)
+ self.assertIsInstance(result, LocalRouter)
+ self.assertIn("skip_validation", result.route)
+ self.assertTrue(result.route["skip_validation"])
+
+ ## localrouter.version
+ def test_version_method(self):
+ """Test LocalRouter version method"""
+ result = self.router.version(supported=2)
+ self.assertIsInstance(result, LocalRouter)
+ self.assertEqual(result.route["version"], 2)
+
+ ## localrouter.call
+ def test_call_method(self):
+ """Test LocalRouter __call__ method"""
+ def mock_function():
+ pass
+ with patch('hug.interface.Local') as mock_local:
+ self.router(mock_function)
+ mock_local.assert_called_once_with(self.router.route, mock_function)
+
+if __name__ == '__main__':
+ unittest.main()
+
\ No newline at end of file
diff --git a/tests/test_router.py b/tests/test_router.py
new file mode 100644
index 00000000..977b9ae3
--- /dev/null
+++ b/tests/test_router.py
@@ -0,0 +1,64 @@
+"""This is the test module for the Router class,
+made by Marwan Amrhar & Yahia Noeman & Ayoub Bouazza & Sajeed Bouzziane
+It covers the function:
+ Router.__init__"""
+
+import unittest
+from hug.routing import Router
+
+class TestRouterInit(unittest.TestCase):
+ def test_router_init_with_all_parameters(self):
+ """Test Router initialization with all parameters"""
+ transform = lambda x: x
+ output = "output_format"
+ validate = "validate_function"
+ api = "api_object"
+ requires = ("requirement1", "requirement2")
+ map_params = {"param1": "mapped_param1"}
+ args = ["arg1", "arg2"]
+
+ router = Router(
+ transform=transform,
+ output=output,
+ validate=validate,
+ api=api,
+ requires=requires,
+ map_params=map_params,
+ args=args,
+ )
+
+ self.assertEqual(router.route["transform"], transform)
+ self.assertEqual(router.route["output"], output)
+ self.assertEqual(router.route["validate"], validate)
+ self.assertEqual(router.route["api"], api)
+ self.assertEqual(router.route["requires"], requires)
+ self.assertEqual(router.route["map_params"], map_params)
+ self.assertEqual(router.route["args"], args)
+
+ def test_router_init_with_default_parameters(self):
+ """Test Router initialization with default parameters"""
+ router = Router()
+
+ self.assertNotIn("transform", router.route)
+ self.assertNotIn("output", router.route)
+ self.assertNotIn("validate", router.route)
+ self.assertNotIn("api", router.route)
+ self.assertEqual(router.route.get("requires", ()), ())
+ self.assertNotIn("map_params", router.route)
+ self.assertNotIn("args", router.route)
+
+ def test_router_init_with_single_requirement(self):
+ """Test Router initialization with a single requirement"""
+ router = Router(requires="requirement1")
+
+ self.assertEqual(router.route["requires"], ("requirement1",))
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TestRouterInit))
+ return suite
+
+if __name__ == "__main__":
+ runner = unittest.TextTestRunner()
+ runner.run(test_suite())
+
\ No newline at end of file