Skip to content

Commit 5105e25

Browse files
committed
Use kebab-case for attr/command slug
1 parent 35e62c8 commit 5105e25

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/fastcs/backends/rest/rest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _add_attribute_api_routes(app: FastAPI, mapping: Mapping) -> None:
9393
path = single_mapping.controller.path
9494

9595
for attr_name, attribute in single_mapping.attributes.items():
96-
attr_name = attr_name.title().replace("_", "")
96+
attr_name = attr_name.replace("_", "-")
9797
route = f"{'/'.join(path)}/{attr_name}" if path else attr_name
9898

9999
match attribute:
@@ -143,7 +143,7 @@ def _add_command_api_routes(app: FastAPI, mapping: Mapping) -> None:
143143
path = single_mapping.controller.path
144144

145145
for name, method in single_mapping.command_methods.items():
146-
cmd_name = name.title().replace("_", "")
146+
cmd_name = name.replace("_", "-")
147147
route = f"/{'/'.join(path)}/{cmd_name}" if path else cmd_name
148148
app.add_api_route(
149149
f"/{route}",

tests/backends/rest/test_rest.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from fastcs.datatypes import Bool, Float, Int
1111

1212

13-
def pascal_2_snake(input: list[str]) -> list[str]:
13+
def kebab_2_snake(input: list[str]) -> list[str]:
1414
snake_list = copy.deepcopy(input)
15-
snake_list[-1] = re.sub(r"(?<!^)(?=[A-Z])", "_", snake_list[-1]).lower()
15+
snake_list[-1] = snake_list[-1].replace("-", "_")
1616
return snake_list
1717

1818

@@ -30,7 +30,7 @@ def client(self):
3030
def client_read(self, client):
3131
def _client_read(path: list[str], expected: Any):
3232
route = "/" + "/".join(path)
33-
with self.controller.assertPerformed(pascal_2_snake(path), "READ"):
33+
with self.controller.assertPerformed(kebab_2_snake(path), "READ"):
3434
response = client.get(route)
3535
assert response.status_code == 200
3636
assert response.json()["value"] == expected
@@ -41,7 +41,7 @@ def _client_read(path: list[str], expected: Any):
4141
def client_write(self, client):
4242
def _client_write(path: list[str], value: Any):
4343
route = "/" + "/".join(path)
44-
with self.controller.assertPerformed(pascal_2_snake(path), "WRITE"):
44+
with self.controller.assertPerformed(kebab_2_snake(path), "WRITE"):
4545
response = client.put(route, json={"value": value})
4646
assert response.status_code == 204
4747

@@ -51,40 +51,42 @@ def _client_write(path: list[str], value: Any):
5151
def client_exec(self, client):
5252
def _client_exec(path: list[str]):
5353
route = "/" + "/".join(path)
54-
with self.controller.assertPerformed(pascal_2_snake(path), "EXECUTE"):
54+
with self.controller.assertPerformed(kebab_2_snake(path), "EXECUTE"):
5555
response = client.put(route)
5656
assert response.status_code == 204
5757

5858
return _client_exec
5959

6060
def test_read_int(self, client_read):
61-
client_read(["ReadInt"], AttrR(Int())._value)
61+
client_read(["read-int"], AttrR(Int())._value)
6262

6363
def test_read_write_int(self, client_read, client_write):
64-
client_read(["ReadWriteInt"], AttrR(Int())._value)
65-
client_write(["ReadWriteInt"], AttrR(Int())._value)
64+
client_read(["read-write-int"], AttrR(Int())._value)
65+
client_write(["read-write-int"], AttrR(Int())._value)
6666

6767
def test_read_write_float(self, client_read, client_write):
68-
client_read(["ReadWriteFloat"], AttrR(Float())._value)
69-
client_write(["ReadWriteFloat"], AttrR(Float())._value)
68+
client_read(["read-write-float"], AttrR(Float())._value)
69+
client_write(["read-write-float"], AttrR(Float())._value)
7070

7171
def test_read_bool(self, client_read):
72-
client_read(["ReadBool"], AttrR(Bool())._value)
72+
client_read(["read-bool"], AttrR(Bool())._value)
7373

7474
def test_write_bool(self, client_write):
75-
client_write(["WriteBool"], AttrR(Bool())._value)
75+
client_write(["write-bool"], AttrR(Bool())._value)
7676

7777
# # We need to discuss enums
7878
# def test_string_enum(self, client_read, client_write):
7979

8080
def test_big_enum(self, client_read):
81-
client_read(["BigEnum"], AttrR(Int(), allowed_values=list(range(1, 18)))._value)
81+
client_read(
82+
["big-enum"], AttrR(Int(), allowed_values=list(range(1, 18)))._value
83+
)
8284

8385
def test_go(self, client_exec):
84-
client_exec(["Go"])
86+
client_exec(["go"])
8587

8688
def test_read_child1(self, client_read):
87-
client_read(["SubController01", "ReadInt"], AttrR(Int())._value)
89+
client_read(["SubController01", "read-int"], AttrR(Int())._value)
8890

8991
def test_read_child2(self, client_read):
90-
client_read(["SubController02", "ReadInt"], AttrR(Int())._value)
92+
client_read(["SubController02", "read-int"], AttrR(Int())._value)

0 commit comments

Comments
 (0)