Skip to content

Commit

Permalink
Started getting an endpoint test going
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiky30 committed Jan 25, 2024
1 parent ba758ec commit 96cbbd8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
7 changes: 7 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pytest
from rest_framework.test import APIClient


@pytest.fixture
def client():
return APIClient()
27 changes: 27 additions & 0 deletions shedpi_hub_dashboard/tests/test_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
# TODO:
# - Schema with data fields
# - Submit data to the endpoints
import pytest
from django.urls import reverse
from rest_framework import status

from shedpi_hub_dashboard.tests.utils.factories import DeviceModuleFactory


@pytest.mark.django_db
def test_device_reading_submission(client):
schema = {
"$id": "https://example.com/person.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Person",
"type": "object",
"properties": {
"temperature": {"type": "string", "description": "The Temperature"},
},
}
device_module = DeviceModuleFactory(schema=schema)
# devicemodulereading-list
# devicemodulereading-detail
url = reverse("devicemodulereading-detail", kwargs={"pk": device_module.id})

response = client.post(url, data={"device_module_id": device_module.id})

assert response.status_code == status.HTTP_200_OK
assert set(response.data.keys()) == {}
6 changes: 3 additions & 3 deletions shedpi_hub_example_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
"DEFAULT_PERMISSION_CLASSES": [
"rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly"
]
# "DEFAULT_PERMISSION_CLASSES": [
# "rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly"
# ]
}
2 changes: 1 addition & 1 deletion shedpi_hub_example_project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from shedpi_hub_dashboard.views import DeviceModuleReadingViewSet

router = routers.DefaultRouter()
router.register(r"device_module_readings", DeviceModuleReadingViewSet)
router.register(r"device-module-readings", DeviceModuleReadingViewSet)

urlpatterns = [
*[
Expand Down

0 comments on commit 96cbbd8

Please sign in to comment.