Skip to content

Commit

Permalink
Reformatted
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiky30 committed Jan 24, 2024
1 parent 446b320 commit be2d56d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 42 deletions.
7 changes: 3 additions & 4 deletions shedpi_hub_dashboard/forms/fields.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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)

Expand Down
54 changes: 16 additions & 38 deletions shedpi_hub_dashboard/tests/test_json_schema.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)
Expand Down

0 comments on commit be2d56d

Please sign in to comment.