Skip to content

Commit 90fca66

Browse files
CervezaStalloneBrian Rodriguez | BRControls
andauthored
fix(ci): Apply formatting and fix WebSocket test decorator (#27)
Changes: - Applied Black and isort to all Python files (16 files reformatted) - Fixed WebSocket test skip decorator (was misplaced, now uses pytestmark) - Ensures all Code Quality checks pass This resolves the remaining CI failures. Co-authored-by: Brian Rodriguez | BRControls <b.rodriguez@brcontrols.com>
1 parent f7163a5 commit 90fca66

10 files changed

Lines changed: 899 additions & 929 deletions

File tree

modbus_webserver/test_settings.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,33 @@
1313

1414
# Disable static files storage issues in tests
1515
STORAGES = {
16-
'default': {
17-
'BACKEND': 'django.core.files.storage.FileSystemStorage',
16+
"default": {
17+
"BACKEND": "django.core.files.storage.FileSystemStorage",
1818
},
19-
'staticfiles': {
20-
'BACKEND': 'django.contrib.staticfiles.storage.StaticFilesStorage',
19+
"staticfiles": {
20+
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
2121
},
2222
}
2323

2424
# Use faster database for tests (not in-memory to allow migrations)
2525
DATABASES = {
26-
'default': {
27-
'ENGINE': 'django.db.backends.sqlite3',
28-
'NAME': BASE_DIR / 'test_db.sqlite3',
26+
"default": {
27+
"ENGINE": "django.db.backends.sqlite3",
28+
"NAME": BASE_DIR / "test_db.sqlite3",
2929
}
3030
}
3131

3232
# Disable caching in tests
3333
CACHES = {
34-
'default': {
35-
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
34+
"default": {
35+
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
3636
}
3737
}
3838

3939
# Disable Redis channel layer in tests
4040
CHANNEL_LAYERS = {
41-
'default': {
42-
'BACKEND': 'channels.layers.InMemoryChannelLayer',
41+
"default": {
42+
"BACKEND": "channels.layers.InMemoryChannelLayer",
4343
},
4444
}
4545

@@ -49,20 +49,20 @@
4949

5050
# Faster password hashing
5151
PASSWORD_HASHERS = [
52-
'django.contrib.auth.hashers.MD5PasswordHasher',
52+
"django.contrib.auth.hashers.MD5PasswordHasher",
5353
]
5454

5555
# Disable logging in tests
5656
LOGGING = {
57-
'version': 1,
58-
'disable_existing_loggers': True,
59-
'handlers': {
60-
'null': {
61-
'class': 'logging.NullHandler',
57+
"version": 1,
58+
"disable_existing_loggers": True,
59+
"handlers": {
60+
"null": {
61+
"class": "logging.NullHandler",
6262
},
6363
},
64-
'root': {
65-
'handlers': ['null'],
66-
'level': 'DEBUG',
64+
"root": {
65+
"handlers": ["null"],
66+
"level": "DEBUG",
6767
},
6868
}

tests/conftest.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,89 +9,92 @@
99
def api_client():
1010
"""DRF API client."""
1111
from rest_framework.test import APIClient
12+
1213
return APIClient()
1314

1415

1516
@pytest.fixture
1617
def modbus_interface_rtu(db):
1718
"""Create a test RTU interface."""
1819
from modbus_app.models import ModbusInterface
20+
1921
return ModbusInterface.objects.create(
20-
name='Test RTU',
21-
protocol='RTU',
22-
port='COM1',
22+
name="Test RTU",
23+
protocol="RTU",
24+
port="COM1",
2325
baudrate=9600,
24-
parity='N',
26+
parity="N",
2527
stopbits=1,
2628
bytesize=8,
2729
timeout=3.0,
28-
enabled=True
30+
enabled=True,
2931
)
3032

3133

3234
@pytest.fixture
3335
def modbus_interface_tcp(db):
3436
"""Create a test TCP interface."""
3537
from modbus_app.models import ModbusInterface
38+
3639
return ModbusInterface.objects.create(
37-
name='Test TCP',
38-
protocol='TCP',
39-
host='192.168.1.100',
40+
name="Test TCP",
41+
protocol="TCP",
42+
host="192.168.1.100",
4043
tcp_port=502,
4144
timeout=3.0,
42-
enabled=True
45+
enabled=True,
4346
)
4447

4548

4649
@pytest.fixture
4750
def device(db, modbus_interface_rtu):
4851
"""Create a test device."""
4952
from modbus_app.models import Device
53+
5054
return Device.objects.create(
51-
name='Test Device',
55+
name="Test Device",
5256
interface=modbus_interface_rtu,
5357
slave_id=1,
5458
polling_interval=5,
55-
enabled=True
59+
enabled=True,
5660
)
5761

5862

5963
@pytest.fixture
6064
def register(db, device):
6165
"""Create a test register."""
6266
from modbus_app.models import Register
67+
6368
return Register.objects.create(
6469
device=device,
65-
name='Test Register',
70+
name="Test Register",
6671
function_code=3,
6772
address=100,
68-
data_type='UINT16',
73+
data_type="UINT16",
6974
conversion_factor=1.0,
7075
conversion_offset=0.0,
71-
unit='°C',
72-
enabled=True
76+
unit="°C",
77+
enabled=True,
7378
)
7479

7580

7681
@pytest.fixture
7782
def test_user(db, django_user_model):
7883
"""Create a test user for each test."""
7984
import uuid
80-
username = f'testuser_{uuid.uuid4().hex[:8]}'
85+
86+
username = f"testuser_{uuid.uuid4().hex[:8]}"
8187
return django_user_model.objects.create_user(
82-
username=username,
83-
password='testpass123',
84-
email=f'{username}@example.com'
88+
username=username, password="testpass123", email=f"{username}@example.com"
8589
)
8690

8791

8892
@pytest.fixture
8993
def admin_user(db, django_user_model):
9094
"""Create an admin user for each test."""
9195
import uuid
92-
username = f'admin_{uuid.uuid4().hex[:8]}'
96+
97+
username = f"admin_{uuid.uuid4().hex[:8]}"
9398
return django_user_model.objects.create_superuser(
94-
username=username,
95-
password='admin123',
96-
email=f'{username}@example.com'
99+
username=username, password="admin123", email=f"{username}@example.com"
97100
)

tests/factories.py

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@
44

55
import factory
66
from factory.django import DjangoModelFactory
7-
from modbus_app.models import (
8-
ModbusInterface, Device, Register, TrendData,
9-
DashboardGroup, DashboardWidget, Alarm
10-
)
7+
8+
from modbus_app.models import (Alarm, DashboardGroup, DashboardWidget, Device,
9+
ModbusInterface, Register, TrendData)
1110

1211

1312
class ModbusInterfaceFactory(DjangoModelFactory):
1413
"""Factory for ModbusInterface model."""
15-
14+
1615
class Meta:
1716
model = ModbusInterface
18-
19-
name = factory.Sequence(lambda n: f'Interface {n}')
20-
protocol = 'RTU'
21-
port = 'COM1'
17+
18+
name = factory.Sequence(lambda n: f"Interface {n}")
19+
protocol = "RTU"
20+
port = "COM1"
2221
baudrate = 9600
23-
parity = 'N'
22+
parity = "N"
2423
stopbits = 1
2524
bytesize = 8
2625
timeout = 3.0
@@ -29,20 +28,20 @@ class Meta:
2928

3029
class TCPInterfaceFactory(ModbusInterfaceFactory):
3130
"""Factory for TCP ModbusInterface."""
32-
33-
protocol = 'TCP'
34-
host = '192.168.1.100'
31+
32+
protocol = "TCP"
33+
host = "192.168.1.100"
3534
tcp_port = 502
36-
port = ''
35+
port = ""
3736

3837

3938
class DeviceFactory(DjangoModelFactory):
4039
"""Factory for Device model."""
41-
40+
4241
class Meta:
4342
model = Device
44-
45-
name = factory.Sequence(lambda n: f'Device {n}')
43+
44+
name = factory.Sequence(lambda n: f"Device {n}")
4645
interface = factory.SubFactory(ModbusInterfaceFactory)
4746
slave_id = factory.Sequence(lambda n: n + 1)
4847
polling_interval = 5
@@ -51,54 +50,54 @@ class Meta:
5150

5251
class RegisterFactory(DjangoModelFactory):
5352
"""Factory for Register model."""
54-
53+
5554
class Meta:
5655
model = Register
57-
56+
5857
device = factory.SubFactory(DeviceFactory)
59-
name = factory.Sequence(lambda n: f'Register {n}')
58+
name = factory.Sequence(lambda n: f"Register {n}")
6059
function_code = 3
6160
address = factory.Sequence(lambda n: n)
62-
data_type = 'UINT16'
61+
data_type = "UINT16"
6362
conversion_factor = 1.0
6463
conversion_offset = 0.0
65-
unit = '°C'
64+
unit = "°C"
6665
enabled = True
6766

6867

6968
class TrendDataFactory(DjangoModelFactory):
7069
"""Factory for TrendData model."""
71-
70+
7271
class Meta:
7372
model = TrendData
74-
73+
7574
register = factory.SubFactory(RegisterFactory)
76-
raw_value = factory.Faker('pyfloat', min_value=0, max_value=100)
75+
raw_value = factory.Faker("pyfloat", min_value=0, max_value=100)
7776
converted_value = factory.LazyAttribute(lambda obj: obj.raw_value * 0.1)
78-
quality = 'good'
77+
quality = "good"
7978

8079

8180
class DashboardGroupFactory(DjangoModelFactory):
8281
"""Factory for DashboardGroup model."""
83-
82+
8483
class Meta:
8584
model = DashboardGroup
86-
87-
name = factory.Sequence(lambda n: f'Group {n}')
85+
86+
name = factory.Sequence(lambda n: f"Group {n}")
8887
row_order = factory.Sequence(lambda n: n)
8988
collapsed = False
9089

9190

9291
class DashboardWidgetFactory(DjangoModelFactory):
9392
"""Factory for DashboardWidget model."""
94-
93+
9594
class Meta:
9695
model = DashboardWidget
97-
96+
9897
group = factory.SubFactory(DashboardGroupFactory)
9998
register = factory.SubFactory(RegisterFactory)
100-
title = factory.Sequence(lambda n: f'Widget {n}')
101-
widget_type = 'line_chart'
99+
title = factory.Sequence(lambda n: f"Widget {n}")
100+
widget_type = "line_chart"
102101
column_position = 0
103102
row_position = 0
104103
width = 6
@@ -107,14 +106,14 @@ class Meta:
107106

108107
class AlarmFactory(DjangoModelFactory):
109108
"""Factory for Alarm model."""
110-
109+
111110
class Meta:
112111
model = Alarm
113-
112+
114113
register = factory.SubFactory(RegisterFactory)
115-
name = factory.Sequence(lambda n: f'Alarm {n}')
116-
condition = 'greater_than'
114+
name = factory.Sequence(lambda n: f"Alarm {n}")
115+
condition = "greater_than"
117116
threshold_high = 80.0
118-
severity = 'warning'
119-
message = 'Threshold exceeded'
117+
severity = "warning"
118+
message = "Threshold exceeded"
120119
enabled = True

0 commit comments

Comments
 (0)