From be2d56d3e3cbd4f30ec2e125fc3b02cf1501531f Mon Sep 17 00:00:00 2001 From: Andrew Aikman Date: Wed, 24 Jan 2024 21:18:56 +0000 Subject: [PATCH] Reformatted --- shedpi_hub_dashboard/forms/fields.py | 7 ++- .../tests/test_json_schema.py | 54 ++++++------------- 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/shedpi_hub_dashboard/forms/fields.py b/shedpi_hub_dashboard/forms/fields.py index 487ceab..c0bc3cd 100644 --- a/shedpi_hub_dashboard/forms/fields.py +++ b/shedpi_hub_dashboard/forms/fields.py @@ -1,6 +1,7 @@ import json -from django.forms import widgets + from django.forms import JSONField as JSONFormField +from django.forms import widgets class PrettyJSONWidget(widgets.Textarea): @@ -9,9 +10,7 @@ def format_value(self, value): value = json.dumps(json.loads(value), indent=2, sort_keys=True) # Calculate the size of the contents - row_lengths = [ - len(r) for r in value.split("\n") - ] + row_lengths = [len(r) for r in value.split("\n")] content_width = max(len(row_lengths) + 2, 20) content_height = max(max(row_lengths) + 2, 45) diff --git a/shedpi_hub_dashboard/tests/test_json_schema.py b/shedpi_hub_dashboard/tests/test_json_schema.py index ed460db..a78e744 100644 --- a/shedpi_hub_dashboard/tests/test_json_schema.py +++ b/shedpi_hub_dashboard/tests/test_json_schema.py @@ -1,16 +1,14 @@ import pytest - from jsonschema.exceptions import SchemaError, ValidationError -from shedpi_hub_dashboard.tests.utils.factories import DeviceModuleFactory from shedpi_hub_dashboard.models import DeviceModuleReading - +from shedpi_hub_dashboard.tests.utils.factories import DeviceModuleFactory """ device_temp = models.CharField(max_length=8) probe_temp = models.CharField(max_length=8) measurement_type = models.CharField(max_length=10) - + TODO: # Design where the validation shoudl live, needs to: # '- Validate on save @@ -29,26 +27,16 @@ def test_schema_validation_happy_path(): "title": "Person", "type": "object", "properties": { - "firstName": { - "type": "string", - "description": "The person's first name." - }, - "lastName": { - "type": "string", - "description": "The person's last name." - }, + "firstName": {"type": "string", "description": "The person's first name."}, + "lastName": {"type": "string", "description": "The person's last name."}, "age": { "description": "Age in years which must be equal to or greater than zero.", "type": "integer", - "minimum": 0 - } - } - } - data = { - "firstName": "John", - "lastName": "Doe", - "age": 21 + "minimum": 0, + }, + }, } + data = {"firstName": "John", "lastName": "Doe", "age": 21} device_module = DeviceModuleFactory(schema=schema) reading = DeviceModuleReading(device_module=device_module, data=data) @@ -68,16 +56,12 @@ def test_json_schema_invalid_data(): "age": { "description": "Age in years which must be equal to or greater than zero.", "type": "integer", - "minimum": 0 + "minimum": 0, } - } - } - data = { - "age": 21 - } - updated_data = { - "age": "Some text" + }, } + data = {"age": 21} + updated_data = {"age": "Some text"} device_module = DeviceModuleFactory(schema=schema) reading = DeviceModuleReading(device_module=device_module, data=data) @@ -101,13 +85,11 @@ def test_json_schema_update_with_invalid_data(): "age": { "description": "Age in years which must be equal to or greater than zero.", "type": "integer", - "minimum": 0 + "minimum": 0, } - } - } - data = { - "age": "Some text" + }, } + data = {"age": "Some text"} device_module = DeviceModuleFactory(schema=schema) reading = DeviceModuleReading(device_module=device_module, data=data) @@ -118,11 +100,7 @@ def test_json_schema_update_with_invalid_data(): @pytest.mark.django_db def test_json_schema_invalid_schema(): schema = {"type": 1234} - data = { - "firstName": "John", - "lastName": "Doe", - "age": 21 - } + data = {"firstName": "John", "lastName": "Doe", "age": 21} device_module = DeviceModuleFactory(schema=schema) reading = DeviceModuleReading(device_module=device_module, data=data)