Kanaderu / iotsite

IoT Web App
https://udsensors.tk/ws/
3 stars 2 forks source link

Add Backend UnitTests #73

Open Kanaderu opened 4 years ago

Kanaderu commented 4 years ago

Add backend unittests. As more features are added, it becomes much more difficult to verify existing features work.

Backend tests should be testable and managed with manage.py for now. Applying CI at this stage is maybe too early.

Kanaderu commented 4 years ago

Unittests are executed by running ./manage.py test

Kanaderu commented 4 years ago

Finished with user unittests for now I think. The only thing on the user unittests may be to check that the sliding tokens work like they're supposed to but haven't verified that entirely during development.

Kanaderu commented 4 years ago

Testing websockets will need to be done differently than from traditional Django Testcase setups. This will probably be addressed in Django v3.0 due to the added support for async operations.

Current setup for testing async operations for now are from the following documentation links: https://channels.readthedocs.io/en/latest/topics/testing.html

https://pytest-django.readthedocs.io/en/latest/tutorial.html https://pytest-django.readthedocs.io/en/latest/configuring_django.html

Running pytests to test the async operations is done by running pytest

Kanaderu commented 4 years ago

Leaving a note that ignoring the deprecation warnings using

@pytest.mark.filterwarnings('ignore::DeprecationWarning')

was added since pytest didn't like the regular expressions for the DRF routes accounting for case-insensitive endpoints for Feather and LoRaGateway. Hopefully, there will be a patch to fix this in a later release of DRF.

Kanaderu commented 4 years ago

May need to pylint the backend too

Kanaderu commented 4 years ago

Add unittests for websocket channels

Kanaderu commented 4 years ago

Example here:

https://github.com/django/channels/blob/master/tests/test_layers.py