Skip to content

Commit 6eca1e6

Browse files
authored
detect if None is passed to parse_tasks (#1080)
* detect if None is passed to parse_tasks * add test to ensure proper exception is raised * fix * update nix infrastructure to allow tests to run
1 parent 45ee5e9 commit 6eca1e6

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

.envrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

shell.nix

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
{ pkgs ? import <nixpkgs> {}}:
2-
3-
pkgs.mkShell {
4-
5-
#buildInputs = [
6-
#];
7-
8-
packages = [
9-
pkgs.python311
10-
];
11-
}
1+
{ pkgs ? import <nixpkgs> {} }:
2+
(pkgs.buildFHSEnv {
3+
name = "pipzone";
4+
targetPkgs = pkgs: (with pkgs; [
5+
python311
6+
python311Packages.pip
7+
python311Packages.virtualenv
8+
]);
9+
runScript = "zsh";
10+
}).env

src/meshapi/tests/test_uisp_import.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,3 +2128,27 @@ def active(self):
21282128
response = c.get("/api/v1/uisp-import/status/")
21292129

21302130
self.assertEqual(500, response.status_code)
2131+
2132+
@patch("meshapi.views.uisp_import.app.control.inspect")
2133+
def test_view_uisp_on_demand_import_status_none(self, mock_celery_app):
2134+
class BrokenMockInspect(MagicMock):
2135+
def scheduled(self):
2136+
return None
2137+
2138+
def reserved(self):
2139+
return None
2140+
2141+
def active(self):
2142+
return None
2143+
2144+
mock_celery_app.side_effect = BrokenMockInspect()
2145+
2146+
# Create a client
2147+
self.admin_user = User.objects.create_superuser(
2148+
username="admin", password="admin_password", email="admin@example.com"
2149+
)
2150+
c = Client()
2151+
c.login(username="admin", password="admin_password")
2152+
response = c.get("/api/v1/uisp-import/status/")
2153+
2154+
self.assertEqual(500, response.status_code)

src/meshapi/views/uisp_import.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def view_uisp_on_demand_import_status(request: Request) -> Response:
4646

4747
def parse_tasks(tasks_by_worker: dict[str, list], status: str) -> list[dict[str, str]]:
4848
parsed_tasks = []
49+
if tasks_by_worker is None:
50+
raise Exception("Got None for tasks_by_worker. Is something wrong with celery-worker?")
4951
for _, tasks in tasks_by_worker.items():
5052
for t in tasks:
5153
if "run_uisp_on_demand_import" in t.get("name"):

0 commit comments

Comments
 (0)